2021-12-28 19:30:38 +00:00
|
|
|
/* eslint-disable qunit/require-expect */
|
|
|
|
/* eslint-disable qunit/no-conditional-assertions */
|
2022-01-26 16:30:06 +00:00
|
|
|
import {
|
|
|
|
click,
|
|
|
|
currentRouteName,
|
|
|
|
currentURL,
|
|
|
|
visit,
|
|
|
|
} 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';
|
2022-01-26 17:06:18 +00:00
|
|
|
import setPolicy from 'nomad-ui/tests/utils/set-policy';
|
2018-02-02 01:22:09 +00:00
|
|
|
|
2022-01-05 17:50:15 +00:00
|
|
|
// moduleFor is an old Ember-QUnit API that is deprected https://guides.emberjs.com/v1.10.0/testing/unit-test-helpers/
|
|
|
|
// this is a misnomer in our context, because we're not using this API, however, the linter does not understand this
|
|
|
|
// the linter warning will go away if we rename this factory function to generateJobDetailsTests
|
2021-02-17 21:01:44 +00:00
|
|
|
// eslint-disable-next-line ember/no-test-module-for
|
2021-12-28 16:08:12 +00:00
|
|
|
export default function moduleForJob(
|
|
|
|
title,
|
|
|
|
context,
|
|
|
|
jobFactory,
|
|
|
|
additionalTests
|
|
|
|
) {
|
2018-02-02 01:22:09 +00:00
|
|
|
let job;
|
|
|
|
|
2022-01-20 15:39:02 +00:00
|
|
|
module(title, function (hooks) {
|
2019-03-13 00:40:39 +00:00
|
|
|
setupApplicationTest(hooks);
|
2019-03-13 01:09:19 +00:00
|
|
|
setupMirage(hooks);
|
2022-01-20 15:39:02 +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
|
|
|
});
|
|
|
|
|
2022-01-20 15:39:02 +00:00
|
|
|
hooks.beforeEach(async function () {
|
2018-02-02 01:22:09 +00:00
|
|
|
server.create('node');
|
|
|
|
job = jobFactory();
|
2021-09-01 18:40:25 +00:00
|
|
|
if (!job.namespace || job.namespace === 'default') {
|
|
|
|
await JobDetail.visit({ id: job.id });
|
|
|
|
} else {
|
|
|
|
await JobDetail.visit({ id: job.id, namespace: job.namespace });
|
|
|
|
}
|
2022-01-26 16:30:06 +00:00
|
|
|
|
|
|
|
const hasClientStatus = ['system', 'sysbatch'].includes(job.type);
|
|
|
|
if (context === 'allocations' && hasClientStatus) {
|
|
|
|
await click("[data-test-accordion-summary-chart='allocation-status']");
|
|
|
|
}
|
2019-03-13 00:40:39 +00:00
|
|
|
});
|
2018-02-02 01:22:09 +00:00
|
|
|
|
2022-01-20 15:39:02 +00:00
|
|
|
test('visiting /jobs/:job_id', async function (assert) {
|
2022-01-24 15:58:28 +00:00
|
|
|
assert.equal(
|
|
|
|
currentURL(),
|
|
|
|
urlWithNamespace(`/jobs/${encodeURIComponent(job.id)}`, job.namespace)
|
2021-09-01 18:40:25 +00:00
|
|
|
);
|
2019-07-17 20:02:58 +00:00
|
|
|
assert.equal(document.title, `Job ${job.name} - Nomad`);
|
2018-02-02 01:22:09 +00:00
|
|
|
});
|
|
|
|
|
2022-01-20 15:39:02 +00:00
|
|
|
test('the subnav links to overview', async function (assert) {
|
2019-03-14 06:44:53 +00:00
|
|
|
await JobDetail.tabFor('overview').visit();
|
2022-01-24 15:58:28 +00:00
|
|
|
assert.equal(
|
|
|
|
currentURL(),
|
|
|
|
urlWithNamespace(`/jobs/${encodeURIComponent(job.id)}`, job.namespace)
|
2021-09-01 18:40:25 +00:00
|
|
|
);
|
2018-02-02 01:22:09 +00:00
|
|
|
});
|
|
|
|
|
2022-01-20 15:39:02 +00:00
|
|
|
test('the subnav links to definition', async function (assert) {
|
2019-03-14 06:44:53 +00:00
|
|
|
await JobDetail.tabFor('definition').visit();
|
2021-09-01 18:40:25 +00:00
|
|
|
assert.equal(
|
|
|
|
currentURL(),
|
2021-12-28 16:08:12 +00:00
|
|
|
urlWithNamespace(
|
|
|
|
`/jobs/${encodeURIComponent(job.id)}/definition`,
|
|
|
|
job.namespace
|
|
|
|
)
|
2021-09-01 18:40:25 +00:00
|
|
|
);
|
2018-02-02 01:22:09 +00:00
|
|
|
});
|
|
|
|
|
2022-01-20 15:39:02 +00:00
|
|
|
test('the subnav links to versions', async function (assert) {
|
2019-03-14 06:44:53 +00:00
|
|
|
await JobDetail.tabFor('versions').visit();
|
2021-09-01 18:40:25 +00:00
|
|
|
assert.equal(
|
|
|
|
currentURL(),
|
2021-12-28 16:08:12 +00:00
|
|
|
urlWithNamespace(
|
|
|
|
`/jobs/${encodeURIComponent(job.id)}/versions`,
|
|
|
|
job.namespace
|
|
|
|
)
|
2021-09-01 18:40:25 +00:00
|
|
|
);
|
2018-07-11 02:28:54 +00:00
|
|
|
});
|
|
|
|
|
2022-01-20 15:39:02 +00:00
|
|
|
test('the subnav links to evaluations', async function (assert) {
|
2019-03-14 06:44:53 +00:00
|
|
|
await JobDetail.tabFor('evaluations').visit();
|
2021-09-01 18:40:25 +00:00
|
|
|
assert.equal(
|
|
|
|
currentURL(),
|
2021-12-28 16:08:12 +00:00
|
|
|
urlWithNamespace(
|
|
|
|
`/jobs/${encodeURIComponent(job.id)}/evaluations`,
|
|
|
|
job.namespace
|
|
|
|
)
|
2021-09-01 18:40:25 +00:00
|
|
|
);
|
2018-11-08 05:04:27 +00:00
|
|
|
});
|
|
|
|
|
2022-01-20 15:39:02 +00:00
|
|
|
test('the title buttons are dependent on job status', async function (assert) {
|
2020-05-11 16:29:30 +00:00
|
|
|
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') {
|
2022-01-20 15:39:02 +00:00
|
|
|
test('allocations for the job are shown in the overview', async function (assert) {
|
2022-01-12 16:21:01 +00:00
|
|
|
assert.ok(
|
|
|
|
JobDetail.allocationsSummary.isPresent,
|
|
|
|
'Allocations are shown in the summary section'
|
|
|
|
);
|
|
|
|
assert.ok(
|
|
|
|
JobDetail.childrenSummary.isHidden,
|
|
|
|
'Children are not shown in the summary section'
|
|
|
|
);
|
2019-03-13 00:40:39 +00:00
|
|
|
});
|
2019-08-08 14:26:46 +00:00
|
|
|
|
2022-01-20 15:39:02 +00:00
|
|
|
test('clicking in an allocation row navigates to that allocation', async function (assert) {
|
2019-08-08 14:26:46 +00:00
|
|
|
const allocationRow = JobDetail.allocations[0];
|
|
|
|
const allocationId = allocationRow.id;
|
|
|
|
|
|
|
|
await allocationRow.visitRow();
|
|
|
|
|
|
|
|
assert.equal(
|
|
|
|
currentURL(),
|
|
|
|
`/allocations/${allocationId}`,
|
|
|
|
'Allocation row links to allocation detail'
|
|
|
|
);
|
|
|
|
});
|
2022-01-12 16:21:01 +00:00
|
|
|
|
2022-01-20 15:39:02 +00:00
|
|
|
test('clicking legend item navigates to a pre-filtered allocations table', async function (assert) {
|
2021-12-28 16:08:12 +00:00
|
|
|
const legendItem =
|
|
|
|
JobDetail.allocationsSummary.legend.clickableItems[1];
|
2022-01-12 16:21:01 +00:00
|
|
|
const status = legendItem.label;
|
|
|
|
await legendItem.click();
|
|
|
|
|
|
|
|
const encodedStatus = encodeURIComponent(JSON.stringify([status]));
|
|
|
|
const expectedURL = new URL(
|
2021-12-28 16:08:12 +00:00
|
|
|
urlWithNamespace(
|
|
|
|
`/jobs/${job.name}/clients?status=${encodedStatus}`,
|
|
|
|
job.namespace
|
|
|
|
),
|
2022-01-12 16:21:01 +00:00
|
|
|
window.location
|
|
|
|
);
|
|
|
|
const gotURL = new URL(currentURL(), window.location);
|
|
|
|
assert.deepEqual(gotURL.path, expectedURL.path);
|
|
|
|
assert.deepEqual(gotURL.searchParams, expectedURL.searchParams);
|
|
|
|
});
|
|
|
|
|
2022-01-20 15:39:02 +00:00
|
|
|
test('clicking in a slice takes you to a pre-filtered allocations table', async function (assert) {
|
2022-01-12 16:21:01 +00:00
|
|
|
const slice = JobDetail.allocationsSummary.slices[1];
|
|
|
|
const status = slice.label;
|
|
|
|
await slice.click();
|
|
|
|
|
|
|
|
const encodedStatus = encodeURIComponent(JSON.stringify([status]));
|
|
|
|
const expectedURL = new URL(
|
2022-01-18 15:36:10 +00:00
|
|
|
urlWithNamespace(
|
2021-12-28 16:08:12 +00:00
|
|
|
`/jobs/${encodeURIComponent(
|
|
|
|
job.name
|
|
|
|
)}/allocations?status=${encodedStatus}`,
|
2022-01-18 15:36:10 +00:00
|
|
|
job.namespace
|
|
|
|
),
|
2022-01-12 16:21:01 +00:00
|
|
|
window.location
|
|
|
|
);
|
|
|
|
const gotURL = new URL(currentURL(), window.location);
|
|
|
|
assert.deepEqual(gotURL.pathname, expectedURL.pathname);
|
|
|
|
|
|
|
|
// Sort and compare URL query params.
|
|
|
|
gotURL.searchParams.sort();
|
|
|
|
expectedURL.searchParams.sort();
|
2021-12-28 16:08:12 +00:00
|
|
|
assert.equal(
|
|
|
|
gotURL.searchParams.toString(),
|
|
|
|
expectedURL.searchParams.toString()
|
|
|
|
);
|
2022-01-12 16:21:01 +00:00
|
|
|
});
|
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') {
|
2022-01-20 15:39:02 +00:00
|
|
|
test('children for the job are shown in the overview', async function (assert) {
|
2021-12-28 16:08:12 +00:00
|
|
|
assert.ok(
|
|
|
|
JobDetail.childrenSummary.isPresent,
|
|
|
|
'Children are shown in the summary section'
|
|
|
|
);
|
2022-01-12 16:21:01 +00:00
|
|
|
assert.ok(
|
|
|
|
JobDetail.allocationsSummary.isHidden,
|
2019-03-13 00:40:39 +00:00
|
|
|
'Allocations are not shown in the summary section'
|
|
|
|
);
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
for (var testName in additionalTests) {
|
2022-01-20 15:39:02 +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
|
|
|
}
|
2021-09-01 18:40:25 +00:00
|
|
|
|
2022-01-05 17:50:15 +00:00
|
|
|
// moduleFor is an old Ember-QUnit API that is deprected https://guides.emberjs.com/v1.10.0/testing/unit-test-helpers/
|
|
|
|
// this is a misnomer in our context, because we're not using this API, however, the linter does not understand this
|
|
|
|
// the linter warning will go away if we rename this factory function to generateJobClientStatusTests
|
2021-10-07 21:11:38 +00:00
|
|
|
// eslint-disable-next-line ember/no-test-module-for
|
2021-12-28 16:08:12 +00:00
|
|
|
export function moduleForJobWithClientStatus(
|
|
|
|
title,
|
|
|
|
jobFactory,
|
|
|
|
additionalTests
|
|
|
|
) {
|
2021-10-07 21:11:38 +00:00
|
|
|
let job;
|
|
|
|
|
2022-01-20 15:39:02 +00:00
|
|
|
module(title, function (hooks) {
|
2021-10-07 21:11:38 +00:00
|
|
|
setupApplicationTest(hooks);
|
|
|
|
setupMirage(hooks);
|
|
|
|
|
2022-01-20 15:39:02 +00:00
|
|
|
hooks.beforeEach(async function () {
|
2021-10-07 21:11:38 +00:00
|
|
|
const clients = server.createList('node', 3, {
|
|
|
|
datacenter: 'dc1',
|
2022-01-20 15:39:02 +00:00
|
|
|
status: 'ready',
|
2021-10-07 21:11:38 +00:00
|
|
|
});
|
|
|
|
job = jobFactory();
|
2022-01-20 15:39:02 +00:00
|
|
|
clients.forEach((c) => {
|
2021-10-07 21:11:38 +00:00
|
|
|
server.create('allocation', { jobId: job.id, nodeId: c.id });
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
2022-01-05 17:50:15 +00:00
|
|
|
module('with node:read permissions', function (hooks) {
|
|
|
|
hooks.beforeEach(async function () {
|
|
|
|
// Displaying the job status in client requires node:read permission.
|
|
|
|
setPolicy({
|
|
|
|
id: 'node-read',
|
|
|
|
name: 'node-read',
|
|
|
|
rulesJSON: {
|
|
|
|
Node: {
|
|
|
|
Policy: 'read',
|
|
|
|
},
|
|
|
|
},
|
|
|
|
});
|
|
|
|
|
|
|
|
await visitJobDetailPage(job);
|
|
|
|
});
|
2021-10-07 21:11:38 +00:00
|
|
|
|
2022-01-05 17:50:15 +00:00
|
|
|
test('the subnav links to clients', async function (assert) {
|
|
|
|
await JobDetail.tabFor('clients').visit();
|
|
|
|
assert.equal(
|
|
|
|
currentURL(),
|
|
|
|
urlWithNamespace(
|
|
|
|
`/jobs/${encodeURIComponent(job.id)}/clients`,
|
|
|
|
job.namespace
|
|
|
|
)
|
|
|
|
);
|
|
|
|
});
|
2021-10-07 21:11:38 +00:00
|
|
|
|
2022-01-05 17:50:15 +00:00
|
|
|
test('job status summary is shown in the overview', async function (assert) {
|
|
|
|
assert.ok(
|
2022-01-26 16:30:06 +00:00
|
|
|
JobDetail.jobClientStatusSummary.statusBar.isPresent,
|
2022-01-05 17:50:15 +00:00
|
|
|
'Summary bar is displayed in the Job Status in Client summary section'
|
|
|
|
);
|
|
|
|
});
|
2021-10-07 21:11:38 +00:00
|
|
|
|
2022-01-05 17:50:15 +00:00
|
|
|
test('clicking legend item navigates to a pre-filtered clients table', async function (assert) {
|
|
|
|
const legendItem =
|
2022-01-26 16:30:06 +00:00
|
|
|
JobDetail.jobClientStatusSummary.statusBar.legend.clickableItems[0];
|
2022-01-05 17:50:15 +00:00
|
|
|
const status = legendItem.label;
|
|
|
|
await legendItem.click();
|
2021-10-07 21:11:38 +00:00
|
|
|
|
2022-01-05 17:50:15 +00:00
|
|
|
const encodedStatus = encodeURIComponent(JSON.stringify([status]));
|
|
|
|
const expectedURL = new URL(
|
|
|
|
urlWithNamespace(
|
|
|
|
`/jobs/${job.name}/clients?status=${encodedStatus}`,
|
|
|
|
job.namespace
|
|
|
|
),
|
|
|
|
window.location
|
|
|
|
);
|
|
|
|
const gotURL = new URL(currentURL(), window.location);
|
|
|
|
assert.deepEqual(gotURL.path, expectedURL.path);
|
|
|
|
assert.deepEqual(gotURL.searchParams, expectedURL.searchParams);
|
|
|
|
});
|
2021-10-07 21:11:38 +00:00
|
|
|
|
2022-01-05 17:50:15 +00:00
|
|
|
test('clicking in a slice takes you to a pre-filtered clients table', async function (assert) {
|
2022-01-26 16:30:06 +00:00
|
|
|
const slice = JobDetail.jobClientStatusSummary.statusBar.slices[0];
|
2022-01-05 17:50:15 +00:00
|
|
|
const status = slice.label;
|
|
|
|
await slice.click();
|
2021-10-07 21:11:38 +00:00
|
|
|
|
2022-01-05 17:50:15 +00:00
|
|
|
const encodedStatus = encodeURIComponent(JSON.stringify([status]));
|
|
|
|
const expectedURL = new URL(
|
|
|
|
urlWithNamespace(
|
|
|
|
`/jobs/${job.name}/clients?status=${encodedStatus}`,
|
|
|
|
job.namespace
|
|
|
|
),
|
|
|
|
window.location
|
|
|
|
);
|
|
|
|
const gotURL = new URL(currentURL(), window.location);
|
|
|
|
assert.deepEqual(gotURL.pathname, expectedURL.pathname);
|
|
|
|
|
|
|
|
// Sort and compare URL query params.
|
|
|
|
gotURL.searchParams.sort();
|
|
|
|
expectedURL.searchParams.sort();
|
|
|
|
assert.equal(
|
|
|
|
gotURL.searchParams.toString(),
|
|
|
|
expectedURL.searchParams.toString()
|
|
|
|
);
|
|
|
|
});
|
|
|
|
|
|
|
|
for (var testName in additionalTests) {
|
|
|
|
test(testName, async function (assert) {
|
|
|
|
await additionalTests[testName].call(this, job, assert);
|
|
|
|
});
|
|
|
|
}
|
2021-10-07 21:11:38 +00:00
|
|
|
});
|
|
|
|
|
2022-01-05 17:50:15 +00:00
|
|
|
module('without node:read permissions', function (hooks) {
|
|
|
|
hooks.beforeEach(async function () {
|
|
|
|
// Test blank Node policy to mock lack of permission.
|
|
|
|
setPolicy({
|
|
|
|
id: 'node',
|
|
|
|
name: 'node',
|
|
|
|
rulesJSON: {},
|
|
|
|
});
|
|
|
|
|
|
|
|
await visitJobDetailPage(job);
|
2021-10-07 21:11:38 +00:00
|
|
|
});
|
2022-01-05 17:50:15 +00:00
|
|
|
|
|
|
|
test('the page handles presentations concerns regarding the user not having node:read permissions', async function (assert) {
|
|
|
|
assert
|
|
|
|
.dom("[data-test-tab='clients']")
|
|
|
|
.doesNotExist(
|
|
|
|
'Job Detail Sub Navigation should not render Clients tab'
|
|
|
|
);
|
|
|
|
|
|
|
|
assert
|
|
|
|
.dom('[data-test-nodes-not-authorized]')
|
|
|
|
.exists('Renders Not Authorized message');
|
|
|
|
});
|
|
|
|
|
|
|
|
test('/jobs/job/clients route is protected with authorization logic', async function (assert) {
|
|
|
|
await visit(`/jobs/${job.id}/clients`);
|
|
|
|
|
|
|
|
assert.equal(
|
|
|
|
currentRouteName(),
|
|
|
|
'jobs.job.index',
|
|
|
|
'The clients route cannot be visited unless you have node:read permissions'
|
|
|
|
);
|
|
|
|
});
|
|
|
|
});
|
2021-10-07 21:11:38 +00:00
|
|
|
});
|
|
|
|
}
|
|
|
|
|
2021-09-01 18:40:25 +00:00
|
|
|
function urlWithNamespace(url, namespace) {
|
|
|
|
if (!namespace || namespace === 'default') {
|
|
|
|
return url;
|
|
|
|
}
|
|
|
|
|
2021-10-07 21:11:38 +00:00
|
|
|
const parts = url.split('?');
|
|
|
|
const params = new URLSearchParams(parts[1]);
|
|
|
|
params.set('namespace', namespace);
|
|
|
|
|
|
|
|
return `${parts[0]}?${params.toString()}`;
|
2021-09-01 18:40:25 +00:00
|
|
|
}
|
2022-01-05 17:50:15 +00:00
|
|
|
|
|
|
|
async function visitJobDetailPage({ id, namespace }) {
|
|
|
|
if (!namespace || namespace === 'default') {
|
|
|
|
await JobDetail.visit({ id });
|
|
|
|
} else {
|
|
|
|
await JobDetail.visit({ id, namespace });
|
|
|
|
}
|
|
|
|
}
|