wizard_controller_test.js 5.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211
  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. function getController() {
  20. return App.RAHighAvailabilityWizardController.create({});
  21. }
  22. describe('App.RAHighAvailabilityWizardController', function () {
  23. var controller;
  24. beforeEach(function () {
  25. controller = getController();
  26. });
  27. describe("#setCurrentStep()", function () {
  28. beforeEach(function() {
  29. sinon.stub(App.clusterStatus, 'setClusterStatus');
  30. });
  31. afterEach(function() {
  32. App.clusterStatus.setClusterStatus.restore();
  33. });
  34. it("should set current step", function() {
  35. controller.setCurrentStep();
  36. expect(App.clusterStatus.setClusterStatus.calledOnce).to.be.true;
  37. });
  38. });
  39. describe('#loadMap', function() {
  40. describe('should load cluster', function() {
  41. var loadCluster = false;
  42. var loadBalancerURL = false;
  43. var checker = {
  44. load: function() {
  45. loadCluster = true;
  46. loadBalancerURL = true;
  47. }
  48. };
  49. beforeEach(function () {
  50. controller.loadMap['1'][0].callback.call(checker);
  51. });
  52. it('cluster info and loadBalancerURL are loaded', function () {
  53. expect(loadCluster).to.be.true;
  54. });
  55. });
  56. describe('should load service hosts', function() {
  57. var loadHosts = false;
  58. var loadServicesFromServer = false;
  59. var loadMasterComponentHosts = false;
  60. var checker = {
  61. loadHosts: function () {
  62. loadHosts = true;
  63. return $.Deferred().resolve().promise();
  64. },
  65. loadServicesFromServer: function () {
  66. loadServicesFromServer = true;
  67. },
  68. loadMasterComponentHosts: function () {
  69. loadMasterComponentHosts = true;
  70. return $.Deferred().resolve().promise();
  71. }
  72. };
  73. beforeEach(function () {
  74. controller.loadMap['2'][0].callback.call(checker);
  75. });
  76. it('hosts are loaded', function () {
  77. expect(loadHosts).to.be.true;
  78. });
  79. it('services from server are loaded', function () {
  80. expect(loadServicesFromServer).to.be.true;
  81. });
  82. it('master component hosts are loaded', function () {
  83. expect(loadMasterComponentHosts).to.be.true;
  84. });
  85. });
  86. describe('should load cluster', function() {
  87. var loadRaHosts = false;
  88. var checker = {
  89. load: function() {
  90. loadRaHosts = true;
  91. }
  92. };
  93. beforeEach(function () {
  94. controller.loadMap['3'][0].callback.call(checker);
  95. });
  96. it('raHosts are loaded', function () {
  97. expect(loadRaHosts).to.be.true;
  98. });
  99. });
  100. describe('should load tasks', function() {
  101. var loadTasksStatuses = false;
  102. var loadTasksRequestIds = false;
  103. var loadRequestIds = false;
  104. var checker = {
  105. loadTasksStatuses: function () {
  106. loadTasksStatuses = true;
  107. return $.Deferred().resolve().promise();
  108. },
  109. loadTasksRequestIds: function () {
  110. loadTasksRequestIds = true;
  111. },
  112. loadRequestIds: function () {
  113. loadRequestIds = true;
  114. }
  115. };
  116. beforeEach(function () {
  117. controller.loadMap['4'][0].callback.call(checker);
  118. });
  119. it('task statuses are loaded', function () {
  120. expect(loadTasksStatuses).to.be.true;
  121. });
  122. it('task request ids are loaded', function () {
  123. expect(loadTasksRequestIds).to.be.true;
  124. });
  125. it('request ids are loaded', function () {
  126. expect(loadRequestIds).to.be.true;
  127. });
  128. });
  129. });
  130. describe("#clearAllSteps()", function () {
  131. beforeEach(function() {
  132. sinon.stub(controller, 'clearInstallOptions');
  133. sinon.stub(controller, 'getCluster').returns({});
  134. controller.clearAllSteps();
  135. });
  136. afterEach(function() {
  137. controller.clearInstallOptions.restore();
  138. controller.getCluster.restore();
  139. });
  140. it("clearInstallOptions should be called", function() {
  141. expect(controller.clearInstallOptions.calledOnce).to.be.true;
  142. });
  143. it("cluster should be set", function() {
  144. expect(controller.get('content.cluster')).to.be.eql({});
  145. });
  146. });
  147. describe("#finish()", function () {
  148. var container = {
  149. updateAll: Em.K
  150. };
  151. beforeEach(function() {
  152. sinon.stub(controller, 'resetDbNamespace');
  153. sinon.stub(App.router, 'get').returns(container);
  154. sinon.stub(container, 'updateAll');
  155. controller.finish();
  156. });
  157. afterEach(function() {
  158. controller.resetDbNamespace.restore();
  159. App.router.get.restore();
  160. container.updateAll.restore();
  161. });
  162. it("resetDbNamespace should be called", function() {
  163. expect(controller.resetDbNamespace.calledOnce).to.be.true;
  164. });
  165. it("updateAll should be called", function() {
  166. expect(container.updateAll.calledOnce).to.be.true;
  167. });
  168. it("isFinished should be true", function() {
  169. expect(controller.get('isFinished')).to.be.true;
  170. });
  171. });
  172. });