step3_view_test.js 17 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556
  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('messages');
  20. require('views/wizard/step3_view');
  21. var v;
  22. function getView() {
  23. return App.WizardStep3View.create({
  24. monitorStatuses: function () {
  25. },
  26. content: [
  27. Em.Object.create({
  28. name: 'host1',
  29. bootStatus: 'PENDING',
  30. isChecked: false
  31. }),
  32. Em.Object.create({
  33. name: 'host2',
  34. bootStatus: 'PENDING',
  35. isChecked: true
  36. }),
  37. Em.Object.create({
  38. name: 'host3',
  39. bootStatus: 'PENDING',
  40. isChecked: true
  41. })
  42. ],
  43. pageContent: function () {
  44. return this.get('content');
  45. }.property('content')
  46. });
  47. }
  48. describe('App.WizardStep3View', function () {
  49. var view = getView();
  50. describe('#watchSelection', function () {
  51. it('2 of 3 hosts selected', function () {
  52. view.watchSelection();
  53. expect(view.get('noHostsSelected')).to.equal(false);
  54. expect(view.get('selectedHostsCount')).to.equal(2);
  55. });
  56. it('all hosts selected', function () {
  57. view.selectAll();
  58. view.watchSelection();
  59. expect(view.get('noHostsSelected')).to.equal(false);
  60. expect(view.get('selectedHostsCount')).to.equal(3);
  61. });
  62. it('none hosts selected', function () {
  63. view.unSelectAll();
  64. view.watchSelection();
  65. expect(view.get('noHostsSelected')).to.equal(true);
  66. expect(view.get('selectedHostsCount')).to.equal(0);
  67. });
  68. });
  69. describe('#selectAll', function () {
  70. it('select all hosts', function () {
  71. view.selectAll();
  72. expect(view.get('content').everyProperty('isChecked', true)).to.equal(true);
  73. });
  74. });
  75. describe('#unSelectAll', function () {
  76. it('unselect all hosts', function () {
  77. view.unSelectAll();
  78. expect(view.get('content').everyProperty('isChecked', false)).to.equal(true);
  79. });
  80. });
  81. var testCases = Em.A([
  82. {
  83. title: 'none hosts',
  84. content: [],
  85. result: {
  86. "ALL": 0,
  87. "RUNNING": 0,
  88. "REGISTERING": 0,
  89. "REGISTERED": 0,
  90. "FAILED": 0
  91. }
  92. },
  93. {
  94. title: 'all hosts RUNNING',
  95. content: [
  96. Em.Object.create({
  97. name: 'host1',
  98. bootStatus: 'RUNNING'
  99. }),
  100. Em.Object.create({
  101. name: 'host2',
  102. bootStatus: 'RUNNING'
  103. }),
  104. Em.Object.create({
  105. name: 'host3',
  106. bootStatus: 'RUNNING'
  107. })
  108. ],
  109. result: {
  110. "ALL": 3,
  111. "RUNNING": 3,
  112. "REGISTERING": 0,
  113. "REGISTERED": 0,
  114. "FAILED": 0
  115. }
  116. },
  117. {
  118. title: 'all hosts REGISTERING',
  119. content: [
  120. Em.Object.create({
  121. name: 'host1',
  122. bootStatus: 'REGISTERING'
  123. }),
  124. Em.Object.create({
  125. name: 'host2',
  126. bootStatus: 'REGISTERING'
  127. }),
  128. Em.Object.create({
  129. name: 'host3',
  130. bootStatus: 'REGISTERING'
  131. })
  132. ],
  133. result: {
  134. "ALL": 3,
  135. "RUNNING": 0,
  136. "REGISTERING": 3,
  137. "REGISTERED": 0,
  138. "FAILED": 0
  139. }
  140. },
  141. {
  142. title: 'all hosts REGISTERED',
  143. content: [
  144. Em.Object.create({
  145. name: 'host1',
  146. bootStatus: 'REGISTERED'
  147. }),
  148. Em.Object.create({
  149. name: 'host2',
  150. bootStatus: 'REGISTERED'
  151. }),
  152. Em.Object.create({
  153. name: 'host3',
  154. bootStatus: 'REGISTERED'
  155. })
  156. ],
  157. result: {
  158. "ALL": 3,
  159. "RUNNING": 0,
  160. "REGISTERING": 0,
  161. "REGISTERED": 3,
  162. "FAILED": 0
  163. }
  164. },
  165. {
  166. title: 'all hosts FAILED',
  167. content: [
  168. Em.Object.create({
  169. name: 'host1',
  170. bootStatus: 'FAILED'
  171. }),
  172. Em.Object.create({
  173. name: 'host2',
  174. bootStatus: 'FAILED'
  175. }),
  176. Em.Object.create({
  177. name: 'host3',
  178. bootStatus: 'FAILED'
  179. })
  180. ],
  181. result: {
  182. "ALL": 3,
  183. "RUNNING": 0,
  184. "REGISTERING": 0,
  185. "REGISTERED": 0,
  186. "FAILED": 3
  187. }
  188. },
  189. {
  190. title: 'first host is FAILED, second is RUNNING, third is REGISTERED',
  191. content: [
  192. Em.Object.create({
  193. name: 'host1',
  194. bootStatus: 'FAILED'
  195. }),
  196. Em.Object.create({
  197. name: 'host2',
  198. bootStatus: 'RUNNING'
  199. }),
  200. Em.Object.create({
  201. name: 'host3',
  202. bootStatus: 'REGISTERED'
  203. })
  204. ],
  205. result: {
  206. "ALL": 3,
  207. "RUNNING": 1,
  208. "REGISTERING": 0,
  209. "REGISTERED": 1,
  210. "FAILED": 1
  211. }
  212. },
  213. {
  214. title: 'two hosts is REGISTERING, one is REGISTERED',
  215. content: [
  216. Em.Object.create({
  217. name: 'host1',
  218. bootStatus: 'REGISTERING'
  219. }),
  220. Em.Object.create({
  221. name: 'host2',
  222. bootStatus: 'REGISTERING'
  223. }),
  224. Em.Object.create({
  225. name: 'host3',
  226. bootStatus: 'REGISTERED'
  227. })
  228. ],
  229. result: {
  230. "ALL": 3,
  231. "RUNNING": 0,
  232. "REGISTERING": 2,
  233. "REGISTERED": 1,
  234. "FAILED": 0
  235. }
  236. }
  237. ]);
  238. describe('#countCategoryHosts', function () {
  239. var _view;
  240. testCases.forEach(function (test) {
  241. describe(test.title, function () {
  242. beforeEach(function () {
  243. _view = getView();
  244. _view.set('content', test.content);
  245. _view.countCategoryHosts();
  246. });
  247. Object.keys(test.result).forEach(function (categoryName) {
  248. it('`' + categoryName + '`', function () {
  249. expect(_view.get('categories').findProperty('hostsBootStatus', categoryName).get('hostsCount')).to.be.equal(test.result[categoryName])
  250. });
  251. });
  252. });
  253. }, this);
  254. });
  255. describe('#doFilter', function () {
  256. testCases.forEach(function (test) {
  257. describe(test.title, function () {
  258. view.get('categories').forEach(function (category) {
  259. it('. Selected category - ' + category.get('hostsBootStatus'), function () {
  260. view.set('content', test.content);
  261. view.reopen({
  262. selectedCategory: category
  263. });
  264. view.doFilter();
  265. expect(view.get('filteredContent').length).to.equal(test.result[category.get('hostsBootStatus')])
  266. });
  267. });
  268. });
  269. }, this);
  270. });
  271. describe('#monitorStatuses', function() {
  272. var tests = Em.A([
  273. {
  274. controller: Em.Object.create({bootHosts: Em.A([])}),
  275. m: 'Empty hosts list',
  276. e: {status: 'alert-warn', linkText: ''}
  277. },
  278. {
  279. controller: Em.Object.create({bootHosts: Em.A([{}]), isWarningsLoaded: false}),
  280. m: 'isWarningsLoaded false',
  281. e: {status: 'alert-info', linkText: ''}
  282. },
  283. {
  284. controller: Em.Object.create({bootHosts: Em.A([{}]), isWarningsLoaded: true, isHostHaveWarnings: true}),
  285. m: 'isWarningsLoaded true, isHostHaveWarnings true',
  286. e: {status: 'alert-warn', linkText: Em.I18n.t('installer.step3.warnings.linkText')}
  287. },
  288. {
  289. controller: Em.Object.create({bootHosts: Em.A([{}]), isWarningsLoaded: true, repoCategoryWarnings: ['']}),
  290. m: 'isWarningsLoaded true, repoCategoryWarnings not empty',
  291. e: {status: 'alert-warn', linkText: Em.I18n.t('installer.step3.warnings.linkText')}
  292. },
  293. {
  294. controller: Em.Object.create({bootHosts: Em.A([{}]), isWarningsLoaded: true, diskCategoryWarnings: ['']}),
  295. m: 'isWarningsLoaded true, diskCategoryWarnings not empty',
  296. e: {status: 'alert-warn', linkText: Em.I18n.t('installer.step3.warnings.linkText')}
  297. },
  298. {
  299. controller: Em.Object.create({bootHosts: Em.A([{}]), isWarningsLoaded: true, diskCategoryWarnings: [], repoCategoryWarnings: []}),
  300. m: 'isWarningsLoaded true, diskCategoryWarnings is empty, repoCategoryWarnings is empty',
  301. e: {status: 'alert-success', linkText: Em.I18n.t('installer.step3.noWarnings.linkText')}
  302. },
  303. {
  304. controller: Em.Object.create({bootHosts: Em.A([{bootStatus: 'FAILED'}]), isWarningsLoaded: true, diskCategoryWarnings: [], repoCategoryWarnings: []}),
  305. m: 'isWarningsLoaded true, diskCategoryWarnings is empty, repoCategoryWarnings is empty, all failed',
  306. e: {status: 'alert-warn', linkText: ''}
  307. }
  308. ]);
  309. tests.forEach(function(test) {
  310. it(test.m, function() {
  311. v = App.WizardStep3View.create({
  312. controller: test.controller
  313. });
  314. v.monitorStatuses();
  315. expect(v.get('status')).to.equal(test.e.status);
  316. expect(v.get('linkText')).to.equal(test.e.linkText);
  317. });
  318. });
  319. });
  320. describe('#retrySelectedHosts', function() {
  321. it('should set active category "All"', function() {
  322. view.set('controller', Em.Object.create({retrySelectedHosts: Em.K, registeredHosts: []}));
  323. view.retrySelectedHosts();
  324. expect(view.get('categories').findProperty('hostsBootStatus', 'ALL').get('isActive')).to.equal(true);
  325. });
  326. });
  327. describe('#selectCategory', function() {
  328. var tests = Em.A(['ALL','RUNNING','REGISTERING','REGISTERED','FAILED']);
  329. tests.forEach(function(test) {
  330. it('should set active category "' + test + '"', function() {
  331. view.set('controller', Em.Object.create({retrySelectedHosts: Em.K, registeredHosts: []}));
  332. view.selectCategory({context:Em.Object.create({hostsBootStatus:test})});
  333. expect(view.get('categories').findProperty('hostsBootStatus', test).get('isActive')).to.equal(true);
  334. });
  335. });
  336. });
  337. describe('#countCategoryHosts', function() {
  338. it('should set host count for each category', function() {
  339. view.set('content', Em.A([
  340. Em.Object.create({bootStatus: 'RUNNING'}),
  341. Em.Object.create({bootStatus: 'REGISTERING'}),
  342. Em.Object.create({bootStatus: 'REGISTERED'}),
  343. Em.Object.create({bootStatus: 'FAILED'})
  344. ]));
  345. view.countCategoryHosts();
  346. expect(view.get('categories').mapProperty('hostsCount')).to.eql([4,1,1,1,1]);
  347. });
  348. });
  349. describe('#hostBootStatusObserver', function() {
  350. beforeEach(function () {
  351. sinon.spy(Em.run, 'once');
  352. view.hostBootStatusObserver();
  353. });
  354. afterEach(function () {
  355. Em.run.once.restore();
  356. });
  357. it('should call "Em.run.once" three times', function() {
  358. expect(Em.run.once.firstCall.args[1]).to.equal('countCategoryHosts');
  359. expect(Em.run.once.secondCall.args[1]).to.equal('filter');
  360. expect(Em.run.once.thirdCall.args[1]).to.equal('monitorStatuses');
  361. });
  362. });
  363. describe('#watchSelection', function() {
  364. describe('should set "pageChecked"', function() {
  365. var tests = Em.A([
  366. {pageContent: Em.A([]),m:'false if empty "pageContent"', e: false},
  367. {pageContent: Em.A([{isChecked: false}]),m:'false if not-empty "pageContent" and not all "isChecked" true', e: false},
  368. {pageContent: Em.A([{isChecked: true}]),m:'true if not-empty "pageContent" and all "isChecked" true', e: false}
  369. ]);
  370. tests.forEach(function(test) {
  371. it(test.m, function() {
  372. view.set('pageContent', test.pageContent);
  373. view.watchSelection();
  374. expect(view.get('pageChecked')).to.equal(test.e);
  375. });
  376. });
  377. });
  378. describe('should set "noHostsSelected" and "selectedHostsCount"', function() {
  379. var tests = Em.A([
  380. {pageContent: Em.A([]),content:Em.A([]),m:' - "true", "0" if content is empty',e:{selectedHostsCount: 0, noHostsSelected: true}},
  381. {pageContent: Em.A([]),content:Em.A([Em.Object.create({isChecked: false})]),m:' - "true", "0" if no one isChecked',e:{selectedHostsCount: 0, noHostsSelected: true}},
  382. {pageContent: Em.A([]),content:Em.A([Em.Object.create({isChecked: true}),Em.Object.create({isChecked: false})]),m:' - "false", "1" if one isChecked',e:{selectedHostsCount: 1, noHostsSelected: false}}
  383. ]);
  384. tests.forEach(function(test) {
  385. it(test.m, function() {
  386. view.set('pageContent', test.pageContent);
  387. view.set('content', test.content);
  388. view.watchSelection();
  389. expect(view.get('noHostsSelected')).to.equal(test.e.noHostsSelected);
  390. expect(view.get('selectedHostsCount')).to.equal(test.e.selectedHostsCount);
  391. });
  392. });
  393. });
  394. });
  395. describe('#watchSelectionOnce', function() {
  396. beforeEach(function () {
  397. sinon.spy(Em.run, 'once');
  398. view.watchSelectionOnce();
  399. });
  400. afterEach(function () {
  401. Em.run.once.restore();
  402. });
  403. it('should call "Em.run.once" one time', function() {
  404. expect(Em.run.once.calledOnce).to.equal(true);
  405. expect(Em.run.once.firstCall.args[1]).to.equal('watchSelection');
  406. });
  407. });
  408. describe('#selectedCategory', function() {
  409. it('should equal category with isActive = true', function() {
  410. view.get('categories').findProperty('hostsBootStatus', 'FAILED').set('isActive', true);
  411. expect(view.get('selectedCategory.hostsBootStatus')).to.equal('FAILED');
  412. });
  413. });
  414. describe('#onPageChecked', function() {
  415. var tests = Em.A([
  416. {
  417. selectionInProgress: true,
  418. pageContent: [Em.Object.create({isChecked: true}), Em.Object.create({isChecked: false})],
  419. pageChecked: true,
  420. m: 'shouldn\'t do nothing if selectionInProgress is true',
  421. e: [true, false]
  422. },
  423. {
  424. selectionInProgress: false,
  425. pageContent: [Em.Object.create({isChecked: true}), Em.Object.create({isChecked: false})],
  426. pageChecked: true,
  427. m: 'should set each isChecked to pageChecked value',
  428. e: [true, true]
  429. }
  430. ]);
  431. tests.forEach(function(test) {
  432. it(test.m, function() {
  433. v = App.WizardStep3View.create({
  434. 'pageContent': test.pageContent,
  435. 'pageChecked': test.pageChecked,
  436. 'selectionInProgress': test.selectionInProgress
  437. });
  438. v.onPageChecked();
  439. expect(v.get('pageContent').mapProperty('isChecked')).to.eql(test.e);
  440. });
  441. });
  442. });
  443. describe('#didInsertElement', function() {
  444. beforeEach(function() {
  445. v = App.WizardStep3View.create({
  446. controller: Em.Object.create({
  447. loadStep: Em.K
  448. })
  449. });
  450. sinon.spy(v.get('controller'), 'loadStep');
  451. });
  452. afterEach(function() {
  453. v.get('controller').loadStep.restore();
  454. });
  455. it('should call loadStep', function() {
  456. v.didInsertElement();
  457. expect(v.get('controller').loadStep.calledOnce).to.equal(true);
  458. });
  459. });
  460. describe('#categoryObject', function() {
  461. var o;
  462. beforeEach(function() {
  463. v = App.WizardStep3View.create();
  464. o = v.get('categoryObject').create();
  465. });
  466. describe('#label', function() {
  467. it('should use value and hostCount', function() {
  468. o.setProperties({
  469. value: 'abc',
  470. hostsCount: 3
  471. });
  472. expect(o.get('label')).to.equal('abc (3)');
  473. });
  474. });
  475. describe('#itemClass', function() {
  476. it('should depends on isActive', function() {
  477. o.set('isActive', true);
  478. expect(o.get('itemClass')).to.equal('active');
  479. o.set('isActive', false);
  480. expect(o.get('itemClass')).to.equal('');
  481. });
  482. });
  483. });
  484. });
  485. var wView;
  486. describe('App.WizardHostView', function() {
  487. beforeEach(function() {
  488. wView = App.WizardHostView.create({
  489. hostInfo: {},
  490. controller: Em.Object.create({
  491. removeHost: Em.K,
  492. retryHost: Em.K
  493. })
  494. });
  495. sinon.spy(wView.get('controller'), 'retryHost');
  496. sinon.spy(wView.get('controller'), 'removeHost');
  497. });
  498. afterEach(function() {
  499. wView.get('controller').retryHost.restore();
  500. wView.get('controller').removeHost.restore();
  501. });
  502. describe('#retry', function() {
  503. it('should call controller.retryHost', function() {
  504. wView.retry();
  505. expect(wView.get('controller').retryHost.calledWith({})).to.equal(true);
  506. expect(wView.get('controller').retryHost.calledOnce).to.equal(true);
  507. });
  508. });
  509. describe('#remove', function() {
  510. it('should call controller.removeHost', function() {
  511. wView.remove();
  512. expect(wView.get('controller').removeHost.calledWith({})).to.equal(true);
  513. expect(wView.get('controller').removeHost.calledOnce).to.equal(true);
  514. });
  515. });
  516. });