open-nomad/ui/tests/integration/components/job-page/parts/body-test.js

Ignoring revisions in .git-blame-ignore-revs. Click here to bypass and see the normal blame view.

119 lines
3.2 KiB
JavaScript
Raw Normal View History

2019-03-13 00:04:16 +00:00
import { module, test } from 'qunit';
import { setupRenderingTest } from 'ember-qunit';
import { find, findAll, render } from '@ember/test-helpers';
import hbs from 'htmlbars-inline-precompile';
import { startMirage } from 'nomad-ui/initializers/ember-cli-mirage';
import { componentA11yAudit } from 'nomad-ui/tests/helpers/a11y-audit';
2021-12-28 14:45:20 +00:00
module('Integration | Component | job-page/parts/body', function (hooks) {
2019-03-13 00:04:16 +00:00
setupRenderingTest(hooks);
2021-12-28 14:45:20 +00:00
hooks.beforeEach(function () {
window.localStorage.clear();
this.server = startMirage();
this.server.createList('namespace', 3);
2019-03-13 00:04:16 +00:00
});
2021-12-28 14:45:20 +00:00
hooks.afterEach(function () {
this.server.shutdown();
window.localStorage.clear();
2019-03-13 00:04:16 +00:00
});
2021-12-28 14:45:20 +00:00
test('includes a subnav for the job', async function (assert) {
2019-03-13 00:04:16 +00:00
this.set('job', {});
2019-03-13 00:04:16 +00:00
await render(hbs`
<JobPage::Parts::Body @job={{job}}>
2019-03-13 00:04:16 +00:00
<div class="inner-content">Inner content</div>
</JobPage::Parts::Body>
2019-03-13 00:04:16 +00:00
`);
assert.ok(find('[data-test-subnav="job"]'), 'Job subnav is rendered');
});
2021-12-28 14:45:20 +00:00
test('the subnav includes the deployments link when the job is a service', async function (assert) {
assert.expect(4);
2019-03-13 00:04:16 +00:00
const store = this.owner.lookup('service:store');
const job = await store.createRecord('job', {
id: 'service-job',
type: 'service',
});
2019-03-13 00:04:16 +00:00
this.set('job', job);
2019-03-13 00:04:16 +00:00
await render(hbs`
<JobPage::Parts::Body @job={{job}}>
2019-03-13 00:04:16 +00:00
<div class="inner-content">Inner content</div>
</JobPage::Parts::Body>
2019-03-13 00:04:16 +00:00
`);
2022-01-26 16:28:21 +00:00
const subnavLabels = findAll('[data-test-tab]').map((anchor) =>
anchor.textContent.trim()
2021-12-28 16:08:12 +00:00
);
2022-01-26 16:28:21 +00:00
2021-12-28 14:45:20 +00:00
assert.ok(
subnavLabels.some((label) => label === 'Definition'),
'Definition link'
);
assert.ok(
subnavLabels.some((label) => label === 'Versions'),
'Versions link'
);
2022-01-26 16:28:21 +00:00
2021-12-28 14:45:20 +00:00
assert.ok(
subnavLabels.some((label) => label === 'Deployments'),
'Deployments link'
);
await componentA11yAudit(this.element, assert);
});
2021-12-28 14:45:20 +00:00
test('the subnav does not include the deployments link when the job is not a service', async function (assert) {
2019-03-13 00:04:16 +00:00
const store = this.owner.lookup('service:store');
const job = await store.createRecord('job', {
id: 'batch-job',
type: 'batch',
});
2019-03-13 00:04:16 +00:00
this.set('job', job);
2019-03-13 00:04:16 +00:00
await render(hbs`
<JobPage::Parts::Body @job={{job}}>
2019-03-13 00:04:16 +00:00
<div class="inner-content">Inner content</div>
</JobPage::Parts::Body>
2019-03-13 00:04:16 +00:00
`);
2022-01-26 16:28:21 +00:00
const subnavLabels = findAll('[data-test-tab]').map((anchor) =>
anchor.textContent.trim()
2021-12-28 16:08:12 +00:00
);
2021-12-28 14:45:20 +00:00
assert.ok(
subnavLabels.some((label) => label === 'Definition'),
'Definition link'
);
assert.ok(
subnavLabels.some((label) => label === 'Versions'),
'Versions link'
);
assert.notOk(
subnavLabels.some((label) => label === 'Deployments'),
'Deployments link'
);
});
2021-12-28 14:45:20 +00:00
test('body yields content to a section after the subnav', async function (assert) {
2019-03-13 00:04:16 +00:00
this.set('job', {});
2019-03-13 00:04:16 +00:00
await render(hbs`
<JobPage::Parts::Body @job={{job}}>
2019-03-13 00:04:16 +00:00
<div class="inner-content">Inner content</div>
</JobPage::Parts::Body>
2019-03-13 00:04:16 +00:00
`);
assert.ok(
find('[data-test-subnav="job"] + .section > .inner-content'),
'Content is rendered immediately after the subnav'
);
});
});