open-nomad/ui/tests/integration/components/job-client-status-bar-test.js

82 lines
2.3 KiB
JavaScript
Raw Normal View History

import { module, test } from 'qunit';
import { create } from 'ember-cli-page-object';
import { setupRenderingTest } from 'ember-qunit';
import { render } from '@ember/test-helpers';
import { hbs } from 'ember-cli-htmlbars';
import sinon from 'sinon';
import { componentA11yAudit } from 'nomad-ui/tests/helpers/a11y-audit';
import jobClientStatusBar from 'nomad-ui/tests/pages/components/job-client-status-bar';
const JobClientStatusBar = create(jobClientStatusBar());
2021-12-28 14:45:20 +00:00
module('Integration | Component | job-client-status-bar', function (hooks) {
setupRenderingTest(hooks);
const commonProperties = () => ({
onSliceClick: sinon.spy(),
job: {
namespace: {
get: () => 'my-namespace',
},
},
jobClientStatus: {
byStatus: {
queued: [],
starting: ['someNodeId'],
running: [],
complete: [],
degraded: [],
failed: [],
lost: [],
notScheduled: [],
},
},
isNarrow: true,
});
const commonTemplate = hbs`
<JobClientStatusBar
@onSliceClick={{onSliceClick}}
@job={{job}}
@jobClientStatus={{jobClientStatus}}
@isNarrow={{isNarrow}}
/>`;
2021-12-28 14:45:20 +00:00
test('it renders', async function (assert) {
const props = commonProperties();
this.setProperties(props);
await render(commonTemplate);
assert.ok(JobClientStatusBar.isPresent, 'Client Status Bar is rendered');
await componentA11yAudit(this.element, assert);
});
2021-12-28 14:45:20 +00:00
test('it fires the onBarClick handler method when clicking a bar in the chart', async function (assert) {
const props = commonProperties();
this.setProperties(props);
await render(commonTemplate);
await JobClientStatusBar.slices[0].click();
assert.ok(props.onSliceClick.calledOnce);
});
2021-12-28 14:45:20 +00:00
test('it handles an update to client status property', async function (assert) {
const props = commonProperties();
this.setProperties(props);
await render(commonTemplate);
const newProps = {
...props,
jobClientStatus: {
...props.jobClientStatus,
2021-12-28 16:08:12 +00:00
byStatus: {
...props.jobClientStatus.byStatus,
starting: [],
running: ['someNodeId'],
},
},
};
this.setProperties(newProps);
await JobClientStatusBar.visitSlice('running');
assert.ok(props.onSliceClick.calledOnce);
});
});