step1_test.js 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401
  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 wizardStep1Controller;
  20. var stacks = [
  21. App.Stack.createRecord({
  22. "id": "HDP-2.4",
  23. "stackName": "HDP",
  24. "stackVersion": "2.4"
  25. }),
  26. App.Stack.createRecord({
  27. "id": "HDP-2.5-2.5.0.0",
  28. "stackName": "HDP",
  29. "stackVersion": "2.5"
  30. }),
  31. App.Stack.createRecord({
  32. "id": "HDP-2.5",
  33. "stackName": "HDP",
  34. "stackVersion": "2.5"
  35. }),
  36. App.Stack.createRecord({
  37. "id": "HDP-2.3.ECS",
  38. "stackName": "HDP",
  39. "stackVersion": "2.3.ECS"
  40. }),
  41. App.Stack.createRecord({
  42. "id": "HDP-2.3",
  43. "stackName": "HDP",
  44. "stackVersion": "2.3"
  45. }),
  46. App.Stack.createRecord({
  47. "id": "HDP-2.2",
  48. "stackName": "HDP",
  49. "stackVersion": "2.2"
  50. }),
  51. App.Stack.createRecord({
  52. "id": "HDP-2.4-2.4.1.1-12345",
  53. "stackName": "HDP",
  54. "stackVersion": "2.4"
  55. })
  56. ];
  57. function getController() {
  58. return App.WizardStep1Controller.create({content: Em.Object.create({stacks: stacks}), onNetworkIssuesExist: Em.K});
  59. }
  60. describe('App.WizardStep1Controller', function () {
  61. beforeEach(function() {
  62. wizardStep1Controller = getController();
  63. });
  64. App.TestAliases.testAsComputedFindBy(getController(), 'selectedStack', 'content.stacks', 'isSelected', true);
  65. App.TestAliases.testAsComputedFindBy(getController(), 'selectedStackType', 'availableStackTypes', 'isSelected', true);
  66. App.TestAliases.testAsComputedFilterBy(getController(), 'servicesForSelectedStack', 'selectedStack.stackServices', 'isHidden', false);
  67. App.TestAliases.testAsComputedEveryBy(getController(), 'networkIssuesExist', 'content.stacks', 'stackDefault', true);
  68. describe('#usePublicRepo', function () {
  69. beforeEach(function () {
  70. wizardStep1Controller.get('content.stacks').findProperty('id', 'HDP-2.5-2.5.0.0').setProperties({
  71. isSelected: true,
  72. useRedhatSatellite: true,
  73. usePublicRepo: false,
  74. useLocalRepo: true,
  75. });
  76. wizardStep1Controller.usePublicRepo();
  77. });
  78. it('correct stack is selected', function () {
  79. expect(wizardStep1Controller.get('selectedStack.id')).to.be.equal('HDP-2.5-2.5.0.0');
  80. });
  81. it('`useRedhatSatellite` is set `false`', function () {
  82. expect(wizardStep1Controller.get('selectedStack.useRedhatSatellite')).to.be.false;
  83. });
  84. it('`usePublicRepo` is set `true`', function () {
  85. expect(wizardStep1Controller.get('selectedStack.usePublicRepo')).to.be.true;
  86. });
  87. it('`useLocalRepo` is set `false`', function () {
  88. expect(wizardStep1Controller.get('selectedStack.useLocalRepo')).to.be.false;
  89. });
  90. });
  91. describe('#useLocalRepo', function () {
  92. beforeEach(function () {
  93. wizardStep1Controller.get('content.stacks').findProperty('id', 'HDP-2.5-2.5.0.0').setProperties({
  94. isSelected: true,
  95. usePublicRepo: true,
  96. useLocalRepo: false,
  97. });
  98. wizardStep1Controller.useLocalRepo();
  99. });
  100. it('correct stack is selected', function () {
  101. expect(wizardStep1Controller.get('selectedStack.id')).to.be.equal('HDP-2.5-2.5.0.0');
  102. });
  103. it('`usePublicRepo` is set `false`', function () {
  104. expect(wizardStep1Controller.get('selectedStack.usePublicRepo')).to.be.false;
  105. });
  106. it('`useLocalRepo` is set `true`', function () {
  107. expect(wizardStep1Controller.get('selectedStack.useLocalRepo')).to.be.true;
  108. });
  109. });
  110. describe('#selectStackBy', function () {
  111. it('select by `id`', function () {
  112. wizardStep1Controller.selectStackBy('id', 'HDP-2.5-2.5.0.0');
  113. expect(wizardStep1Controller.get('selectedStack.id')).to.be.equal('HDP-2.5-2.5.0.0');
  114. expect(wizardStep1Controller.get('content.stacks').filterProperty('isSelected')).to.have.property('length').equal(1);
  115. });
  116. it('select by `stackNameVersion`', function () {
  117. wizardStep1Controller.selectStackBy('stackNameVersion', 'HDP-2.5');
  118. expect(wizardStep1Controller.get('selectedStack.id')).to.be.equal('HDP-2.5-2.5.0.0'); // `HDP-2.5-2.5.0.0`-id is before `HDP-2.5`-id
  119. expect(wizardStep1Controller.get('content.stacks').filterProperty('isSelected')).to.have.property('length').equal(1);
  120. });
  121. });
  122. describe('#availableStackTypes', function () {
  123. it('stack types are sorted desc', function () {
  124. expect(wizardStep1Controller.get('availableStackTypes').mapProperty('stackName')).to.be.eql(['HDP-2.5', 'HDP-2.4', 'HDP-2.3.ECS', 'HDP-2.3', 'HDP-2.2']);
  125. });
  126. });
  127. describe('#readInfoIsNotProvided', function () {
  128. Em.A([
  129. {
  130. options: {
  131. uploadFile: {isSelected: false},
  132. enterUrl: {isSelected: false}
  133. },
  134. m: 'url and file are not selected',
  135. e: false
  136. },
  137. {
  138. options: {
  139. uploadFile: {isSelected: false},
  140. enterUrl: {isSelected: true, url: ''}
  141. },
  142. m: 'url is selected but not provided',
  143. e: true
  144. },
  145. {
  146. options: {
  147. uploadFile: {isSelected: false},
  148. enterUrl: {isSelected: true, url: ' url'}
  149. },
  150. m: 'url is selected and provided',
  151. e: false
  152. },
  153. {
  154. options: {
  155. uploadFile: {isSelected: true, file: ''},
  156. enterUrl: {isSelected: false}
  157. },
  158. m: 'file is selected but not provided',
  159. e: true
  160. },
  161. {
  162. options: {
  163. uploadFile: {isSelected: true, file: 'path'},
  164. enterUrl: {isSelected: false}
  165. },
  166. m: 'file is selected and provided',
  167. e: false
  168. }
  169. ]).forEach(function (test) {
  170. it(test.m, function () {
  171. wizardStep1Controller.set('optionsToSelect.useLocalRepo', test.options);
  172. expect(wizardStep1Controller.get('readInfoIsNotProvided')).to.be.equal(test.e);
  173. });
  174. });
  175. });
  176. describe('#uploadVdf', function () {
  177. function getModal() {
  178. var controller = getController();
  179. controller.set('optionsToSelect', Em.Object.create({
  180. useLocalRepo: {
  181. enterUrl: {isSelected: true, url: 'apache.org'},
  182. uploadFile: {isSelected: false, file: 'some_file'}
  183. }
  184. }));
  185. return controller.uploadVdf();
  186. }
  187. beforeEach(function () {
  188. this.modal = getModal();
  189. });
  190. describe('#restoreUploadOptions', function () {
  191. beforeEach(function () {
  192. wizardStep1Controller.set('optionsToSelect.useLocalRepo', {
  193. enterUrl: {isSelected: true, url: 'apache.org'},
  194. uploadFile: {isSelected: false, file: 'some_file'}
  195. });
  196. this.modal.restoreUploadOptions();
  197. });
  198. it('`enterUrl.isSelected`', function () {
  199. expect(this.modal.get('controller.optionsToSelect.useLocalRepo.enterUrl.isSelected')).to.be.false;
  200. });
  201. it('`enterUrl.url`', function () {
  202. expect(this.modal.get('controller.optionsToSelect.useLocalRepo.enterUrl.url')).to.be.equal('');
  203. });
  204. it('`uploadFile.isSelected`', function () {
  205. expect(this.modal.get('controller.optionsToSelect.useLocalRepo.uploadFile.isSelected')).to.be.true;
  206. });
  207. it('`uploadFile.file`', function () {
  208. expect(this.modal.get('controller.optionsToSelect.useLocalRepo.uploadFile.file')).to.be.equal('');
  209. });
  210. });
  211. describe('#bodyClass', function () {
  212. beforeEach(function () {
  213. this.body = this.modal.get('bodyClass').create();
  214. });
  215. describe('#uploadFileView', function () {
  216. beforeEach(function() {
  217. this.fileView = this.body.get('uploadFileView').create();
  218. });
  219. describe('#click', function () {
  220. beforeEach(function () {
  221. this.fileView.set('controller', getController());
  222. this.fileView.set('controller.optionsToSelect', {
  223. useLocalRepo: {
  224. enterUrl: {isSelected: true, hasError: true},
  225. uploadFile: {isSelected: false, hasError: true}
  226. }
  227. });
  228. this.fileView.click();
  229. });
  230. it('`enterUrl.isSelected`', function () {
  231. expect(this.fileView.get('controller.optionsToSelect.useLocalRepo.enterUrl.isSelected')).to.be.false;
  232. });
  233. it('`enterUrl.hasError`', function () {
  234. expect(this.fileView.get('controller.optionsToSelect.useLocalRepo.enterUrl.hasError')).to.be.false;
  235. });
  236. it('`uploadFile.isSelected`', function () {
  237. expect(this.fileView.get('controller.optionsToSelect.useLocalRepo.uploadFile.isSelected')).to.be.true;
  238. });
  239. it('`uploadFile.hasError`', function () {
  240. expect(this.fileView.get('controller.optionsToSelect.useLocalRepo.uploadFile.hasError')).to.be.false;
  241. });
  242. });
  243. });
  244. describe('#enterUrlView', function () {
  245. beforeEach(function() {
  246. this.fileView = this.body.get('enterUrlView').create();
  247. });
  248. describe('#click', function () {
  249. beforeEach(function () {
  250. this.fileView.set('controller', getController());
  251. this.fileView.set('controller.optionsToSelect', {
  252. useLocalRepo: {
  253. enterUrl: {isSelected: false, hasError: true},
  254. uploadFile: {isSelected: false, hasError: true}
  255. }
  256. });
  257. this.fileView.click();
  258. });
  259. it('`enterUrl.isSelected`', function () {
  260. expect(this.fileView.get('controller.optionsToSelect.useLocalRepo.enterUrl.isSelected')).to.be.true;
  261. });
  262. it('`enterUrl.hasError`', function () {
  263. expect(this.fileView.get('controller.optionsToSelect.useLocalRepo.enterUrl.hasError')).to.be.false;
  264. });
  265. it('`uploadFile.isSelected`', function () {
  266. expect(this.fileView.get('controller.optionsToSelect.useLocalRepo.uploadFile.isSelected')).to.be.false;
  267. });
  268. it('`uploadFile.hasError`', function () {
  269. expect(this.fileView.get('controller.optionsToSelect.useLocalRepo.uploadFile.hasError')).to.be.false;
  270. });
  271. });
  272. });
  273. });
  274. })
  275. describe('#removeOS', function() {
  276. beforeEach(function () {
  277. wizardStep1Controller.set('selectedStack', {useRedhatSatellite: null});
  278. });
  279. [
  280. {
  281. useRedhatSatellite: false,
  282. e: false,
  283. },
  284. {
  285. useRedhatSatellite: true,
  286. e: true
  287. }
  288. ].forEach(function (test) {
  289. it('useRedhatSatellite is ' + JSON.stringify(test.useRedhatSatellite), function () {
  290. wizardStep1Controller.set('selectedStack.useRedhatSatellite', test.useRedhatSatellite);
  291. var os = {isSelected: true};
  292. wizardStep1Controller.removeOS({context: os})
  293. expect(Ember.get(os, 'isSelected')).to.be.equal(test.e);
  294. });
  295. });
  296. });
  297. describe('#addOS', function() {
  298. it('should set `isSelected` to true', function () {
  299. var os = {isSelected: false};
  300. wizardStep1Controller.addOS({context: os})
  301. expect(Ember.get(os, 'isSelected')).to.be.true;
  302. });
  303. });
  304. describe('#onNetworkIssuesExist', function () {
  305. beforeEach(function () {
  306. this.controller = App.WizardStep1Controller.create({content: Em.Object.create({stacks: stacks})});
  307. this.controller.get('content.stacks').setEach('usePublicRepo', true);
  308. this.controller.get('content.stacks').setEach('useLocalRepo', false);
  309. this.controller.reopen({networkIssuesExist: true});
  310. this.controller.onNetworkIssuesExist();
  311. });
  312. it('each stack has `usePublicRepo` false', function() {
  313. expect(this.controller.get('content.stacks').everyProperty('usePublicRepo', false)).to.be.true;
  314. });
  315. it('each stack has `useLocalRepo` true', function() {
  316. expect(this.controller.get('content.stacks').everyProperty('useLocalRepo', true)).to.be.true;
  317. });
  318. });
  319. });