step2_test.js 8.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258
  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. var Ember = require('ember');
  20. require('controllers/wizard/step2_controller');
  21. require('models/host');
  22. require('messages');
  23. describe('App.WizardStep2Controller', function () {
  24. describe('#updateHostNameArr()', function () {
  25. var controller = App.WizardStep2Controller.create({
  26. hostNames: 'apache.ambari'
  27. });
  28. App.store.load(App.Host, {'host_name': 'apache.ambari', id: '1'});
  29. controller.updateHostNameArr();
  30. it('should push to hostNameArr only new host names', function(){
  31. expect(controller.get('hostNameArr').length).to.equal(0);
  32. })
  33. it('should push to inputtedAgainHostNames already installed host names', function(){
  34. expect(controller.get('inputtedAgainHostNames').length).to.equal(1);
  35. })
  36. })
  37. describe('#isAllHostNamesValid()', function () {
  38. var controller = App.WizardStep2Controller.create({
  39. hostNames: ''
  40. });
  41. it('should return true if all host names are valid', function(){
  42. controller.set('hostNames', 'amache ambari');
  43. expect(controller.isAllHostNamesValid()).to.equal(true);
  44. })
  45. /*it('should return false if there is invalid host names', function(){
  46. controller.set('hostNames', 'amache #@$ ambari');
  47. expect(controller.isAllHostNamesValid()).to.equal(false);
  48. })*/
  49. })
  50. describe('#checkHostError()', function () {
  51. var controller = App.WizardStep2Controller.create();
  52. it('should set hostsError if hostNames is ""', function () {
  53. controller.set('content', {'installOptions': {'hostNames': ''}});
  54. controller.checkHostError();
  55. expect(controller.get('hostsError').length).to.be.above(2);
  56. })
  57. /*it('should set hostsError if hostNames is invalid', function () {
  58. controller.set('content', {'installOptions': {'hostNames': '@#$%'}});
  59. controller.checkHostError();
  60. expect(controller.get('hostsError').length).to.be.above(2);
  61. })*/
  62. it('should set hostsError to null if hostNames is valid', function () {
  63. controller.set('content', {'installOptions': {'hostNames': 'ambari'}});
  64. controller.checkHostError();
  65. expect(controller.get('hostsError')).to.equal(null);
  66. })
  67. })
  68. describe('#checkHostAfterSubmitHandler()', function () {
  69. it('should be called after changing hasSubmitted', function (done) {
  70. var controller = App.WizardStep2Controller.create({
  71. checkHostError: function () {
  72. done();
  73. }
  74. });
  75. controller.set('hasSubmitted', true);
  76. })
  77. it('should be called after changing hostNames', function (done) {
  78. var controller = App.WizardStep2Controller.create({
  79. hasSubmitted: true,
  80. checkHostError: function () {
  81. done();
  82. }
  83. });
  84. controller.set('content', {'installOptions': {'hostNames': 'ambari'}});
  85. })
  86. })
  87. describe('#sshKeyError', function () {
  88. var controller = App.WizardStep2Controller.create({
  89. manualInstall: false,
  90. sshKey: '',
  91. hasSubmitted: true
  92. });
  93. it('should return error message if hasSubmitted is true, manualInstall is false and sshKey is ""', function () {
  94. expect(controller.get('sshKeyError').length).to.be.above(2);
  95. })
  96. it('should return null if hasSubmitted is false', function () {
  97. controller.set('hasSubmitted', false);
  98. expect(controller.get('sshKeyError')).to.equal(null);
  99. })
  100. })
  101. describe('#getHostInfo()', function () {
  102. it('should return object with bootStatus, installType and name for every element in hostNameArr', function () {
  103. var controller = App.WizardStep2Controller.create({
  104. hostNameArr: ['apache', 'ambari'],
  105. installType: 'manualDriven'
  106. });
  107. var test = controller.getHostInfo();
  108. expect(test).to.eql({
  109. 'apache':{'name':'apache', 'installType': 'manualDriven', 'bootStatus': 'PENDING'},
  110. 'ambari':{'name':'ambari', 'installType': 'manualDriven', 'bootStatus': 'PENDING'}
  111. });
  112. })
  113. })
  114. describe('#setSshKey()', function () {
  115. it('should set content.installOptions.sshKey', function () {
  116. var controller = App.WizardStep2Controller.create({
  117. content: {'installOptions': {'sshKey': '111'}}
  118. });
  119. controller.setSshKey('222');
  120. expect(controller.get('content.installOptions.sshKey')).to.equal('222');
  121. })
  122. })
  123. describe('#evaluateStep()', function () {
  124. it('should return false if isSubmitDisabled is true', function () {
  125. var controller = App.WizardStep2Controller.create({
  126. hostNames: 'apache.ambari'
  127. });
  128. controller.set('isSubmitDisabled', true);
  129. expect(controller.evaluateStep()).to.equal(false);
  130. })
  131. it('should return false if hostsError is not empty', function () {
  132. var controller = App.WizardStep2Controller.create({
  133. hostNames: 'apache.ambari'
  134. });
  135. controller.set('hostsError', 'error');
  136. expect(controller.evaluateStep()).to.equal(false);
  137. })
  138. it('should return false if sshKeyError is not empty', function () {
  139. var controller = App.WizardStep2Controller.create({
  140. hostNames: 'apache.ambari'
  141. });
  142. controller.set('sshKeyError', 'error');
  143. expect(controller.evaluateStep()).to.equal(false);
  144. })
  145. it('should return false if hostNameArr is empty', function () {
  146. var controller = App.WizardStep2Controller.create({
  147. hostNames: ''
  148. });
  149. expect(controller.evaluateStep()).to.equal(false);
  150. })
  151. it('should return false if isPattern is false', function () {
  152. var controller = App.WizardStep2Controller.create({
  153. hostNames: 'apache.ambari',
  154. isPattern: false
  155. });
  156. expect(controller.evaluateStep()).to.equal(false);
  157. })
  158. })
  159. describe('#patternExpression()', function () {
  160. it('should parse hosts from pattern expression to hostNameArr', function () {
  161. var controller = App.WizardStep2Controller.create({
  162. hostNameArr: ['host[001-011]']
  163. });
  164. controller.patternExpression();
  165. var result = true;
  166. var hosts = controller.get('hostNameArr');
  167. for (var i = 1; i<12; i++) {
  168. var extra = (i.toString().length == 1) ? 0 : '';
  169. if (hosts[i-1] !== 'host0' + extra + i) {
  170. result = false;
  171. }
  172. }
  173. expect(result).to.equal(true);
  174. })
  175. })
  176. describe('#proceedNext()', function () {
  177. it('should call manualInstallPopup if manualInstall is true', function (done) {
  178. var controller = App.WizardStep2Controller.create({
  179. manualInstall: true,
  180. manualInstallPopup: function () {
  181. done();
  182. }
  183. });
  184. controller.proceedNext();
  185. })
  186. })
  187. describe('#isSubmitDisabled', function () {
  188. var controller = App.WizardStep2Controller.create({
  189. hostsError: '',
  190. sshKeyError: ''
  191. });
  192. it('should return value if hostsError is not empty', function () {
  193. controller.set('hostsError', 'error');
  194. expect(controller.get('isSubmitDisabled').length).to.above(0);
  195. })
  196. it('should return value if sshKeyError is not empty', function () {
  197. controller.set('sshKeyError', 'error');
  198. controller.set('hostsError', '');
  199. expect(controller.get('isSubmitDisabled').length).to.above(0);
  200. })
  201. })
  202. describe('#saveHosts()', function () {
  203. it('should set content.hosts', function () {
  204. var controller = App.WizardStep2Controller.create({
  205. hostNameArr: ['ambari'],
  206. content:{'hosts':{}}
  207. });
  208. App.router = Ember.Object.create({
  209. send:function() {}
  210. });
  211. controller.saveHosts();
  212. expect(controller.get('content.hosts')).to.not.be.empty;
  213. })
  214. })
  215. })