github.com/anth0d/nomad@v0.0.0-20221214183521-ae3a0a2cad06/ui/tests/integration/components/job-client-status-bar-test.js (about) 1 import { module, test } from 'qunit'; 2 import { create } from 'ember-cli-page-object'; 3 import { setupRenderingTest } from 'ember-qunit'; 4 import { render } from '@ember/test-helpers'; 5 import { hbs } from 'ember-cli-htmlbars'; 6 import sinon from 'sinon'; 7 import { componentA11yAudit } from 'nomad-ui/tests/helpers/a11y-audit'; 8 import jobClientStatusBar from 'nomad-ui/tests/pages/components/job-client-status-bar'; 9 10 const JobClientStatusBar = create(jobClientStatusBar()); 11 12 module('Integration | Component | job-client-status-bar', function (hooks) { 13 setupRenderingTest(hooks); 14 15 const commonProperties = () => ({ 16 onSliceClick: sinon.spy(), 17 job: { 18 namespace: { 19 get: () => 'my-namespace', 20 }, 21 }, 22 jobClientStatus: { 23 byStatus: { 24 queued: [], 25 starting: ['someNodeId'], 26 running: [], 27 complete: [], 28 degraded: [], 29 failed: [], 30 lost: [], 31 notScheduled: [], 32 unknown: [], 33 }, 34 }, 35 isNarrow: true, 36 }); 37 38 const commonTemplate = hbs` 39 <JobClientStatusBar 40 @onSliceClick={{onSliceClick}} 41 @job={{job}} 42 @jobClientStatus={{jobClientStatus}} 43 @isNarrow={{isNarrow}} 44 />`; 45 46 test('it renders', async function (assert) { 47 assert.expect(2); 48 49 const props = commonProperties(); 50 this.setProperties(props); 51 await render(commonTemplate); 52 53 assert.ok(JobClientStatusBar.isPresent, 'Client Status Bar is rendered'); 54 await componentA11yAudit(this.element, assert); 55 }); 56 57 test('it fires the onBarClick handler method when clicking a bar in the chart', async function (assert) { 58 const props = commonProperties(); 59 this.setProperties(props); 60 await render(commonTemplate); 61 await JobClientStatusBar.slices[0].click(); 62 assert.ok(props.onSliceClick.calledOnce); 63 }); 64 65 test('it handles an update to client status property', async function (assert) { 66 const props = commonProperties(); 67 this.setProperties(props); 68 await render(commonTemplate); 69 const newProps = { 70 ...props, 71 jobClientStatus: { 72 ...props.jobClientStatus, 73 byStatus: { 74 ...props.jobClientStatus.byStatus, 75 starting: [], 76 running: ['someNodeId'], 77 }, 78 }, 79 }; 80 this.setProperties(newProps); 81 await JobClientStatusBar.visitSlice('running'); 82 assert.ok(props.onSliceClick.calledOnce); 83 }); 84 });