wizard_test.js 5.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162
  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. describe('App.WizardController', function () {
  22. var wizardController = App.WizardController.create({});
  23. var totalSteps = 11;
  24. var ruller = [];
  25. for(var i = 0; i < totalSteps; i++) {
  26. ruller.push(i);
  27. }
  28. describe('#setLowerStepsDisable', function() {
  29. for(var i = 1; i < totalSteps; i++) {
  30. var indx = i;
  31. var steps = [];
  32. for(var j = 1; j <= indx; j++) {
  33. steps.push(Em.Object.create({step:j,value:false}));
  34. }
  35. wizardController.set('isStepDisabled', steps);
  36. for(j = 1; j <= indx; j++) {
  37. it('Steps: ' + i + ' | Disabled: ' + (j-1), function() {
  38. wizardController.setLowerStepsDisable(j);
  39. expect(wizardController.get('isStepDisabled').filterProperty('value', true).length).to.equal(j-1);
  40. });
  41. }
  42. }
  43. });
  44. // isStep0 ... isStep10 tests
  45. App.WizardController1 = App.WizardController.extend({currentStep:''});
  46. var tests = [];
  47. for(var i = 0; i < totalSteps; i++) {
  48. var n = ruller.slice(0);
  49. n.splice(i,1);
  50. tests.push({i:i,n:n});
  51. }
  52. tests.forEach(function(test) {
  53. describe('isStep'+test.i, function() {
  54. var w = App.WizardController1.create();
  55. w.set('currentStep', test.i);
  56. it('Current Step is ' + test.i + ', so isStep' + test.i + ' is TRUE', function() {
  57. expect(w.get('isStep'+ test.i)).to.equal(true);
  58. });
  59. test.n.forEach(function(indx) {
  60. it('Current Step is ' + test.i + ', so isStep' + indx + ' is FALSE', function() {
  61. expect(w.get('isStep'+ indx)).to.equal(false);
  62. });
  63. });
  64. });
  65. });
  66. // isStep0 ... isStep10 tests end
  67. describe('#gotoStep', function() {
  68. var w = App.WizardController1.create();
  69. var steps = [];
  70. for(var j = 0; j < totalSteps; j++) {
  71. steps.push(Em.Object.create({step:j,value:false}));
  72. }
  73. steps.forEach(function(step, index) {
  74. step.set('value', true);
  75. w.set('isStepDisabled', steps);
  76. it('step ' + index + ' is disabled, so gotoStep('+index+') is not possible', function() {
  77. expect(w.gotoStep(index)).to.equal(false);
  78. });
  79. });
  80. });
  81. describe('#launchBootstrapSuccessCallback', function() {
  82. it('Save bootstrapRequestId', function() {
  83. var data = {requestId: 123};
  84. var params = {popup: {finishLoading: function(){}}};
  85. sinon.spy(params.popup, "finishLoading");
  86. wizardController.launchBootstrapSuccessCallback(data, {}, params);
  87. expect(params.popup.finishLoading.calledWith(123)).to.be.true;
  88. params.popup.finishLoading.restore();
  89. });
  90. });
  91. describe('#getInstallOptions', function () {
  92. var cases = [
  93. {
  94. isHadoopWindowsStack: true,
  95. expected: {
  96. useSsh: false
  97. }
  98. },
  99. {
  100. isHadoopWindowsStack: false,
  101. expected: {
  102. useSsh: true
  103. }
  104. }
  105. ],
  106. title = 'should return {0}';
  107. beforeEach(function () {
  108. sinon.stub(wizardController, 'get')
  109. .withArgs('installOptionsTemplate').returns({useSsh: true})
  110. .withArgs('installWindowsOptionsTemplate').returns({useSsh: false});
  111. });
  112. afterEach(function () {
  113. App.get.restore();
  114. wizardController.get.restore();
  115. });
  116. cases.forEach(function (item) {
  117. it(title.format(item.expected), function () {
  118. sinon.stub(App, 'get').withArgs('isHadoopWindowsStack').returns(item.isHadoopWindowsStack);
  119. expect(wizardController.getInstallOptions()).to.eql(item.expected);
  120. });
  121. });
  122. });
  123. describe('#clearInstallOptions', function () {
  124. wizardController.setProperties({
  125. content: {},
  126. name: 'wizard'
  127. });
  128. beforeEach(function () {
  129. sinon.stub(App, 'get').withArgs('isHadoopWindowsStack').returns(false);
  130. });
  131. afterEach(function () {
  132. App.get.restore();
  133. });
  134. it('should clear install options', function () {
  135. wizardController.clearInstallOptions();
  136. expect(wizardController.get('content.installOptions')).to.eql(wizardController.get('installOptionsTemplate'));
  137. expect(wizardController.get('content.hosts')).to.eql({});
  138. expect(wizardController.getDBProperty('installOptions')).to.eql(wizardController.get('installOptionsTemplate'))
  139. expect(wizardController.getDBProperty('hosts')).to.eql({});
  140. });
  141. });
  142. });