step9_view_test.js 19 KB

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