step1_view_test.js 17 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517
  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('views/wizard/step1_view');
  20. var view;
  21. var controller;
  22. function getView() {
  23. return App.WizardStep1View.create();
  24. }
  25. describe('App.WizardStep1View', function () {
  26. App.TestAliases.testAsComputedAnd(getView(), 'showErrorsWarningCount', ['isSubmitDisabled', 'totalErrorCnt']);
  27. describe('#operatingSystems', function () {
  28. beforeEach(function () {
  29. sinon.stub(App.Stack, 'find', function () {
  30. return [
  31. Ember.Object.create({
  32. id: 'HDP-1.3',
  33. stackName: 'HDP',
  34. stackVersion: '1.3',
  35. active: true,
  36. operatingSystems: [
  37. Ember.Object.create({
  38. id: 'HDP-1.3-redhat5',
  39. osType: 'redhat5',
  40. isSelected: false,
  41. repositories: [
  42. Ember.Object.create({
  43. id: 'redhat5-HDP-1.3',
  44. isSelected: false
  45. }),
  46. Ember.Object.create({
  47. id: 'redhat5-HDP-UTILS-1.1.0.19',
  48. isSelected: false
  49. })
  50. ]
  51. }),
  52. Ember.Object.create({
  53. id: 'HDP-1.3-redhat6',
  54. osType: 'redhat6',
  55. isSelected: false,
  56. repositories: [
  57. Ember.Object.create({
  58. id: 'redhat6-HDP-1.3',
  59. isSelected: false
  60. }),
  61. Ember.Object.create({
  62. id: 'redhat6-HDP-UTILS-1.1.0.19',
  63. isSelected: false
  64. })
  65. ]
  66. })
  67. ],
  68. isSelected: false
  69. }),
  70. Ember.Object.create({
  71. id: 'HDP-2.1',
  72. stackName: 'HDP',
  73. stackVersion: '2.1',
  74. active: true,
  75. operatingSystems: [
  76. Ember.Object.create({
  77. id: 'HDP-2.1-redhat5',
  78. osType: 'redhat5',
  79. isSelected: true,
  80. repositories: [
  81. Ember.Object.create({
  82. id: 'redhat5-HDP-2.1',
  83. isSelected: true,
  84. baseUrl: "http://public-repo-1.hortonworks.com/HDP/centos5/2.x/updates/2.1.5.0",
  85. latestBaseUrl: "http://public-repo-1.hortonworks.com/HDP/centos5/2.x/updates/2.1.5.0"
  86. }),
  87. Ember.Object.create({
  88. id: 'redhat5-HDP-UTILS-1.1.0.19',
  89. isSelected: true,
  90. baseUrl: "http://s3.amazonaws.com/dev.hortonworks.com/HDP-UTILS-1.1.0.19/repos/centos5",
  91. latestBaseUrl: "http://s3.amazonaws.com/dev.hortonworks.com/HDP-UTILS-1.1.0.19/repos/centos5"
  92. })
  93. ]
  94. }),
  95. Ember.Object.create({
  96. id: 'HDP-2.1-redhat6',
  97. osType: 'redhat6',
  98. isSelected: true,
  99. repositories: [
  100. Ember.Object.create({
  101. id: 'redhat6-HDP-2.1',
  102. isSelected: true,
  103. baseUrl: "http://public-repo-1.hortonworks.com/HDP/centos6/2.x/updates/2.1.5.0",
  104. latestBaseUrl: "http://public-repo-1.hortonworks.com/HDP/centos6/2.x/updates/2.1.5.0"
  105. }),
  106. Ember.Object.create({
  107. id: 'redhat6-HDP-UTILS-1.1.0.19',
  108. isSelected: true,
  109. baseUrl: "http://s3.amazonaws.com/dev.hortonworks.com/HDP-UTILS-1.1.0.19/repos/centos6",
  110. latestBaseUrl: "http://s3.amazonaws.com/dev.hortonworks.com/HDP-UTILS-1.1.0.19/repos/centos6"
  111. })
  112. ]
  113. })
  114. ],
  115. repositories: [
  116. Ember.Object.create({
  117. id: 'redhat5-HDP-2.1',
  118. isSelected: true,
  119. baseUrl: "http://public-repo-1.hortonworks.com/HDP/centos5/2.x/updates/2.1.5.0",
  120. latestBaseUrl: "http://public-repo-1.hortonworks.com/HDP/centos5/2.x/updates/2.1.5.0"
  121. }),
  122. Ember.Object.create({
  123. id: 'redhat5-HDP-UTILS-1.1.0.19',
  124. isSelected: true,
  125. baseUrl: "http://s3.amazonaws.com/dev.hortonworks.com/HDP-UTILS-1.1.0.19/repos/centos5",
  126. latestBaseUrl: "http://s3.amazonaws.com/dev.hortonworks.com/HDP-UTILS-1.1.0.19/repos/centos5"
  127. }),
  128. Ember.Object.create({
  129. id: 'redhat6-HDP-2.1',
  130. isSelected: true,
  131. baseUrl: "http://public-repo-1.hortonworks.com/HDP/centos6/2.x/updates/2.1.5.0",
  132. latestBaseUrl: "http://public-repo-1.hortonworks.com/HDP/centos6/2.x/updates/2.1.5.0"
  133. }),
  134. Ember.Object.create({
  135. id: 'redhat6-HDP-UTILS-1.1.0.19',
  136. isSelected: true,
  137. baseUrl: "http://s3.amazonaws.com/dev.hortonworks.com/HDP-UTILS-1.1.0.19/repos/centos6",
  138. latestBaseUrl: "http://s3.amazonaws.com/dev.hortonworks.com/HDP-UTILS-1.1.0.19/repos/centos6"
  139. })
  140. ],
  141. isSelected: true
  142. })
  143. ];
  144. });
  145. });
  146. afterEach(function () {
  147. App.Stack.find.restore();
  148. });
  149. it('should create empty array if there is no stacks', function () {
  150. controller = App.WizardStep1Controller.create({
  151. content: {
  152. stacks: []
  153. },
  154. selectedStack: []
  155. });
  156. view = App.WizardStep1View.create();
  157. view.reopen({
  158. controller: controller
  159. });
  160. expect(view.get('allRepositories.length')).to.equal(0);
  161. expect(view.get('operatingSystems.length')).to.equal(0);
  162. });
  163. it('should create repo groups from repo list', function () {
  164. controller = App.WizardStep1Controller.create({
  165. content: {
  166. stacks: App.Stack.find()
  167. }
  168. });
  169. view = App.WizardStep1View.create({'controller': controller});
  170. view.set('$', function () {
  171. return Em.Object.create({hide: Em.K, toggle: Em.K});
  172. });
  173. var repositories = view.get('allRepositories');
  174. expect(view.get('operatingSystems.length')).to.equal(2);
  175. expect(view.get('operatingSystems')[0].get('osType')).to.equal('redhat5');
  176. expect(view.get('operatingSystems')[1].get('osType')).to.equal('redhat6');
  177. expect(view.get('operatingSystems')[0].get('isSelected')).to.be.true;
  178. expect(view.get('operatingSystems')[1].get('isSelected')).to.be.true;
  179. expect(view.get('operatingSystems')[0].get('repositories')).to.eql([repositories[0], repositories[1]]);
  180. expect(view.get('operatingSystems')[1].get('repositories')).to.eql([repositories[2], repositories[3]]);
  181. });
  182. });
  183. describe('#invalidFormatUrlExist', function () {
  184. controller = App.WizardStep1Controller.create({
  185. content: {
  186. stacks: App.Stack.find()
  187. }
  188. });
  189. view = App.WizardStep1View.create();
  190. view.reopen({
  191. controller: controller
  192. });
  193. view.set('$', function () {
  194. return Em.Object.create({hide: Em.K, toggle: Em.K});
  195. });
  196. it(view.get('allRepositories').mapProperty('invalidFormatError').join(', '), function () {
  197. expect(view.get('invalidFormatUrlExist')).to.equal(false);
  198. });
  199. });
  200. App.TestAliases.testAsComputedEveryBy(getView(), 'isNoOsChecked', 'operatingSystems', 'isSelected', false);
  201. App.TestAliases.testAsComputedOr(getView(), 'isSubmitDisabled', ['invalidFormatUrlExist', 'isNoOsChecked', 'invalidUrlExist', 'controller.content.isCheckInProgress']);
  202. describe('#stacks', function () {
  203. var tests = Em.A([
  204. {
  205. m: 'Stack with 2 HDP',
  206. stacks: [
  207. Em.Object.create({isSelected: true, id: 'HDP-2.0.1'}),
  208. Em.Object.create({isSelected: false, id: 'HDP-1.3.3'})
  209. ],
  210. e: {
  211. names: ['HDP 2.0.1', 'HDP 1.3.3'],
  212. selected: [true, false]
  213. }
  214. },
  215. {
  216. m: 'No HDP',
  217. stacks: [],
  218. e: {
  219. names: [],
  220. selected: []
  221. }
  222. }
  223. ]);
  224. tests.forEach(function (test) {
  225. it(test.m, function () {
  226. view.set('controller.content.stacks', test.stacks);
  227. var stacks = view.get('stacks');
  228. expect(stacks.mapProperty('name')).to.eql(test.e.names);
  229. expect(stacks.mapProperty('isSelected')).to.eql(test.e.selected);
  230. });
  231. });
  232. });
  233. App.TestAliases.testAsComputedSomeBy(getView(), 'invalidUrlExist', 'allRepositories', 'validation', App.Repository.validation['INVALID']);
  234. App.TestAliases.testAsComputedSomeBy(getView(), 'invalidFormatUrlExist', 'allRepositories', 'invalidFormatError', true);
  235. describe('#totalErrorCnt', function () {
  236. var tests = Em.A([
  237. {
  238. allRepositories: [
  239. {}
  240. ],
  241. m: 'isNoOsChecked',
  242. isNoOsChecked: true,
  243. e: 1
  244. },
  245. {
  246. allRepositories: [
  247. {'invalidFormatError': true},
  248. {'invalidFormatError': true}
  249. ],
  250. isNoOsChecked: false,
  251. m: 'two with empty-error',
  252. e: 2
  253. },
  254. {
  255. allRepositories: [
  256. {'validation': 'icon-exclamation-sign'},
  257. {'validation': 'icon-exclamation-sign'}
  258. ],
  259. isNoOsChecked: false,
  260. m: 'two with validation="icon-exclamation-sign"',
  261. e: 2
  262. },
  263. {
  264. allRepositories: [
  265. {'invalidFormatError': true, 'validation': 'icon-exclamation-sign'},
  266. {'invalidFormatError': true, 'validation': 'icon-exclamation-sign'}
  267. ],
  268. isNoOsChecked: false,
  269. m: 'two with empty-error, two with validation="icon-exclamation-sign"',
  270. e: 4
  271. },
  272. {
  273. allRepositories: [
  274. {}
  275. ],
  276. isNoOsChecked: false,
  277. m: 'no errors/warnings etc',
  278. e: 0
  279. }
  280. ]);
  281. tests.forEach(function (test) {
  282. it(test.m, function () {
  283. view = App.WizardStep1View.create();
  284. view.reopen({
  285. isNoOsChecked: test.isNoOsChecked,
  286. allRepositories: test.allRepositories
  287. });
  288. expect(view.get('totalErrorCnt')).to.equal(test.e);
  289. });
  290. });
  291. });
  292. describe('#didInsertElement', function () {
  293. it('should create tooltip', function () {
  294. sinon.stub($.fn, 'tooltip', Em.K);
  295. view.set('isRLCollapsed', false);
  296. view.didInsertElement();
  297. expect($.fn.tooltip.calledOnce).to.equal(true);
  298. $.fn.tooltip.restore();
  299. });
  300. });
  301. describe('#stackRadioButton', function () {
  302. var v;
  303. beforeEach(function () {
  304. v = view.get('stackRadioButton').create({
  305. content: Em.Object.create({
  306. name: ''
  307. }),
  308. controller: Em.Object.create({
  309. content: Em.Object.create({
  310. stacks: []
  311. })
  312. })
  313. });
  314. });
  315. describe('#isSelected', function () {
  316. it('should be equal content.isSelected', function () {
  317. v.set('content.isSelected', true);
  318. expect(v.get('checked')).to.equal(true);
  319. v.set('content.isSelected', false);
  320. expect(v.get('checked')).to.equal(false);
  321. });
  322. });
  323. describe('#click', function () {
  324. it('should select proper stack', function () {
  325. v.set('controller.content.stacks', Em.A([Em.Object.create({id: 'n-1'}), Em.Object.create({id: 'n-2'}), Em.Object.create({id: 'n-3'})]));
  326. v.set('content.name', 'n 2');
  327. v.click();
  328. expect(v.get('controller.content.stacks').getEach('isSelected')).to.eql([false, true, false]);
  329. });
  330. });
  331. });
  332. describe('#popoverView', function () {
  333. var v;
  334. beforeEach(function () {
  335. v = view.get('popoverView').create();
  336. sinon.stub(App, 'popover', Em.K);
  337. view = App.WizardStep1View.create({'controller': controller});
  338. view.set('$', function () {
  339. return Em.Object.create({hide: Em.K, toggle: Em.K});
  340. });
  341. });
  342. afterEach(function () {
  343. App.popover.restore();
  344. });
  345. describe('#didInsertElement', function () {
  346. it('should create popover', function () {
  347. v.didInsertElement();
  348. expect(App.popover.calledOnce).to.equal(true);
  349. });
  350. });
  351. });
  352. describe('#onToggleBlock', function () {
  353. it('should toggle isRLCollapsed', function () {
  354. view.set('isRLCollapsed', true);
  355. view.onToggleBlock();
  356. expect(view.get('isRLCollapsed')).to.equal(false);
  357. view.onToggleBlock();
  358. expect(view.get('isRLCollapsed')).to.equal(true);
  359. });
  360. });
  361. describe('#updateByCheckbox', function () {
  362. var operatingSystems = [
  363. Em.Object.create({
  364. name: 'redhat5',
  365. isSelected: false,
  366. repositories: [Em.Object.create({
  367. id: 'id',
  368. osType: 'redhat5',
  369. baseUrl: 'baseUrl',
  370. latestBaseUrl: 'latestBaseUrl',
  371. validation: '',
  372. isSelected: false
  373. })
  374. ]
  375. })
  376. ];
  377. var controller = {
  378. content: {
  379. stacks: [
  380. Em.Object.create({
  381. isSelected: true,
  382. operatingSystems: [
  383. Em.Object.create({
  384. id: 'id',
  385. osType: 'redhat5',
  386. baseUrl: 'baseUrl',
  387. latestBaseUrl: 'latestBaseUrl',
  388. validation: '',
  389. isSelected: false
  390. })
  391. ]
  392. })
  393. ]
  394. },
  395. selectedStack: Em.Object.create({
  396. isSelected: true,
  397. operatingSystems: [
  398. Em.Object.create({
  399. id: 'id',
  400. osType: 'redhat5',
  401. baseUrl: 'baseUrl',
  402. latestBaseUrl: 'latestBaseUrl',
  403. validation: '',
  404. isSelected: true
  405. })
  406. ]
  407. }),
  408. skipValidationChecked: true
  409. };
  410. it('target group isn\'t isSelected', function () {
  411. view.reopen({
  412. operatingSystems: operatingSystems,
  413. controller: controller
  414. });
  415. view.updateByCheckbox();
  416. var targetGroup = view.get('operatingSystems.firstObject.repositories.firstObject');
  417. expect(targetGroup.get('baseUrl')).to.equal('latestBaseUrl');
  418. expect(targetGroup.get('latestBaseUrl')).to.equal('latestBaseUrl');
  419. expect(targetGroup.get('validation')).to.be.empty;
  420. });
  421. it('target group is isSelected, skipValidationisSelected = true', function () {
  422. controller.content.stacks[0].operatingSystems[0].selected = true;
  423. operatingSystems[0].set('isSelected', true);
  424. view.reopen({
  425. operatingSystems: operatingSystems,
  426. controller: controller
  427. });
  428. view.updateByCheckbox();
  429. var targetGroup = view.get('operatingSystems.firstObject.repositories.firstObject');
  430. expect(targetGroup.get('validation')).to.be.empty;
  431. });
  432. });
  433. describe('#clearGroupLocalRepository', function () {
  434. var context = {'group-number': 0, id: 'HDP-redhat5', repoId: 'HDP-redhat5', baseUrl: 'baseUrl', validation: 'validation'};
  435. it('should empty base url and validation', function () {
  436. var event = {context: Em.Object.create(context, {isSelected: true})};
  437. view.clearGroupLocalRepository(event);
  438. expect(event.context.get('baseUrl')).to.be.empty;
  439. expect(event.context.get('validation')).to.be.empty;
  440. });
  441. it('should do nothing if corresponding OS is not selected', function () {
  442. var event = {context: Em.Object.create(context, {isSelected: false})};
  443. view.clearGroupLocalRepository(event);
  444. expect(event.context.get('baseUrl')).to.equal('baseUrl');
  445. expect(event.context.get('validation')).to.equal('validation');
  446. });
  447. });
  448. describe('#undoGroupLocalRepository', function () {
  449. it('should reset base url and validation', function () {
  450. var event = {context: Em.Object.create({'group-number': 0, id: 'HDP-redhat5', repoId: 'HDP-redhat5', latestBaseUrl: 'latestBaseUrl', validation: 'validation'})};
  451. view.undoGroupLocalRepository(event);
  452. expect(event.context.get('baseUrl')).to.equal(event.context.get('latestBaseUrl'));
  453. expect(event.context.get('validation')).to.be.empty;
  454. });
  455. });
  456. describe('#editLocalRepository', function () {
  457. it('should update repository', function () {
  458. view.reopen({
  459. allRepositories: [
  460. Em.Object.create({
  461. isSelected: true,
  462. baseUrl: 'b1',
  463. validation: 'icon-exclamation-sign'
  464. })
  465. ]
  466. });
  467. view.editLocalRepository();
  468. var repository = view.get('allRepositories.firstObject');
  469. expect(repository.get('lastBaseUrl')).to.equal(repository.get('baseUrl'));
  470. expect(repository.get('validation')).to.be.empty;
  471. });
  472. });
  473. });