2019-03-13 00:04:16 +00:00
|
|
|
import { module, test } from 'qunit';
|
|
|
|
import { setupRenderingTest } from 'ember-qunit';
|
2019-07-23 19:40:32 +00:00
|
|
|
import { find, findAll, render } from '@ember/test-helpers';
|
2018-01-31 17:23:41 +00:00
|
|
|
import hbs from 'htmlbars-inline-precompile';
|
|
|
|
import { startMirage } from 'nomad-ui/initializers/ember-cli-mirage';
|
2020-08-25 15:56:02 +00:00
|
|
|
import { componentA11yAudit } from 'nomad-ui/tests/helpers/a11y-audit';
|
2018-01-31 17:23:41 +00:00
|
|
|
|
2019-03-13 00:04:16 +00:00
|
|
|
module('Integration | Component | job-page/parts/body', function(hooks) {
|
|
|
|
setupRenderingTest(hooks);
|
|
|
|
|
|
|
|
hooks.beforeEach(function() {
|
2018-01-31 17:23:41 +00:00
|
|
|
window.localStorage.clear();
|
|
|
|
this.server = startMirage();
|
|
|
|
this.server.createList('namespace', 3);
|
2019-03-13 00:04:16 +00:00
|
|
|
});
|
|
|
|
|
|
|
|
hooks.afterEach(function() {
|
2018-01-31 17:23:41 +00:00
|
|
|
this.server.shutdown();
|
|
|
|
window.localStorage.clear();
|
2019-03-13 00:04:16 +00:00
|
|
|
});
|
2018-01-31 17:23:41 +00:00
|
|
|
|
2019-03-13 00:04:16 +00:00
|
|
|
test('includes a subnav for the job', async function(assert) {
|
|
|
|
this.set('job', {});
|
2018-01-31 17:23:41 +00:00
|
|
|
|
2019-03-13 00:04:16 +00:00
|
|
|
await render(hbs`
|
2020-07-09 17:30:11 +00:00
|
|
|
<JobPage::Parts::Body @job={{job}}>
|
2019-03-13 00:04:16 +00:00
|
|
|
<div class="inner-content">Inner content</div>
|
2020-07-09 17:30:11 +00:00
|
|
|
</JobPage::Parts::Body>
|
2019-03-13 00:04:16 +00:00
|
|
|
`);
|
2018-01-31 17:23:41 +00:00
|
|
|
|
2019-03-14 18:35:46 +00:00
|
|
|
assert.ok(find('[data-test-subnav="job"]'), 'Job subnav is rendered');
|
2018-01-31 17:23:41 +00:00
|
|
|
});
|
|
|
|
|
2019-03-13 00:04:16 +00:00
|
|
|
test('the subnav includes the deployments link when the job is a service', async function(assert) {
|
|
|
|
const store = this.owner.lookup('service:store');
|
2019-07-23 19:40:32 +00:00
|
|
|
const job = await store.createRecord('job', {
|
|
|
|
id: 'service-job',
|
|
|
|
type: 'service',
|
2018-01-31 17:23:41 +00:00
|
|
|
});
|
|
|
|
|
2019-03-13 00:04:16 +00:00
|
|
|
this.set('job', job);
|
2018-01-31 17:23:41 +00:00
|
|
|
|
2019-03-13 00:04:16 +00:00
|
|
|
await render(hbs`
|
2020-07-09 17:30:11 +00:00
|
|
|
<JobPage::Parts::Body @job={{job}}>
|
2019-03-13 00:04:16 +00:00
|
|
|
<div class="inner-content">Inner content</div>
|
2020-07-09 17:30:11 +00:00
|
|
|
</JobPage::Parts::Body>
|
2019-03-13 00:04:16 +00:00
|
|
|
`);
|
2018-01-31 17:23:41 +00:00
|
|
|
|
2019-03-14 18:35:46 +00:00
|
|
|
const subnavLabels = findAll('[data-test-tab]').map(anchor => anchor.textContent);
|
|
|
|
assert.ok(subnavLabels.some(label => label === 'Definition'), 'Definition link');
|
|
|
|
assert.ok(subnavLabels.some(label => label === 'Versions'), 'Versions link');
|
|
|
|
assert.ok(subnavLabels.some(label => label === 'Deployments'), 'Deployments link');
|
2020-08-25 15:56:02 +00:00
|
|
|
|
|
|
|
await componentA11yAudit(this.element, assert);
|
2018-01-31 17:23:41 +00:00
|
|
|
});
|
|
|
|
|
2019-03-13 00:04:16 +00:00
|
|
|
test('the subnav does not include the deployments link when the job is not a service', async function(assert) {
|
|
|
|
const store = this.owner.lookup('service:store');
|
2019-07-23 19:40:32 +00:00
|
|
|
const job = await store.createRecord('job', {
|
|
|
|
id: 'batch-job',
|
|
|
|
type: 'batch',
|
2018-01-31 17:23:41 +00:00
|
|
|
});
|
|
|
|
|
2019-03-13 00:04:16 +00:00
|
|
|
this.set('job', job);
|
2018-01-31 17:23:41 +00:00
|
|
|
|
2019-03-13 00:04:16 +00:00
|
|
|
await render(hbs`
|
2020-07-09 17:30:11 +00:00
|
|
|
<JobPage::Parts::Body @job={{job}}>
|
2019-03-13 00:04:16 +00:00
|
|
|
<div class="inner-content">Inner content</div>
|
2020-07-09 17:30:11 +00:00
|
|
|
</JobPage::Parts::Body>
|
2019-03-13 00:04:16 +00:00
|
|
|
`);
|
2018-01-31 17:23:41 +00:00
|
|
|
|
2019-03-14 18:35:46 +00:00
|
|
|
const subnavLabels = findAll('[data-test-tab]').map(anchor => anchor.textContent);
|
|
|
|
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');
|
2018-01-31 17:23:41 +00:00
|
|
|
});
|
|
|
|
|
2019-03-13 00:04:16 +00:00
|
|
|
test('body yields content to a section after the subnav', async function(assert) {
|
|
|
|
this.set('job', {});
|
2018-01-31 17:23:41 +00:00
|
|
|
|
2019-03-13 00:04:16 +00:00
|
|
|
await render(hbs`
|
2020-07-09 17:30:11 +00:00
|
|
|
<JobPage::Parts::Body @job={{job}}>
|
2019-03-13 00:04:16 +00:00
|
|
|
<div class="inner-content">Inner content</div>
|
2020-07-09 17:30:11 +00:00
|
|
|
</JobPage::Parts::Body>
|
2019-03-13 00:04:16 +00:00
|
|
|
`);
|
2018-01-31 17:23:41 +00:00
|
|
|
|
2019-03-14 18:35:46 +00:00
|
|
|
assert.ok(
|
|
|
|
find('[data-test-subnav="job"] + .section > .inner-content'),
|
|
|
|
'Content is rendered immediately after the subnav'
|
|
|
|
);
|
2018-01-31 17:23:41 +00:00
|
|
|
});
|
|
|
|
});
|