step9_view_test.js 18 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721
  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/step9_view');
  20. var v;
  21. describe('App.WizardStep9View', function () {
  22. beforeEach(function () {
  23. v = App.WizardStep9View.create({
  24. controller: App.WizardStep9Controller.create()
  25. });
  26. });
  27. var view = App.WizardStep9View.create({
  28. onStatus: function () {
  29. },
  30. content: [],
  31. pageContent: function () {
  32. return this.get('content');
  33. }.property('content')
  34. });
  35. var testCases = [
  36. {
  37. title: 'none hosts',
  38. content: [],
  39. result: {
  40. "all": 0,
  41. "inProgress": 0,
  42. "warning": 0,
  43. "success": 0,
  44. "failed": 0
  45. }
  46. },
  47. {
  48. title: 'all hosts inProgress',
  49. content: [
  50. Em.Object.create({
  51. name: 'host1',
  52. status: 'in_progress'
  53. }),
  54. Em.Object.create({
  55. name: 'host2',
  56. status: 'info'
  57. }),
  58. Em.Object.create({
  59. name: 'host3',
  60. status: 'pending'
  61. })
  62. ],
  63. result: {
  64. "all": 3,
  65. "inProgress": 3,
  66. "warning": 0,
  67. "success": 0,
  68. "failed": 0
  69. }
  70. },
  71. {
  72. title: 'all hosts warning',
  73. content: [
  74. Em.Object.create({
  75. name: 'host1',
  76. status: 'warning'
  77. }),
  78. Em.Object.create({
  79. name: 'host2',
  80. status: 'warning'
  81. }),
  82. Em.Object.create({
  83. name: 'host3',
  84. status: 'warning'
  85. })
  86. ],
  87. result: {
  88. "all": 3,
  89. "inProgress": 0,
  90. "warning": 3,
  91. "success": 0,
  92. "failed": 0
  93. }
  94. },
  95. {
  96. title: 'all hosts success',
  97. content: [
  98. Em.Object.create({
  99. name: 'host1',
  100. status: 'success'
  101. }),
  102. Em.Object.create({
  103. name: 'host2',
  104. status: 'success'
  105. }),
  106. Em.Object.create({
  107. name: 'host3',
  108. status: 'success'
  109. })
  110. ],
  111. result: {
  112. "all": 3,
  113. "inProgress": 0,
  114. "warning": 0,
  115. "success": 3,
  116. "failed": 0
  117. }
  118. },
  119. {
  120. title: 'all hosts failed',
  121. content: [
  122. Em.Object.create({
  123. name: 'host1',
  124. status: 'failed'
  125. }),
  126. Em.Object.create({
  127. name: 'host2',
  128. status: 'failed'
  129. }),
  130. Em.Object.create({
  131. name: 'host3',
  132. status: 'heartbeat_lost'
  133. })
  134. ],
  135. result: {
  136. "all": 3,
  137. "inProgress": 0,
  138. "warning": 0,
  139. "success": 0,
  140. "failed": 3
  141. }
  142. },
  143. {
  144. title: 'first host is failed, second is warning, third is success',
  145. content: [
  146. Em.Object.create({
  147. name: 'host1',
  148. status: 'failed'
  149. }),
  150. Em.Object.create({
  151. name: 'host2',
  152. status: 'success'
  153. }),
  154. Em.Object.create({
  155. name: 'host3',
  156. status: 'warning'
  157. })
  158. ],
  159. result: {
  160. "all": 3,
  161. "inProgress": 0,
  162. "warning": 1,
  163. "success": 1,
  164. "failed": 1
  165. }
  166. },
  167. {
  168. title: 'two hosts is inProgress, one is success',
  169. content: [
  170. Em.Object.create({
  171. name: 'host1',
  172. status: 'pending'
  173. }),
  174. Em.Object.create({
  175. name: 'host2',
  176. status: 'in_progress'
  177. }),
  178. Em.Object.create({
  179. name: 'host3',
  180. status: 'success'
  181. })
  182. ],
  183. result: {
  184. "all": 3,
  185. "inProgress": 2,
  186. "warning": 0,
  187. "success": 1,
  188. "failed": 0
  189. }
  190. }
  191. ];
  192. describe('#countCategoryHosts', function () {
  193. testCases.forEach(function (test) {
  194. it(test.title, function () {
  195. view.set('content', test.content);
  196. view.countCategoryHosts();
  197. view.get('categories').forEach(function (category) {
  198. expect(category.get('hostsCount')).to.equal(test.result[category.get('hostStatus')])
  199. })
  200. });
  201. }, this);
  202. });
  203. describe('#doFilter', function () {
  204. testCases.forEach(function (test) {
  205. describe(test.title, function () {
  206. view.get('categories').forEach(function (category) {
  207. it('. Selected category - ' + category.get('hostStatus'), function () {
  208. view.set('content', test.content);
  209. view.reopen({selectedCategory: category});
  210. view.doFilter();
  211. expect(view.get('filteredContent').length).to.equal(test.result[category.get('hostStatus')])
  212. });
  213. })
  214. });
  215. }, this);
  216. });
  217. describe('#isStepCompleted', function () {
  218. it('should be true if progress is 100', function () {
  219. v.set('controller.progress', '100');
  220. expect(v.get('isStepCompleted')).to.equal(true);
  221. });
  222. it('should be false if progress isn\'t 100', function () {
  223. v.set('controller.progress', '50');
  224. expect(v.get('isStepCompleted')).to.equal(false);
  225. });
  226. });
  227. describe('#content', function () {
  228. var hosts = [{}, {}, {}];
  229. beforeEach(function () {
  230. sinon.stub(v, 'hostStatusObserver', Em.K);
  231. v.set('controller.hosts', hosts);
  232. });
  233. afterEach(function () {
  234. v.hostStatusObserver.restore();
  235. });
  236. it('should be equal to controller.hosts', function () {
  237. expect(v.get('content')).to.eql(hosts);
  238. });
  239. });
  240. describe('#categoryObject', function () {
  241. it('label should contains value and hostsCount', function () {
  242. var value = 'v',
  243. hostsCount = 10,
  244. o = v.get('categoryObject').create({value: value, hostsCount: hostsCount});
  245. expect(o.get('label')).to.equal(value + ' (' + hostsCount + ')');
  246. });
  247. it('itemClass should depends on isActive', function () {
  248. var o = v.get('categoryObject').create();
  249. o.set('isActive', false);
  250. expect(o.get('itemClass')).to.equal('');
  251. o.set('isActive', true);
  252. expect(o.get('itemClass')).to.equal('active');
  253. });
  254. });
  255. describe('#isHostHeartbeatLost', function () {
  256. Em.A([
  257. {
  258. hostsWithHeartbeatLost: [],
  259. m: 'should be false if hostsWithHeartbeatLost is empty',
  260. e: false
  261. },
  262. {
  263. hostsWithHeartbeatLost: [
  264. {},
  265. {}
  266. ],
  267. m: 'should be true if hostsWithHeartbeatLost contains some values',
  268. e: true
  269. }
  270. ]).forEach(function (test) {
  271. it(test.m, function () {
  272. v.set('controller.hostsWithHeartbeatLost', test.hostsWithHeartbeatLost);
  273. expect(v.get('isHostHeartbeatLost')).to.equal(test.e);
  274. })
  275. });
  276. });
  277. describe('#barWidth', function () {
  278. it('should depends on controller.progress', function () {
  279. var w = '25';
  280. v.set('controller.progress', w);
  281. expect(v.get('barWidth')).to.equal('width: ' + w + '%;');
  282. });
  283. });
  284. describe('#progressMessage', function () {
  285. it('should depends on controller.progress', function () {
  286. var w = '25';
  287. v.set('controller.progress', w);
  288. expect(v.get('progressMessage').contains(w)).to.equal(true);
  289. });
  290. });
  291. describe('#showAllHosts', function () {
  292. it('should set active to category with all hosts', function () {
  293. v.get('categories').findProperty('hostStatus', 'inProgress').set('isActive', true);
  294. v.showAllHosts();
  295. var allCategory = v.get('categories').findProperty('hostStatus', 'all');
  296. expect(allCategory.get('isActive')).to.equal(true);
  297. expect(v.get('categories').without(allCategory).everyProperty('isActive', false)).to.equal(true);
  298. });
  299. });
  300. describe('#didInsertElement', function () {
  301. beforeEach(function () {
  302. sinon.stub(v, 'onStatus', Em.K);
  303. sinon.stub(v.get('controller'), 'navigateStep', Em.K);
  304. });
  305. afterEach(function () {
  306. v.onStatus.restore();
  307. v.get('controller').navigateStep.restore();
  308. });
  309. it('should call onStatus', function () {
  310. v.didInsertElement();
  311. expect(v.onStatus.calledOnce).to.equal(true);
  312. });
  313. it('should call navigateStep', function () {
  314. v.didInsertElement();
  315. expect(v.get('controller').navigateStep.calledOnce).to.equal(true);
  316. });
  317. });
  318. describe('#selectCategory', function () {
  319. it('should set isActive true to selected category', function () {
  320. var event = {context: Em.Object.create({hostStatus: 'inProgress'})},
  321. c = v.get('categories').findProperty('hostStatus', 'inProgress');
  322. c.set('isActive', false);
  323. v.selectCategory(event);
  324. expect(c.get('isActive')).to.equal(true);
  325. });
  326. });
  327. describe('#onStatus', function () {
  328. Em.A([
  329. {
  330. status: 'success',
  331. e: {
  332. barColor: 'progress-success',
  333. resultMsg: Em.I18n.t('installer.step9.status.success'),
  334. resultMsgColor: 'alert-success'
  335. }
  336. },
  337. {
  338. status: 'info',
  339. e: {
  340. barColor: 'progress-info',
  341. resultMsg: ''
  342. }
  343. },
  344. {
  345. status: 'warning',
  346. e: {
  347. barColor: 'progress-warning',
  348. resultMsg: Em.I18n.t('installer.step9.status.warning'),
  349. resultMsgColor: 'alert-warning'
  350. }
  351. },
  352. {
  353. status: 'failed',
  354. e: {
  355. barColor: 'progress-danger',
  356. resultMsgColor: 'alert-error'
  357. }
  358. }
  359. ]).forEach(function (test) {
  360. it(test.status, function () {
  361. v.set('controller.status', test.status);
  362. v.onStatus();
  363. Em.keys(test.e).forEach(function (k) {
  364. expect(v.get(k)).to.equal(test.e[k]);
  365. });
  366. });
  367. });
  368. Em.A([
  369. {
  370. hostsWithHeartbeatLost: [
  371. {},
  372. {}
  373. ],
  374. startCallFailed: false,
  375. m: 'heartbeat lost for 2 hosts',
  376. resultMsg: Em.I18n.t('installer.step9.status.hosts.heartbeat_lost').format(2)
  377. },
  378. {
  379. hostsWithHeartbeatLost: [],
  380. startCallFailed: true,
  381. m: 'heartbeat not lost, startCallFailed true',
  382. resultMsg: Em.I18n.t('installer.step9.status.start.services.failed')
  383. },
  384. {
  385. hostsWithHeartbeatLost: [],
  386. startCallFailed: false,
  387. m: 'heartbeat not lost, startCallFailed false',
  388. resultMsg: Em.I18n.t('installer.step9.status.failed')
  389. }
  390. ]).forEach(function (test) {
  391. it(test.m, function () {
  392. v.set('controller.hostsWithHeartbeatLost', test.hostsWithHeartbeatLost);
  393. v.set('controller.startCallFailed', test.startCallFailed);
  394. v.set('controller.status', 'failed');
  395. v.onStatus();
  396. expect(v.get('resultMsg')).to.equal(test.resultMsg);
  397. });
  398. });
  399. });
  400. describe('#hostWithInstallFailed', function () {
  401. it('popup property failedHosts should be equal to hostsWithHeartbeatLost', function () {
  402. var hostsWithHeartbeatLost = [
  403. {},
  404. {}
  405. ];
  406. v.set('controller.hostsWithHeartbeatLost', hostsWithHeartbeatLost);
  407. var body = v.hostWithInstallFailed().get('bodyClass').create();
  408. expect(body.get('failedHosts')).to.eql(hostsWithHeartbeatLost);
  409. });
  410. });
  411. });
  412. var hv;
  413. describe('App.HostStatusView', function () {
  414. beforeEach(function () {
  415. hv = App.HostStatusView.create();
  416. });
  417. var tests = [
  418. {
  419. p: 'isFailed',
  420. tests: [
  421. {
  422. obj: {
  423. status: 'failed',
  424. progress: 100
  425. },
  426. e: true
  427. },
  428. {
  429. obj: {
  430. status: 'failed',
  431. progress: 99
  432. },
  433. e: false
  434. },
  435. {
  436. obj: {
  437. status: 'success',
  438. progress: 100
  439. },
  440. e: false
  441. },
  442. {
  443. obj: {
  444. status: 'success',
  445. progress: 99
  446. },
  447. e: false
  448. }
  449. ]
  450. },
  451. {
  452. p: 'isSuccess',
  453. tests: [
  454. {
  455. obj: {
  456. status: 'success',
  457. progress: 100
  458. },
  459. e: true
  460. },
  461. {
  462. obj: {
  463. status: 'success',
  464. progress: 99
  465. },
  466. e: false
  467. },
  468. {
  469. obj: {
  470. status: 'failed',
  471. progress: 100
  472. },
  473. e: false
  474. },
  475. {
  476. obj: {
  477. status: 'failed',
  478. progress: 99
  479. },
  480. e: false
  481. }
  482. ]
  483. },
  484. {
  485. p: 'isWarning',
  486. tests: [
  487. {
  488. obj: {
  489. status: 'warning',
  490. progress: 100
  491. },
  492. e: true
  493. },
  494. {
  495. obj: {
  496. status: 'warning',
  497. progress: 99
  498. },
  499. e: false
  500. },
  501. {
  502. obj: {
  503. status: 'failed',
  504. progress: 100
  505. },
  506. e: false
  507. },
  508. {
  509. obj: {
  510. status: 'failed',
  511. progress: 99
  512. },
  513. e: false
  514. }
  515. ]
  516. }
  517. ];
  518. tests.forEach(function (test) {
  519. describe(test.p, function () {
  520. test.tests.forEach(function (t) {
  521. var hostStatusView = App.HostStatusView.create();
  522. it('obj.progress = ' + t.obj.progress + '; obj.status = ' + t.obj.status, function () {
  523. hostStatusView.set('obj', t.obj);
  524. expect(hostStatusView.get(test.p)).to.equal(t.e);
  525. });
  526. });
  527. });
  528. });
  529. describe('#barWidth', function () {
  530. it('should depends of obj.progress', function () {
  531. hv.set('obj', {progress: '25'});
  532. expect(hv.get('barWidth')).to.equal('width: 25%;');
  533. });
  534. });
  535. describe('#didInsertElement', function () {
  536. beforeEach(function () {
  537. sinon.stub(hv, 'onStatus', Em.K);
  538. });
  539. afterEach(function () {
  540. hv.onStatus.restore();
  541. });
  542. it('should call onStatus', function () {
  543. hv.didInsertElement();
  544. expect(hv.onStatus.calledOnce).to.equal(true);
  545. });
  546. });
  547. describe('#onStatus', function () {
  548. Em.A([
  549. {
  550. obj: {
  551. status: 'info'
  552. },
  553. e: {
  554. barColor: 'progress-info'
  555. }
  556. },
  557. {
  558. obj: {
  559. status: 'warning'
  560. },
  561. e: {
  562. barColor: 'progress-warning'
  563. }
  564. },
  565. {
  566. obj: {
  567. status: 'warning',
  568. progress: '100'
  569. },
  570. e: {
  571. barColor: 'progress-warning',
  572. 'obj.message': Em.I18n.t('installer.step9.host.status.warning')
  573. }
  574. },
  575. {
  576. obj: {
  577. status: 'failed'
  578. },
  579. e: {
  580. barColor: 'progress-danger'
  581. }
  582. },
  583. {
  584. obj: {
  585. status: 'failed',
  586. progress: '100'
  587. },
  588. e: {
  589. barColor: 'progress-danger',
  590. 'obj.message': Em.I18n.t('installer.step9.host.status.failed')
  591. }
  592. },
  593. {
  594. obj: {
  595. status: 'heartbeat_lost'
  596. },
  597. e: {
  598. barColor: 'progress-danger'
  599. }
  600. },
  601. {
  602. obj: {
  603. status: 'heartbeat_lost',
  604. progress: '100'
  605. },
  606. e: {
  607. barColor: 'progress-danger',
  608. 'obj.message': Em.I18n.t('installer.step9.host.heartbeat_lost')
  609. }
  610. }
  611. ]).forEach(function (test) {
  612. it(JSON.stringify(test.obj), function () {
  613. hv.set('obj', test.obj);
  614. hv.onStatus();
  615. Em.keys(test.e).forEach(function (k) {
  616. expect(hv.get(k)).to.equal(test.e[k]);
  617. });
  618. });
  619. });
  620. Em.A([
  621. {
  622. obj: {
  623. status: 'success',
  624. progress: '100'
  625. },
  626. progress: '35',
  627. e: true
  628. },
  629. {
  630. obj: {
  631. status: 'success',
  632. progress: '100'
  633. },
  634. progress: '34',
  635. e: false
  636. },
  637. {
  638. obj: {
  639. status: 'success',
  640. progress: '99'
  641. },
  642. progress: '35',
  643. e: false
  644. },
  645. {
  646. obj: {
  647. status: 'failed',
  648. progress: '100'
  649. },
  650. progress: '35',
  651. e: false
  652. }
  653. ]).forEach(function (test) {
  654. it(JSON.stringify(test.obj) + ' ' + test.progress, function() {
  655. hv.set('barColor', '');
  656. hv.set('obj', test.obj);
  657. hv.set('obj.message', '');
  658. hv.set('controller', {progress: test.progress});
  659. hv.onStatus();
  660. expect(hv.get('obj.message') === Em.I18n.t('installer.step9.host.status.success')).to.equal(test.e);
  661. expect(hv.get('barColor') === 'progress-success').to.equal(test.e);
  662. });
  663. });
  664. });
  665. describe('#hostLogPopup', function() {
  666. describe('#onClose', function() {
  667. beforeEach(function() {
  668. hv.set('controller', {currentOpenTaskId: 123});
  669. hv.set('obj', Em.Object.create());
  670. this.p = hv.hostLogPopup();
  671. sinon.spy(this.p, 'hide');
  672. });
  673. afterEach(function () {
  674. this.p.hide.restore();
  675. });
  676. it('popup should clear currentOpenTaskId', function() {
  677. this.p.onClose();
  678. expect(hv.get('controller.currentOpenTaskId')).to.equal(0);
  679. });
  680. it('onClose popup should hide popup', function() {
  681. this.p.onClose();
  682. expect(this.p.hide.calledOnce).to.equal(true);
  683. });
  684. });
  685. });
  686. });