application_test.js 3.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133
  1. /**
  2. * Licensed to the Apache Software Foundation (ASF) under one
  3. * or more contributor license agreements. See the NOTICE file
  4. * distributed with this work for additional information
  5. * regarding copyright ownership. The ASF licenses this file
  6. * to you under the Apache License, Version 2.0 (the
  7. * "License"); you may not use this file except in compliance
  8. * with the License. You may obtain a copy of the License at
  9. *
  10. * http://www.apache.org/licenses/LICENSE-2.0
  11. *
  12. * Unless required by applicable law or agreed to in writing, software
  13. * distributed under the License is distributed on an "AS IS" BASIS,
  14. * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  15. * See the License for the specific language governing permissions and
  16. * limitations under the License.
  17. */
  18. var App = require('app');
  19. require('models/cluster');
  20. describe('App.ApplicationController', function () {
  21. var applicationController = App.ApplicationController.create();
  22. describe('#showAboutPopup', function() {
  23. var dataToShowRes = {};
  24. beforeEach(function () {
  25. sinon.stub(App.ModalPopup, 'show', function(dataToShow){
  26. dataToShowRes = dataToShow;
  27. });
  28. });
  29. afterEach(function () {
  30. App.ModalPopup.show.restore();
  31. });
  32. it ('Should send correct data to popup', function() {
  33. applicationController.showAboutPopup();
  34. dataToShowRes = JSON.parse(JSON.stringify(dataToShowRes));
  35. expect(dataToShowRes).to.eql({
  36. "header": "About",
  37. "secondary": false
  38. });
  39. });
  40. });
  41. describe('#clusterName', function() {
  42. beforeEach(function () {
  43. sinon.stub(App.router, 'get').returns('cl1');
  44. });
  45. afterEach(function () {
  46. App.router.get.restore();
  47. });
  48. it ('Should return cluster name', function() {
  49. expect(applicationController.get('clusterName')).to.equal('cl1');
  50. });
  51. });
  52. describe('#startKeepAlivePoller', function() {
  53. it ('Should change run poller state', function() {
  54. applicationController.set('isPollerRunning', false);
  55. applicationController.startKeepAlivePoller();
  56. expect(applicationController.get('isPollerRunning')).to.be.true;
  57. });
  58. });
  59. describe('#goToAdminView', function() {
  60. var result;
  61. beforeEach(function () {
  62. sinon.stub(App.router, 'route', function(data) {
  63. result = data;
  64. return false;
  65. });
  66. });
  67. afterEach(function () {
  68. App.router.route.restore();
  69. });
  70. it ('Should call route once', function() {
  71. applicationController.goToAdminView();
  72. expect(result).to.be.equal('adminView');
  73. });
  74. });
  75. describe('#getStack', function() {
  76. var res;
  77. beforeEach(function () {
  78. sinon.stub(App.ajax, 'send', function(data) {
  79. res = data;
  80. });
  81. });
  82. afterEach(function () {
  83. App.ajax.send.restore();
  84. });
  85. it ('Should return send value', function() {
  86. var callback = {
  87. 'callback': true
  88. };
  89. applicationController.getStack(callback);
  90. res = JSON.parse(JSON.stringify(res));
  91. expect(res).to.be.eql({
  92. "name": "router.login.clusters",
  93. "sender": {
  94. "isPollerRunning": true
  95. },
  96. "callback": {
  97. "callback": true
  98. }
  99. });
  100. });
  101. });
  102. describe('#clusterDisplayName', function() {
  103. it ('Should return cluster display name', function() {
  104. applicationController.set('clusterName', '');
  105. expect(applicationController.get('clusterDisplayName')).to.equal('mycluster');
  106. });
  107. });
  108. describe('#isClusterDataLoaded', function() {
  109. beforeEach(function () {
  110. var stub = sinon.stub(App, 'get');
  111. stub.withArgs('router.clusterController.isLoaded').returns(true);
  112. stub.withArgs('router.loggedIn').returns(true);
  113. });
  114. afterEach(function () {
  115. App.get.restore();
  116. });
  117. it ('Should return true, when data loaded', function() {
  118. expect(applicationController.get('isClusterDataLoaded')).to.be.true;
  119. });
  120. });
  121. });