step3_view_test.js 16 KB

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