open-nomad/ui/tests/helpers/module-for-job.js

102 lines
3.6 KiB
JavaScript
Raw Normal View History

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';
// eslint-disable-next-line ember/no-test-module-for
export default function moduleForJob(title, context, jobFactory, additionalTests) {
let job;
module(title, function(hooks) {
setupApplicationTest(hooks);
2019-03-13 01:09:19 +00:00
setupMirage(hooks);
hooks.before(function() {
if (context !== 'allocations' && context !== 'children') {
throw new Error(
`Invalid context provided to moduleForJob, expected either "allocations" or "children", got ${context}`
);
}
});
hooks.beforeEach(async function() {
server.create('node');
job = jobFactory();
await JobDetail.visit({ id: job.id });
});
test('visiting /jobs/:job_id', async function(assert) {
ui: add parameterized dispatch interface (#10675) * ui: add parameterized dispatch interface This commit adds a new interface for dispatching parameteried jobs, if the user has the right permissions. The UI can be accessed by viewing a parameterized job and clicking on the "Dispatch Job" button located in the "Job Launches" section. * fix failing lint test * clean up dispatch and remove meta This commit cleans up a few things that had typos and inconsistent naming. In line with this, the custom `meta` view was removed in favor of using the included `AttributesTable`. * ui: encode dispatch job payload and start adding tests * ui: remove unused test imports * ui: redesign job dispatch form * ui: initial acceptance tests for dispatch job * ui: generate parameterized job children with correct id format * ui: fix job dispatch breadcrumb link * ui: refactor job dispatch component into glimmer component and add form validation * ui: remove unused CSS class * ui: align job dispatch button * ui: handle namespace-specific requests on job dispatch * ui: rename payloadMissing to payloadHasError * ui: don't re-fetch job spec on dispatch job * ui: keep overview tab selected on job dispatch page * ui: fix task and task-group linting * ui: URL encode job id on dispatch job tests * ui: fix error when job meta is null * ui: handle job dispatch from adapter * ui: add more tests for dispatch job page * ui: add "job dispatch" capability check * ui: update job dispatch from code review Co-authored-by: Luiz Aoqui <luiz@hashicorp.com>
2021-07-20 22:27:41 +00:00
assert.equal(currentURL(), `/jobs/${encodeURIComponent(job.id)}`);
assert.equal(document.title, `Job ${job.name} - Nomad`);
});
test('the subnav links to overview', async function(assert) {
await JobDetail.tabFor('overview').visit();
ui: add parameterized dispatch interface (#10675) * ui: add parameterized dispatch interface This commit adds a new interface for dispatching parameteried jobs, if the user has the right permissions. The UI can be accessed by viewing a parameterized job and clicking on the "Dispatch Job" button located in the "Job Launches" section. * fix failing lint test * clean up dispatch and remove meta This commit cleans up a few things that had typos and inconsistent naming. In line with this, the custom `meta` view was removed in favor of using the included `AttributesTable`. * ui: encode dispatch job payload and start adding tests * ui: remove unused test imports * ui: redesign job dispatch form * ui: initial acceptance tests for dispatch job * ui: generate parameterized job children with correct id format * ui: fix job dispatch breadcrumb link * ui: refactor job dispatch component into glimmer component and add form validation * ui: remove unused CSS class * ui: align job dispatch button * ui: handle namespace-specific requests on job dispatch * ui: rename payloadMissing to payloadHasError * ui: don't re-fetch job spec on dispatch job * ui: keep overview tab selected on job dispatch page * ui: fix task and task-group linting * ui: URL encode job id on dispatch job tests * ui: fix error when job meta is null * ui: handle job dispatch from adapter * ui: add more tests for dispatch job page * ui: add "job dispatch" capability check * ui: update job dispatch from code review Co-authored-by: Luiz Aoqui <luiz@hashicorp.com>
2021-07-20 22:27:41 +00:00
assert.equal(currentURL(), `/jobs/${encodeURIComponent(job.id)}`);
});
test('the subnav links to definition', async function(assert) {
await JobDetail.tabFor('definition').visit();
ui: add parameterized dispatch interface (#10675) * ui: add parameterized dispatch interface This commit adds a new interface for dispatching parameteried jobs, if the user has the right permissions. The UI can be accessed by viewing a parameterized job and clicking on the "Dispatch Job" button located in the "Job Launches" section. * fix failing lint test * clean up dispatch and remove meta This commit cleans up a few things that had typos and inconsistent naming. In line with this, the custom `meta` view was removed in favor of using the included `AttributesTable`. * ui: encode dispatch job payload and start adding tests * ui: remove unused test imports * ui: redesign job dispatch form * ui: initial acceptance tests for dispatch job * ui: generate parameterized job children with correct id format * ui: fix job dispatch breadcrumb link * ui: refactor job dispatch component into glimmer component and add form validation * ui: remove unused CSS class * ui: align job dispatch button * ui: handle namespace-specific requests on job dispatch * ui: rename payloadMissing to payloadHasError * ui: don't re-fetch job spec on dispatch job * ui: keep overview tab selected on job dispatch page * ui: fix task and task-group linting * ui: URL encode job id on dispatch job tests * ui: fix error when job meta is null * ui: handle job dispatch from adapter * ui: add more tests for dispatch job page * ui: add "job dispatch" capability check * ui: update job dispatch from code review Co-authored-by: Luiz Aoqui <luiz@hashicorp.com>
2021-07-20 22:27:41 +00:00
assert.equal(currentURL(), `/jobs/${encodeURIComponent(job.id)}/definition`);
});
test('the subnav links to versions', async function(assert) {
await JobDetail.tabFor('versions').visit();
ui: add parameterized dispatch interface (#10675) * ui: add parameterized dispatch interface This commit adds a new interface for dispatching parameteried jobs, if the user has the right permissions. The UI can be accessed by viewing a parameterized job and clicking on the "Dispatch Job" button located in the "Job Launches" section. * fix failing lint test * clean up dispatch and remove meta This commit cleans up a few things that had typos and inconsistent naming. In line with this, the custom `meta` view was removed in favor of using the included `AttributesTable`. * ui: encode dispatch job payload and start adding tests * ui: remove unused test imports * ui: redesign job dispatch form * ui: initial acceptance tests for dispatch job * ui: generate parameterized job children with correct id format * ui: fix job dispatch breadcrumb link * ui: refactor job dispatch component into glimmer component and add form validation * ui: remove unused CSS class * ui: align job dispatch button * ui: handle namespace-specific requests on job dispatch * ui: rename payloadMissing to payloadHasError * ui: don't re-fetch job spec on dispatch job * ui: keep overview tab selected on job dispatch page * ui: fix task and task-group linting * ui: URL encode job id on dispatch job tests * ui: fix error when job meta is null * ui: handle job dispatch from adapter * ui: add more tests for dispatch job page * ui: add "job dispatch" capability check * ui: update job dispatch from code review Co-authored-by: Luiz Aoqui <luiz@hashicorp.com>
2021-07-20 22:27:41 +00:00
assert.equal(currentURL(), `/jobs/${encodeURIComponent(job.id)}/versions`);
2018-07-11 02:28:54 +00:00
});
test('the subnav links to evaluations', async function(assert) {
await JobDetail.tabFor('evaluations').visit();
ui: add parameterized dispatch interface (#10675) * ui: add parameterized dispatch interface This commit adds a new interface for dispatching parameteried jobs, if the user has the right permissions. The UI can be accessed by viewing a parameterized job and clicking on the "Dispatch Job" button located in the "Job Launches" section. * fix failing lint test * clean up dispatch and remove meta This commit cleans up a few things that had typos and inconsistent naming. In line with this, the custom `meta` view was removed in favor of using the included `AttributesTable`. * ui: encode dispatch job payload and start adding tests * ui: remove unused test imports * ui: redesign job dispatch form * ui: initial acceptance tests for dispatch job * ui: generate parameterized job children with correct id format * ui: fix job dispatch breadcrumb link * ui: refactor job dispatch component into glimmer component and add form validation * ui: remove unused CSS class * ui: align job dispatch button * ui: handle namespace-specific requests on job dispatch * ui: rename payloadMissing to payloadHasError * ui: don't re-fetch job spec on dispatch job * ui: keep overview tab selected on job dispatch page * ui: fix task and task-group linting * ui: URL encode job id on dispatch job tests * ui: fix error when job meta is null * ui: handle job dispatch from adapter * ui: add more tests for dispatch job page * ui: add "job dispatch" capability check * ui: update job dispatch from code review Co-authored-by: Luiz Aoqui <luiz@hashicorp.com>
2021-07-20 22:27:41 +00:00
assert.equal(currentURL(), `/jobs/${encodeURIComponent(job.id)}/evaluations`);
});
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);
}
});
if (context === 'allocations') {
test('allocations for the job are shown in the overview', async function(assert) {
assert.ok(JobDetail.allocationsSummary, 'Allocations are shown in the summary section');
assert.notOk(JobDetail.childrenSummary, 'Children are not shown in the summary section');
});
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'
);
});
}
if (context === 'children') {
test('children for the job are shown in the overview', async function(assert) {
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) {
test(testName, async function(assert) {
await additionalTests[testName].call(this, job, assert);
});
}
});
}