2019-03-13 00:40:39 +00:00
|
|
|
import { currentURL } from '@ember/test-helpers';
|
2019-03-13 00:04:16 +00:00
|
|
|
import { module, test } from 'qunit';
|
|
|
|
import { setupApplicationTest } from 'ember-qunit';
|
2019-09-26 18:47:07 +00:00
|
|
|
import { setupMirage } from 'ember-cli-mirage/test-support';
|
2018-07-11 02:20:02 +00:00
|
|
|
import JobDetail from 'nomad-ui/tests/pages/jobs/detail';
|
2018-02-02 01:22:09 +00:00
|
|
|
|
2021-02-17 21:01:44 +00:00
|
|
|
// eslint-disable-next-line ember/no-test-module-for
|
2018-11-08 05:04:27 +00:00
|
|
|
export default function moduleForJob(title, context, jobFactory, additionalTests) {
|
2018-02-02 01:22:09 +00:00
|
|
|
let job;
|
|
|
|
|
2019-03-13 00:40:39 +00:00
|
|
|
module(title, function(hooks) {
|
|
|
|
setupApplicationTest(hooks);
|
2019-03-13 01:09:19 +00:00
|
|
|
setupMirage(hooks);
|
2019-03-13 00:40:39 +00:00
|
|
|
hooks.before(function() {
|
2018-11-08 05:04:27 +00:00
|
|
|
if (context !== 'allocations' && context !== 'children') {
|
|
|
|
throw new Error(
|
|
|
|
`Invalid context provided to moduleForJob, expected either "allocations" or "children", got ${context}`
|
|
|
|
);
|
|
|
|
}
|
2019-03-13 00:40:39 +00:00
|
|
|
});
|
|
|
|
|
2019-03-14 06:44:53 +00:00
|
|
|
hooks.beforeEach(async function() {
|
2018-02-02 01:22:09 +00:00
|
|
|
server.create('node');
|
|
|
|
job = jobFactory();
|
2019-03-14 06:44:53 +00:00
|
|
|
await JobDetail.visit({ id: job.id });
|
2019-03-13 00:40:39 +00:00
|
|
|
});
|
2018-02-02 01:22:09 +00:00
|
|
|
|
2019-03-14 06:44:53 +00:00
|
|
|
test('visiting /jobs/:job_id', async function(assert) {
|
2018-02-02 01:22:09 +00:00
|
|
|
assert.equal(currentURL(), `/jobs/${job.id}`);
|
2019-07-17 20:02:58 +00:00
|
|
|
assert.equal(document.title, `Job ${job.name} - Nomad`);
|
2018-02-02 01:22:09 +00:00
|
|
|
});
|
|
|
|
|
2019-03-14 06:44:53 +00:00
|
|
|
test('the subnav links to overview', async function(assert) {
|
|
|
|
await JobDetail.tabFor('overview').visit();
|
|
|
|
assert.equal(currentURL(), `/jobs/${job.id}`);
|
2018-02-02 01:22:09 +00:00
|
|
|
});
|
|
|
|
|
2019-03-14 06:44:53 +00:00
|
|
|
test('the subnav links to definition', async function(assert) {
|
|
|
|
await JobDetail.tabFor('definition').visit();
|
|
|
|
assert.equal(currentURL(), `/jobs/${job.id}/definition`);
|
2018-02-02 01:22:09 +00:00
|
|
|
});
|
|
|
|
|
2019-03-14 06:44:53 +00:00
|
|
|
test('the subnav links to versions', async function(assert) {
|
|
|
|
await JobDetail.tabFor('versions').visit();
|
|
|
|
assert.equal(currentURL(), `/jobs/${job.id}/versions`);
|
2018-07-11 02:28:54 +00:00
|
|
|
});
|
|
|
|
|
2019-03-14 06:44:53 +00:00
|
|
|
test('the subnav links to evaluations', async function(assert) {
|
|
|
|
await JobDetail.tabFor('evaluations').visit();
|
|
|
|
assert.equal(currentURL(), `/jobs/${job.id}/evaluations`);
|
2018-11-08 05:04:27 +00:00
|
|
|
});
|
|
|
|
|
2020-05-11 16:29:30 +00:00
|
|
|
test('the title buttons are dependent on job status', async function(assert) {
|
|
|
|
if (job.status === 'dead') {
|
|
|
|
assert.ok(JobDetail.start.isPresent);
|
|
|
|
assert.notOk(JobDetail.stop.isPresent);
|
|
|
|
assert.notOk(JobDetail.execButton.isPresent);
|
|
|
|
} else {
|
|
|
|
assert.notOk(JobDetail.start.isPresent);
|
|
|
|
assert.ok(JobDetail.stop.isPresent);
|
|
|
|
assert.ok(JobDetail.execButton.isPresent);
|
|
|
|
}
|
|
|
|
});
|
|
|
|
|
2019-03-13 00:40:39 +00:00
|
|
|
if (context === 'allocations') {
|
2019-03-14 06:44:53 +00:00
|
|
|
test('allocations for the job are shown in the overview', async function(assert) {
|
2019-03-13 00:40:39 +00:00
|
|
|
assert.ok(JobDetail.allocationsSummary, 'Allocations are shown in the summary section');
|
|
|
|
assert.notOk(JobDetail.childrenSummary, 'Children are not shown in the summary section');
|
|
|
|
});
|
2019-08-08 14:26:46 +00:00
|
|
|
|
|
|
|
test('clicking in an allocation row navigates to that allocation', async function(assert) {
|
|
|
|
const allocationRow = JobDetail.allocations[0];
|
|
|
|
const allocationId = allocationRow.id;
|
|
|
|
|
|
|
|
await allocationRow.visitRow();
|
|
|
|
|
|
|
|
assert.equal(
|
|
|
|
currentURL(),
|
|
|
|
`/allocations/${allocationId}`,
|
|
|
|
'Allocation row links to allocation detail'
|
|
|
|
);
|
|
|
|
});
|
2019-03-13 00:40:39 +00:00
|
|
|
}
|
2018-11-08 05:04:27 +00:00
|
|
|
|
2019-03-13 00:40:39 +00:00
|
|
|
if (context === 'children') {
|
2019-03-14 06:44:53 +00:00
|
|
|
test('children for the job are shown in the overview', async function(assert) {
|
2019-03-13 00:40:39 +00:00
|
|
|
assert.ok(JobDetail.childrenSummary, 'Children are shown in the summary section');
|
|
|
|
assert.notOk(
|
|
|
|
JobDetail.allocationsSummary,
|
|
|
|
'Allocations are not shown in the summary section'
|
|
|
|
);
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
for (var testName in additionalTests) {
|
2019-03-14 06:44:53 +00:00
|
|
|
test(testName, async function(assert) {
|
2020-09-19 05:20:09 +00:00
|
|
|
await additionalTests[testName].call(this, job, assert);
|
2019-03-13 00:40:39 +00:00
|
|
|
});
|
|
|
|
}
|
|
|
|
});
|
2018-02-02 01:22:09 +00:00
|
|
|
}
|