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-03-13 01:09:19 +00:00
|
|
|
import setupMirage from 'ember-cli-mirage/test-support/setup-mirage';
|
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
|
|
|
|
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
|
|
|
});
|
|
|
|
|
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');
|
|
|
|
});
|
|
|
|
}
|
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) {
|
|
|
|
await additionalTests[testName](job, assert);
|
2019-03-13 00:40:39 +00:00
|
|
|
});
|
|
|
|
}
|
|
|
|
});
|
2018-02-02 01:22:09 +00:00
|
|
|
}
|