step2_test.js 8.2 KB

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