wizard_test.js 6.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218
  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. require('controllers/wizard');
  21. var c;
  22. describe('App.WizardController', function () {
  23. var wizardController = App.WizardController.create({});
  24. var totalSteps = 11;
  25. var ruller = [];
  26. for(var i = 0; i < totalSteps; i++) {
  27. ruller.push(i);
  28. }
  29. beforeEach(function () {
  30. c = App.WizardController.create({});
  31. });
  32. describe('#setLowerStepsDisable', function() {
  33. for(var i = 1; i < totalSteps; i++) {
  34. var indx = i;
  35. var steps = [];
  36. for(var j = 1; j <= indx; j++) {
  37. steps.push(Em.Object.create({step:j,value:false}));
  38. }
  39. wizardController.set('isStepDisabled', steps);
  40. for(j = 1; j <= indx; j++) {
  41. it('Steps: ' + i + ' | Disabled: ' + (j-1), function() {
  42. wizardController.setLowerStepsDisable(j);
  43. expect(wizardController.get('isStepDisabled').filterProperty('value', true).length).to.equal(j-1);
  44. });
  45. }
  46. }
  47. });
  48. // isStep0 ... isStep10 tests
  49. App.WizardController1 = App.WizardController.extend({currentStep:''});
  50. var tests = [];
  51. for(var i = 0; i < totalSteps; i++) {
  52. var n = ruller.slice(0);
  53. n.splice(i,1);
  54. tests.push({i:i,n:n});
  55. }
  56. tests.forEach(function(test) {
  57. describe('isStep'+test.i, function() {
  58. var w = App.WizardController1.create();
  59. w.set('currentStep', test.i);
  60. it('Current Step is ' + test.i + ', so isStep' + test.i + ' is TRUE', function() {
  61. expect(w.get('isStep'+ test.i)).to.equal(true);
  62. });
  63. test.n.forEach(function(indx) {
  64. it('Current Step is ' + test.i + ', so isStep' + indx + ' is FALSE', function() {
  65. expect(w.get('isStep'+ indx)).to.equal(false);
  66. });
  67. });
  68. });
  69. });
  70. // isStep0 ... isStep10 tests end
  71. describe('#gotoStep', function() {
  72. var w = App.WizardController1.create();
  73. var steps = [];
  74. for(var j = 0; j < totalSteps; j++) {
  75. steps.push(Em.Object.create({step:j,value:false}));
  76. }
  77. steps.forEach(function(step, index) {
  78. step.set('value', true);
  79. w.set('isStepDisabled', steps);
  80. it('step ' + index + ' is disabled, so gotoStep('+index+') is not possible', function() {
  81. expect(w.gotoStep(index)).to.equal(false);
  82. });
  83. });
  84. });
  85. describe('#launchBootstrapSuccessCallback', function() {
  86. it('Save bootstrapRequestId', function() {
  87. var data = {requestId: 123};
  88. var params = {popup: {finishLoading: function(){}}};
  89. sinon.spy(params.popup, "finishLoading");
  90. wizardController.launchBootstrapSuccessCallback(data, {}, params);
  91. expect(params.popup.finishLoading.calledWith(123)).to.be.true;
  92. params.popup.finishLoading.restore();
  93. });
  94. });
  95. describe('#getInstallOptions', function () {
  96. var cases = [
  97. {
  98. isHadoopWindowsStack: true,
  99. expected: {
  100. useSsh: false
  101. }
  102. },
  103. {
  104. isHadoopWindowsStack: false,
  105. expected: {
  106. useSsh: true
  107. }
  108. }
  109. ],
  110. title = 'should return {0}';
  111. beforeEach(function () {
  112. sinon.stub(wizardController, 'get')
  113. .withArgs('installOptionsTemplate').returns({useSsh: true})
  114. .withArgs('installWindowsOptionsTemplate').returns({useSsh: false});
  115. });
  116. afterEach(function () {
  117. App.get.restore();
  118. wizardController.get.restore();
  119. });
  120. cases.forEach(function (item) {
  121. it(title.format(item.expected), function () {
  122. sinon.stub(App, 'get').withArgs('isHadoopWindowsStack').returns(item.isHadoopWindowsStack);
  123. expect(wizardController.getInstallOptions()).to.eql(item.expected);
  124. });
  125. });
  126. });
  127. describe('#clearInstallOptions', function () {
  128. wizardController.setProperties({
  129. content: {},
  130. name: 'wizard'
  131. });
  132. beforeEach(function () {
  133. sinon.stub(App, 'get').withArgs('isHadoopWindowsStack').returns(false);
  134. });
  135. afterEach(function () {
  136. App.get.restore();
  137. });
  138. it('should clear install options', function () {
  139. wizardController.clearInstallOptions();
  140. expect(wizardController.get('content.installOptions')).to.eql(wizardController.get('installOptionsTemplate'));
  141. expect(wizardController.get('content.hosts')).to.eql({});
  142. expect(wizardController.getDBProperty('installOptions')).to.eql(wizardController.get('installOptionsTemplate'))
  143. expect(wizardController.getDBProperty('hosts')).to.eql({});
  144. });
  145. });
  146. describe('#saveServiceConfigProperties', function () {
  147. beforeEach(function () {
  148. c.set('content', {});
  149. sinon.stub(c, 'setDBProperty', Em.K);
  150. });
  151. afterEach(function () {
  152. c.setDBProperty.restore();
  153. });
  154. var stepController = Em.Object.create({
  155. installedServiceNames: [],
  156. stepConfigs: [
  157. Em.Object.create({
  158. serviceName: 'HDFS',
  159. configs: [
  160. Em.Object.create({
  161. id: 'id',
  162. name: 'name',
  163. value: 'value',
  164. defaultValue: 'defaultValue',
  165. description: 'description',
  166. serviceName: 'serviceName',
  167. domain: 'domain',
  168. isVisible: true,
  169. isFinal: true,
  170. defaultIsFinal: true,
  171. supportsFinal: true,
  172. filename: 'filename',
  173. displayType: 'string',
  174. isRequiredByAgent: true,
  175. hasInitialValue: true,
  176. isRequired: true,
  177. group: {name: 'group'},
  178. showLabel: true,
  179. category: 'some_category'
  180. })
  181. ]
  182. })
  183. ]});
  184. it('should save configs to content.serviceConfigProperties', function () {
  185. c.saveServiceConfigProperties(stepController);
  186. var saved = c.get('content.serviceConfigProperties');
  187. expect(saved.length).to.equal(1);
  188. expect(saved[0].category).to.equal('some_category');
  189. });
  190. });
  191. });