application_test.js 6.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203
  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 installerController = 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. installerController.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(installerController.get('clusterName')).to.equal('cl1');
  50. });
  51. });
  52. describe('#showSettingsPopup', function() {
  53. var dataToShowRes = {};
  54. beforeEach(function () {
  55. sinon.stub(App.ModalPopup, 'show', function(dataToShow){
  56. dataToShowRes = dataToShow;
  57. });
  58. sinon.stub(App, 'isAccessible').returns(true);
  59. var emulatorClass = function() {};
  60. emulatorClass.prototype.done = function(func) {
  61. if (func) {
  62. func();
  63. }
  64. };
  65. var emulator = new emulatorClass();
  66. sinon.stub(installerController, 'dataLoading').returns(emulator);
  67. });
  68. afterEach(function () {
  69. App.isAccessible.restore();
  70. App.ModalPopup.show.restore();
  71. installerController.dataLoading.restore();
  72. });
  73. it ('Should show settings popup', function() {
  74. installerController.showSettingsPopup();
  75. dataToShowRes = JSON.parse(JSON.stringify(dataToShowRes));
  76. expect(dataToShowRes).to.eql({
  77. "header": "User Settings",
  78. "primary": "Save"
  79. });
  80. });
  81. });
  82. describe('#startKeepAlivePoller', function() {
  83. it ('Should change run poller state', function() {
  84. installerController.set('isPollerRunning', false);
  85. installerController.startKeepAlivePoller();
  86. expect(installerController.get('isPollerRunning')).to.be.true;
  87. });
  88. });
  89. describe('#getUserPrefErrorCallback', function() {
  90. it ('Should set currentPrefObject', function() {
  91. installerController.getUserPrefErrorCallback({status: 404}, {}, {});
  92. expect(installerController.get('currentPrefObject')).to.be.true;
  93. });
  94. });
  95. describe('#getUserPrefSuccessCallback', function() {
  96. it ('Should set currentPrefObject', function() {
  97. installerController.getUserPrefSuccessCallback({status: 200}, {}, {});
  98. expect(installerController.get('currentPrefObject')).to.be.eql({status: 200});
  99. });
  100. });
  101. describe('#goToAdminView', function() {
  102. var result;
  103. beforeEach(function () {
  104. sinon.stub(App.router, 'route', function(data) {
  105. result = data;
  106. return false;
  107. });
  108. });
  109. afterEach(function () {
  110. App.router.route.restore();
  111. });
  112. it ('Should call route once', function() {
  113. installerController.goToAdminView();
  114. expect(result).to.be.equal('adminView');
  115. });
  116. });
  117. describe('#dataLoading', function() {
  118. beforeEach(function () {
  119. sinon.stub(installerController, 'getUserPref', function(){
  120. return {
  121. complete: function(func) {
  122. if (func) {
  123. func();
  124. }
  125. }
  126. };
  127. });
  128. });
  129. afterEach(function () {
  130. installerController.getUserPref.restore();
  131. });
  132. it ('Should change run poller state', function() {
  133. installerController.set('currentPrefObject', {name: 'n1'});
  134. installerController.dataLoading().then(function(data){
  135. expect(data).to.be.eql({
  136. "name": "n1"
  137. });
  138. });
  139. });
  140. });
  141. describe('#getStack', function() {
  142. var res;
  143. beforeEach(function () {
  144. sinon.stub(App.ajax, 'send', function(data) {
  145. res = data;
  146. });
  147. });
  148. afterEach(function () {
  149. App.ajax.send.restore();
  150. });
  151. it ('Should return send value', function() {
  152. var callback = {
  153. 'callback': true
  154. };
  155. installerController.getStack(callback);
  156. res = JSON.parse(JSON.stringify(res));
  157. expect(res).to.be.eql({
  158. "name": "router.login.clusters",
  159. "sender": {
  160. "isPollerRunning": true,
  161. "currentPrefObject": null
  162. },
  163. "callback": {
  164. "callback": true
  165. }
  166. });
  167. });
  168. });
  169. describe('#clusterDisplayName', function() {
  170. it ('Should return cluster display name', function() {
  171. installerController.set('clusterName', '');
  172. expect(installerController.get('clusterDisplayName')).to.equal('mycluster');
  173. });
  174. });
  175. describe('#isClusterDataLoaded', function() {
  176. beforeEach(function () {
  177. sinon.stub(App.router, 'get').returns('cl1');
  178. });
  179. afterEach(function () {
  180. App.router.get.restore();
  181. });
  182. it ('Should return true, when data loaded', function() {
  183. expect(installerController.get('isClusterDataLoaded')).to.be.equal('cl1');
  184. });
  185. });
  186. });