2023-04-10 15:36:59 +00:00
|
|
|
/**
|
|
|
|
* Copyright (c) HashiCorp, Inc.
|
|
|
|
* SPDX-License-Identifier: MPL-2.0
|
|
|
|
*/
|
|
|
|
|
2021-12-28 19:30:38 +00:00
|
|
|
/* eslint-disable qunit/require-expect */
|
2019-03-13 00:08:16 +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';
|
2020-07-28 17:59:14 +00:00
|
|
|
import a11yAudit from 'nomad-ui/tests/helpers/a11y-audit';
|
2020-03-31 23:29:34 +00:00
|
|
|
import pageSizeSelect from './behaviors/page-size-select';
|
2018-07-11 01:42:19 +00:00
|
|
|
import JobsList from 'nomad-ui/tests/pages/jobs/list';
|
2022-05-05 20:05:13 +00:00
|
|
|
import percySnapshot from '@percy/ember';
|
2022-09-14 15:27:48 +00:00
|
|
|
import faker from 'nomad-ui/mirage/faker';
|
2017-09-19 14:47:10 +00:00
|
|
|
|
2020-01-20 20:57:01 +00:00
|
|
|
let managementToken, clientToken;
|
|
|
|
|
2021-12-28 14:45:20 +00:00
|
|
|
module('Acceptance | jobs list', function (hooks) {
|
2019-03-13 00:04:16 +00:00
|
|
|
setupApplicationTest(hooks);
|
2019-03-13 01:09:19 +00:00
|
|
|
setupMirage(hooks);
|
2019-03-13 00:04:16 +00:00
|
|
|
|
2021-12-28 14:45:20 +00:00
|
|
|
hooks.beforeEach(function () {
|
2017-09-19 14:47:10 +00:00
|
|
|
// Required for placing allocations (a result of creating jobs)
|
|
|
|
server.create('node');
|
2020-01-20 20:57:01 +00:00
|
|
|
|
|
|
|
managementToken = server.create('token');
|
|
|
|
clientToken = server.create('token');
|
|
|
|
|
2020-03-31 23:11:23 +00:00
|
|
|
window.localStorage.clear();
|
2020-01-20 20:57:01 +00:00
|
|
|
window.localStorage.nomadTokenSecret = managementToken.secretId;
|
2019-03-13 00:04:16 +00:00
|
|
|
});
|
2017-09-19 14:47:10 +00:00
|
|
|
|
2021-12-28 14:45:20 +00:00
|
|
|
test('it passes an accessibility audit', async function (assert) {
|
2020-07-28 17:59:14 +00:00
|
|
|
await JobsList.visit();
|
2020-08-25 15:56:02 +00:00
|
|
|
await a11yAudit(assert);
|
2020-07-28 17:59:14 +00:00
|
|
|
});
|
|
|
|
|
2021-12-28 14:45:20 +00:00
|
|
|
test('visiting /jobs', async function (assert) {
|
2019-03-14 06:44:53 +00:00
|
|
|
await JobsList.visit();
|
2017-09-19 14:47:10 +00:00
|
|
|
|
|
|
|
assert.equal(currentURL(), '/jobs');
|
2019-07-17 20:02:58 +00:00
|
|
|
assert.equal(document.title, 'Jobs - Nomad');
|
2017-09-19 14:47:10 +00:00
|
|
|
});
|
|
|
|
|
2021-12-28 14:45:20 +00:00
|
|
|
test('/jobs should list the first page of jobs sorted by modify index', async function (assert) {
|
2022-09-14 15:27:48 +00:00
|
|
|
faker.seed(1);
|
2019-03-13 00:04:16 +00:00
|
|
|
const jobsCount = JobsList.pageSize + 1;
|
[ui, feature] Job Page Redesign (#16932)
* [ui] Service job status panel (#16134)
* it begins
* Hacky demo enabled
* Still very hacky but seems deece
* Floor of at least 3 must be shown
* Width from on-high
* Other statuses considered
* More sensible allocTypes listing
* Beginnings of a legend
* Total number of allocs running now maps over job.groups
* Lintfix
* base the number of slots to hold open on actual tallies, which should never exceed totalAllocs
* Versions get yer versions here
* Versions lookin like versions
* Mirage fixup
* Adds Remaining as an alloc chart status and adds historical status option
* Get tests passing again by making job status static for a sec
* Historical status panel click actions moved into their own component class
* job detail tests plz chill
* Testing if percy is fickle
* Hyper-specfic on summary distribution bar identifier
* Perhaps the 2nd allocSummary item no longer exists with the more accurate afterCreate data
* UI Test eschewing the page pattern
* Bones of a new acceptance test
* Track width changes explicitly with window-resize
* testlintfix
* Alloc counting tests
* Alloc grouping test
* Alloc grouping with complex resizing
* Refined the list of showable statuses
* PR feedback addressed
* renamed allocation-row to allocation-status-row
* [ui, job status] Make panel status mode a queryParam (#16345)
* queryParam changing
* Test for QP in panel
* Adding @tracked to legacy controller
* Move the job of switching to Historical out to larger context
* integration test mock passed func
* [ui] Service job deployment status panel (#16383)
* A very fast and loose deployment panel
* Removing Unknown status from the panel
* Set up oldAllocs list in constructor, rather than as a getter/tracked var
* Small amount of template cleanup
* Refactored latest-deployment new logic back into panel.js
* Revert now-unused latest-deployment component
* margin bottom when ungrouped also
* Basic integration tests for job deployment status panel
* Updates complete alloc colour to green for new visualizations only (#16618)
* Updates complete alloc colour to green for new visualizations only
* Pale green instead of dark green for viz in general
* [ui] Job Deployment Status: History and Update Props (#16518)
* Deployment history wooooooo
* Styled deployment history
* Update Params
* lintfix
* Types and groups for updateParams
* Live-updating history
* Harden with types, error states, and pending states
* Refactor updateParams to use trigger component
* [ui] Deployment History search (#16608)
* Functioning searchbox
* Some nice animations for history items
* History search test
* Fixing up some old mirage conventions
* some a11y rule override to account for scss keyframes
* Split panel into deploying and steady components
* HandleError passed from job index
* gridified panel elements
* TotalAllocs added to deploying.js
* Width perc to px
* [ui] Splitting deployment allocs by status, health, and canary status (#16766)
* Initial attempt with lots of scratchpad work
* Style mods per UI discussion
* Fix canary overflow bug
* Dont show canary or health for steady/prev-alloc blocks
* Steady state
* Thanks Julie
* Fixes steady-state versions
* Legen, wait for it...
* Test fixes now that we have a minimum block size
* PR prep
* Shimmer effect on pending and unplaced allocs (#16801)
* Shimmer effect on pending and unplaced
* Dont show animation in the legend
* [ui, deployments] Linking allocblocks and legends to allocation / allocations index routes (#16821)
* Conditional link-to component and basic linking to allocations and allocation routes
* Job versions filter added to allocations index page
* Steady state legends link
* Legend links
* Badge count links for versions
* Fix: faded class on steady-state legend items
* version link now wont show completed ones
* Fix a11y violations with link labels
* Combining some template conditional logic
* [ui, deployments] Conversions on long nanosecond update params (#16882)
* Conversions on long nanosecond nums
* Early return in updateParamGroups comp prop
* [ui, deployments] Mirage Actively Deploying Job and Deployment Integration Tests (#16888)
* Start of deployment alloc test scaffolding
* Bit of test cleanup and canary for ungrouped allocs
* Flakey but more robust integrations for deployment panel
* De-flake acceptance tests and add an actively deploying job to mirage
* Jitter-less alloc status distribution removes my bad math
* bugfix caused by summary.desiredTotal non-null
* More interesting mirage active deployment alloc breakdown
* Further tests for previous-allocs row
* Previous alloc legend tests
* Percy snapshots added to integration test
* changelog
2023-04-25 02:45:39 +00:00
|
|
|
server.createList('job', jobsCount, { createAllocations: true });
|
2017-09-19 14:47:10 +00:00
|
|
|
|
2019-03-14 06:44:53 +00:00
|
|
|
await JobsList.visit();
|
2017-09-19 14:47:10 +00:00
|
|
|
|
2022-05-05 20:05:13 +00:00
|
|
|
await percySnapshot(assert);
|
|
|
|
|
2017-09-19 14:47:10 +00:00
|
|
|
const sortedJobs = server.db.jobs.sortBy('modifyIndex').reverse();
|
2018-07-11 01:42:19 +00:00
|
|
|
assert.equal(JobsList.jobs.length, JobsList.pageSize);
|
|
|
|
JobsList.jobs.forEach((job, index) => {
|
|
|
|
assert.equal(job.name, sortedJobs[index].name, 'Jobs are ordered');
|
|
|
|
});
|
2017-09-19 14:47:10 +00:00
|
|
|
});
|
|
|
|
|
2021-12-28 14:45:20 +00:00
|
|
|
test('each job row should contain information about the job', async function (assert) {
|
2019-03-13 00:04:16 +00:00
|
|
|
server.createList('job', 2);
|
|
|
|
const job = server.db.jobs.sortBy('modifyIndex').reverse()[0];
|
|
|
|
const taskGroups = server.db.taskGroups.where({ jobId: job.id });
|
2017-09-19 14:47:10 +00:00
|
|
|
|
2019-03-14 06:44:53 +00:00
|
|
|
await JobsList.visit();
|
2017-09-19 14:47:10 +00:00
|
|
|
|
2018-07-11 01:42:19 +00:00
|
|
|
const jobRow = JobsList.jobs.objectAt(0);
|
|
|
|
|
|
|
|
assert.equal(jobRow.name, job.name, 'Name');
|
2021-04-29 20:00:59 +00:00
|
|
|
assert.notOk(jobRow.hasNamespace);
|
2022-05-13 21:01:27 +00:00
|
|
|
assert.equal(jobRow.link, `/ui/jobs/${job.id}@default`, 'Detail Link');
|
2018-07-11 01:42:19 +00:00
|
|
|
assert.equal(jobRow.status, job.status, 'Status');
|
|
|
|
assert.equal(jobRow.type, typeForJob(job), 'Type');
|
|
|
|
assert.equal(jobRow.priority, job.priority, 'Priority');
|
2019-03-13 00:04:16 +00:00
|
|
|
assert.equal(jobRow.taskGroups, taskGroups.length, '# Groups');
|
2017-09-19 14:47:10 +00:00
|
|
|
});
|
|
|
|
|
2021-12-28 14:45:20 +00:00
|
|
|
test('each job row should link to the corresponding job', async function (assert) {
|
2019-03-13 00:04:16 +00:00
|
|
|
server.create('job');
|
|
|
|
const job = server.db.jobs[0];
|
2017-09-19 14:47:10 +00:00
|
|
|
|
2019-03-14 06:44:53 +00:00
|
|
|
await JobsList.visit();
|
|
|
|
await JobsList.jobs.objectAt(0).clickName();
|
2017-09-19 14:47:10 +00:00
|
|
|
|
2022-05-13 21:01:27 +00:00
|
|
|
assert.equal(currentURL(), `/jobs/${job.id}@default`);
|
2017-09-19 14:47:10 +00:00
|
|
|
});
|
2017-09-30 00:41:12 +00:00
|
|
|
|
2021-12-28 14:45:20 +00:00
|
|
|
test('the new job button transitions to the new job page', async function (assert) {
|
2019-03-14 06:44:53 +00:00
|
|
|
await JobsList.visit();
|
2020-01-20 20:57:01 +00:00
|
|
|
await JobsList.runJobButton.click();
|
2018-08-16 00:12:18 +00:00
|
|
|
|
|
|
|
assert.equal(currentURL(), '/jobs/run');
|
|
|
|
});
|
|
|
|
|
2021-12-28 14:45:20 +00:00
|
|
|
test('the job run button is disabled when the token lacks permission', async function (assert) {
|
2020-01-20 20:57:01 +00:00
|
|
|
window.localStorage.nomadTokenSecret = clientToken.secretId;
|
2022-03-08 17:28:36 +00:00
|
|
|
|
2020-01-20 20:57:01 +00:00
|
|
|
await JobsList.visit();
|
|
|
|
|
|
|
|
assert.ok(JobsList.runJobButton.isDisabled);
|
|
|
|
});
|
|
|
|
|
2021-12-28 14:45:20 +00:00
|
|
|
test('the anonymous policy is fetched to check whether to show the job run button', async function (assert) {
|
2020-01-20 20:57:01 +00:00
|
|
|
window.localStorage.removeItem('nomadTokenSecret');
|
|
|
|
|
|
|
|
server.create('policy', {
|
|
|
|
id: 'anonymous',
|
|
|
|
name: 'anonymous',
|
|
|
|
rulesJSON: {
|
|
|
|
Namespaces: [
|
|
|
|
{
|
|
|
|
Name: 'default',
|
|
|
|
Capabilities: ['list-jobs', 'submit-job'],
|
|
|
|
},
|
|
|
|
],
|
|
|
|
},
|
|
|
|
});
|
|
|
|
|
|
|
|
await JobsList.visit();
|
|
|
|
assert.notOk(JobsList.runJobButton.isDisabled);
|
|
|
|
});
|
|
|
|
|
2021-12-28 14:45:20 +00:00
|
|
|
test('when there are no jobs, there is an empty message', async function (assert) {
|
2022-09-14 15:27:48 +00:00
|
|
|
faker.seed(1);
|
2019-03-14 06:44:53 +00:00
|
|
|
await JobsList.visit();
|
2017-09-30 00:41:12 +00:00
|
|
|
|
2022-05-05 20:05:13 +00:00
|
|
|
await percySnapshot(assert);
|
|
|
|
|
2018-07-11 01:42:19 +00:00
|
|
|
assert.ok(JobsList.isEmpty, 'There is an empty message');
|
2021-12-28 16:08:12 +00:00
|
|
|
assert.equal(
|
|
|
|
JobsList.emptyState.headline,
|
|
|
|
'No Jobs',
|
|
|
|
'The message is appropriate'
|
|
|
|
);
|
2017-09-30 00:41:12 +00:00
|
|
|
});
|
|
|
|
|
2021-12-28 14:45:20 +00:00
|
|
|
test('when there are jobs, but no matches for a search result, there is an empty message', async function (assert) {
|
2019-03-13 00:04:16 +00:00
|
|
|
server.create('job', { name: 'cat 1' });
|
|
|
|
server.create('job', { name: 'cat 2' });
|
2017-09-30 00:41:12 +00:00
|
|
|
|
2019-03-14 06:44:53 +00:00
|
|
|
await JobsList.visit();
|
2017-09-30 00:41:12 +00:00
|
|
|
|
2020-06-19 18:05:28 +00:00
|
|
|
await JobsList.search.fillIn('dog');
|
2018-07-11 01:42:19 +00:00
|
|
|
assert.ok(JobsList.isEmpty, 'The empty message is shown');
|
2021-12-28 16:08:12 +00:00
|
|
|
assert.equal(
|
|
|
|
JobsList.emptyState.headline,
|
|
|
|
'No Matches',
|
|
|
|
'The message is appropriate'
|
|
|
|
);
|
2017-09-30 00:41:12 +00:00
|
|
|
});
|
2017-10-11 20:44:27 +00:00
|
|
|
|
2021-12-28 14:45:20 +00:00
|
|
|
test('searching resets the current page', async function (assert) {
|
2021-12-28 16:08:12 +00:00
|
|
|
server.createList('job', JobsList.pageSize + 1, {
|
|
|
|
createAllocations: false,
|
|
|
|
});
|
2018-10-30 21:17:23 +00:00
|
|
|
|
2019-03-14 06:44:53 +00:00
|
|
|
await JobsList.visit();
|
|
|
|
await JobsList.nextPage();
|
|
|
|
|
2021-12-28 16:08:12 +00:00
|
|
|
assert.equal(
|
|
|
|
currentURL(),
|
|
|
|
'/jobs?page=2',
|
|
|
|
'Page query param captures page=2'
|
|
|
|
);
|
2019-03-14 06:44:53 +00:00
|
|
|
|
2020-06-19 18:05:28 +00:00
|
|
|
await JobsList.search.fillIn('foobar');
|
2019-03-14 06:44:53 +00:00
|
|
|
|
2018-10-30 21:17:23 +00:00
|
|
|
assert.equal(currentURL(), '/jobs?search=foobar', 'No page query param');
|
|
|
|
});
|
|
|
|
|
2021-12-28 14:45:20 +00:00
|
|
|
test('when a cluster has namespaces, each job row includes the job namespace', async function (assert) {
|
2021-04-29 20:00:59 +00:00
|
|
|
server.createList('namespace', 2);
|
|
|
|
server.createList('job', 2);
|
|
|
|
const job = server.db.jobs.sortBy('modifyIndex').reverse()[0];
|
|
|
|
|
|
|
|
await JobsList.visit({ namespace: '*' });
|
|
|
|
|
|
|
|
const jobRow = JobsList.jobs.objectAt(0);
|
|
|
|
assert.equal(jobRow.namespace, job.namespaceId);
|
|
|
|
});
|
|
|
|
|
2021-12-28 14:45:20 +00:00
|
|
|
test('when the namespace query param is set, only matching jobs are shown', async function (assert) {
|
2019-03-13 00:04:16 +00:00
|
|
|
server.createList('namespace', 2);
|
2021-12-28 16:08:12 +00:00
|
|
|
const job1 = server.create('job', {
|
|
|
|
namespaceId: server.db.namespaces[0].id,
|
|
|
|
});
|
|
|
|
const job2 = server.create('job', {
|
|
|
|
namespaceId: server.db.namespaces[1].id,
|
|
|
|
});
|
2017-10-11 20:44:27 +00:00
|
|
|
|
2019-03-14 06:44:53 +00:00
|
|
|
await JobsList.visit();
|
2021-10-21 14:24:07 +00:00
|
|
|
assert.equal(JobsList.jobs.length, 2, 'All jobs by default');
|
2017-10-11 20:44:27 +00:00
|
|
|
|
2021-10-21 14:24:07 +00:00
|
|
|
const firstNamespace = server.db.namespaces[0];
|
|
|
|
await JobsList.visit({ namespace: firstNamespace.id });
|
2018-07-11 01:42:19 +00:00
|
|
|
assert.equal(JobsList.jobs.length, 1, 'One job in the default namespace');
|
2021-12-28 16:08:12 +00:00
|
|
|
assert.equal(
|
|
|
|
JobsList.jobs.objectAt(0).name,
|
|
|
|
job1.name,
|
|
|
|
'The correct job is shown'
|
|
|
|
);
|
2017-10-11 20:44:27 +00:00
|
|
|
|
2019-03-13 00:04:16 +00:00
|
|
|
const secondNamespace = server.db.namespaces[1];
|
2019-03-14 06:44:53 +00:00
|
|
|
await JobsList.visit({ namespace: secondNamespace.id });
|
2017-10-11 20:44:27 +00:00
|
|
|
|
2021-12-28 16:08:12 +00:00
|
|
|
assert.equal(
|
|
|
|
JobsList.jobs.length,
|
|
|
|
1,
|
|
|
|
`One job in the ${secondNamespace.name} namespace`
|
|
|
|
);
|
|
|
|
assert.equal(
|
|
|
|
JobsList.jobs.objectAt(0).name,
|
|
|
|
job2.name,
|
|
|
|
'The correct job is shown'
|
|
|
|
);
|
2017-10-11 20:44:27 +00:00
|
|
|
});
|
2017-10-24 23:08:01 +00:00
|
|
|
|
2021-12-28 14:45:20 +00:00
|
|
|
test('when accessing jobs is forbidden, show a message with a link to the tokens page', async function (assert) {
|
2019-03-13 00:04:16 +00:00
|
|
|
server.pretender.get('/v1/jobs', () => [403, {}, null]);
|
2017-10-24 23:08:01 +00:00
|
|
|
|
2019-03-14 06:44:53 +00:00
|
|
|
await JobsList.visit();
|
2018-07-11 01:42:19 +00:00
|
|
|
assert.equal(JobsList.error.title, 'Not Authorized');
|
2017-10-24 23:08:01 +00:00
|
|
|
|
2019-03-14 06:44:53 +00:00
|
|
|
await JobsList.error.seekHelp();
|
2017-10-24 23:08:01 +00:00
|
|
|
assert.equal(currentURL(), '/settings/tokens');
|
|
|
|
});
|
2018-01-26 23:01:10 +00:00
|
|
|
|
2019-03-13 00:04:16 +00:00
|
|
|
function typeForJob(job) {
|
2021-12-28 16:08:12 +00:00
|
|
|
return job.periodic
|
|
|
|
? 'periodic'
|
|
|
|
: job.parameterized
|
|
|
|
? 'parameterized'
|
|
|
|
: job.type;
|
2019-03-13 00:04:16 +00:00
|
|
|
}
|
2019-01-24 04:35:51 +00:00
|
|
|
|
2021-12-28 14:45:20 +00:00
|
|
|
test('the jobs list page has appropriate faceted search options', async function (assert) {
|
2019-03-14 06:44:53 +00:00
|
|
|
await JobsList.visit();
|
2019-01-24 04:35:51 +00:00
|
|
|
|
2021-12-28 16:08:12 +00:00
|
|
|
assert.ok(
|
|
|
|
JobsList.facets.namespace.isHidden,
|
|
|
|
'Namespace facet not found (no namespaces)'
|
|
|
|
);
|
2019-01-24 04:35:51 +00:00
|
|
|
assert.ok(JobsList.facets.type.isPresent, 'Type facet found');
|
|
|
|
assert.ok(JobsList.facets.status.isPresent, 'Status facet found');
|
|
|
|
assert.ok(JobsList.facets.datacenter.isPresent, 'Datacenter facet found');
|
|
|
|
assert.ok(JobsList.facets.prefix.isPresent, 'Prefix facet found');
|
|
|
|
});
|
|
|
|
|
2021-04-29 20:00:59 +00:00
|
|
|
testSingleSelectFacet('Namespace', {
|
|
|
|
facet: JobsList.facets.namespace,
|
|
|
|
paramName: 'namespace',
|
|
|
|
expectedOptions: ['All (*)', 'default', 'namespace-2'],
|
|
|
|
optionToSelect: 'namespace-2',
|
|
|
|
async beforeEach() {
|
|
|
|
server.create('namespace', { id: 'default' });
|
|
|
|
server.create('namespace', { id: 'namespace-2' });
|
|
|
|
server.createList('job', 2, { namespaceId: 'default' });
|
|
|
|
server.createList('job', 2, { namespaceId: 'namespace-2' });
|
|
|
|
await JobsList.visit();
|
|
|
|
},
|
|
|
|
filter(job, selection) {
|
|
|
|
return job.namespaceId === selection;
|
|
|
|
},
|
|
|
|
});
|
|
|
|
|
2019-03-13 00:04:16 +00:00
|
|
|
testFacet('Type', {
|
|
|
|
facet: JobsList.facets.type,
|
|
|
|
paramName: 'type',
|
2021-12-28 16:08:12 +00:00
|
|
|
expectedOptions: [
|
|
|
|
'Batch',
|
2023-05-18 16:47:11 +00:00
|
|
|
'Pack',
|
2021-12-28 16:08:12 +00:00
|
|
|
'Parameterized',
|
|
|
|
'Periodic',
|
|
|
|
'Service',
|
|
|
|
'System',
|
|
|
|
'System Batch',
|
|
|
|
],
|
2019-03-14 06:44:53 +00:00
|
|
|
async beforeEach() {
|
2019-03-13 00:04:16 +00:00
|
|
|
server.createList('job', 2, { createAllocations: false, type: 'batch' });
|
|
|
|
server.createList('job', 2, {
|
|
|
|
createAllocations: false,
|
|
|
|
type: 'batch',
|
|
|
|
periodic: true,
|
|
|
|
childrenCount: 0,
|
|
|
|
});
|
|
|
|
server.createList('job', 2, {
|
|
|
|
createAllocations: false,
|
|
|
|
type: 'batch',
|
|
|
|
parameterized: true,
|
|
|
|
childrenCount: 0,
|
|
|
|
});
|
2021-12-28 16:08:12 +00:00
|
|
|
server.createList('job', 2, {
|
|
|
|
createAllocations: false,
|
|
|
|
type: 'service',
|
|
|
|
});
|
2019-03-14 06:44:53 +00:00
|
|
|
await JobsList.visit();
|
2019-03-13 00:04:16 +00:00
|
|
|
},
|
|
|
|
filter(job, selection) {
|
|
|
|
let displayType = job.type;
|
|
|
|
if (job.parameterized) displayType = 'parameterized';
|
|
|
|
if (job.periodic) displayType = 'periodic';
|
|
|
|
return selection.includes(displayType);
|
|
|
|
},
|
|
|
|
});
|
2019-01-24 04:35:51 +00:00
|
|
|
|
2019-03-13 00:04:16 +00:00
|
|
|
testFacet('Status', {
|
|
|
|
facet: JobsList.facets.status,
|
|
|
|
paramName: 'status',
|
|
|
|
expectedOptions: ['Pending', 'Running', 'Dead'],
|
2019-03-14 06:44:53 +00:00
|
|
|
async beforeEach() {
|
2019-03-13 00:40:39 +00:00
|
|
|
server.createList('job', 2, {
|
|
|
|
status: 'pending',
|
|
|
|
createAllocations: false,
|
|
|
|
childrenCount: 0,
|
|
|
|
});
|
|
|
|
server.createList('job', 2, {
|
|
|
|
status: 'running',
|
|
|
|
createAllocations: false,
|
|
|
|
childrenCount: 0,
|
|
|
|
});
|
2021-12-28 16:08:12 +00:00
|
|
|
server.createList('job', 2, {
|
|
|
|
status: 'dead',
|
|
|
|
createAllocations: false,
|
|
|
|
childrenCount: 0,
|
|
|
|
});
|
2019-03-14 06:44:53 +00:00
|
|
|
await JobsList.visit();
|
2019-03-13 00:04:16 +00:00
|
|
|
},
|
|
|
|
filter: (job, selection) => selection.includes(job.status),
|
|
|
|
});
|
2019-01-24 04:35:51 +00:00
|
|
|
|
2019-03-13 00:04:16 +00:00
|
|
|
testFacet('Datacenter', {
|
|
|
|
facet: JobsList.facets.datacenter,
|
|
|
|
paramName: 'dc',
|
|
|
|
expectedOptions(jobs) {
|
|
|
|
const allDatacenters = new Set(
|
|
|
|
jobs.mapBy('datacenters').reduce((acc, val) => acc.concat(val), [])
|
|
|
|
);
|
|
|
|
return Array.from(allDatacenters).sort();
|
|
|
|
},
|
2019-03-14 06:44:53 +00:00
|
|
|
async beforeEach() {
|
2019-03-13 00:04:16 +00:00
|
|
|
server.create('job', {
|
|
|
|
datacenters: ['pdx', 'lax'],
|
|
|
|
createAllocations: false,
|
|
|
|
childrenCount: 0,
|
|
|
|
});
|
|
|
|
server.create('job', {
|
|
|
|
datacenters: ['pdx', 'ord'],
|
|
|
|
createAllocations: false,
|
|
|
|
childrenCount: 0,
|
|
|
|
});
|
|
|
|
server.create('job', {
|
|
|
|
datacenters: ['lax', 'jfk'],
|
|
|
|
createAllocations: false,
|
|
|
|
childrenCount: 0,
|
|
|
|
});
|
|
|
|
server.create('job', {
|
|
|
|
datacenters: ['jfk', 'dfw'],
|
|
|
|
createAllocations: false,
|
|
|
|
childrenCount: 0,
|
|
|
|
});
|
2021-12-28 16:08:12 +00:00
|
|
|
server.create('job', {
|
|
|
|
datacenters: ['pdx'],
|
|
|
|
createAllocations: false,
|
|
|
|
childrenCount: 0,
|
|
|
|
});
|
2019-03-14 06:44:53 +00:00
|
|
|
await JobsList.visit();
|
2019-03-13 00:04:16 +00:00
|
|
|
},
|
2021-12-28 16:08:12 +00:00
|
|
|
filter: (job, selection) =>
|
|
|
|
job.datacenters.find((dc) => selection.includes(dc)),
|
2019-03-13 00:04:16 +00:00
|
|
|
});
|
2019-01-24 04:35:51 +00:00
|
|
|
|
2019-03-13 00:04:16 +00:00
|
|
|
testFacet('Prefix', {
|
|
|
|
facet: JobsList.facets.prefix,
|
|
|
|
paramName: 'prefix',
|
|
|
|
expectedOptions: ['hashi (3)', 'nmd (2)', 'pre (2)'],
|
2019-03-14 06:44:53 +00:00
|
|
|
async beforeEach() {
|
2019-03-13 00:04:16 +00:00
|
|
|
[
|
|
|
|
'pre-one',
|
2019-05-21 21:20:40 +00:00
|
|
|
'hashi_one',
|
|
|
|
'nmd.one',
|
2019-03-13 00:04:16 +00:00
|
|
|
'one-alone',
|
2019-05-21 21:20:40 +00:00
|
|
|
'pre_two',
|
|
|
|
'hashi.two',
|
2019-03-13 00:04:16 +00:00
|
|
|
'hashi-three',
|
2019-05-21 21:20:40 +00:00
|
|
|
'nmd_two',
|
2019-03-13 00:04:16 +00:00
|
|
|
'noprefix',
|
2021-12-28 14:45:20 +00:00
|
|
|
].forEach((name) => {
|
2021-12-28 16:08:12 +00:00
|
|
|
server.create('job', {
|
|
|
|
name,
|
|
|
|
createAllocations: false,
|
|
|
|
childrenCount: 0,
|
|
|
|
});
|
2019-03-13 00:04:16 +00:00
|
|
|
});
|
2019-03-14 06:44:53 +00:00
|
|
|
await JobsList.visit();
|
2019-03-13 00:04:16 +00:00
|
|
|
},
|
2021-12-28 16:08:12 +00:00
|
|
|
filter: (job, selection) =>
|
|
|
|
selection.find((prefix) => job.name.startsWith(prefix)),
|
2019-03-13 00:04:16 +00:00
|
|
|
});
|
2019-01-24 04:35:51 +00:00
|
|
|
|
2021-12-28 14:45:20 +00:00
|
|
|
test('when the facet selections result in no matches, the empty state states why', async function (assert) {
|
2021-12-28 16:08:12 +00:00
|
|
|
server.createList('job', 2, {
|
|
|
|
status: 'pending',
|
|
|
|
createAllocations: false,
|
|
|
|
childrenCount: 0,
|
|
|
|
});
|
2019-01-24 04:35:51 +00:00
|
|
|
|
2019-03-14 06:44:53 +00:00
|
|
|
await JobsList.visit();
|
2019-01-24 04:35:51 +00:00
|
|
|
|
2019-03-14 06:44:53 +00:00
|
|
|
await JobsList.facets.status.toggle();
|
|
|
|
await JobsList.facets.status.options.objectAt(1).toggle();
|
2019-01-24 04:35:51 +00:00
|
|
|
assert.ok(JobsList.isEmpty, 'There is an empty message');
|
2021-12-28 16:08:12 +00:00
|
|
|
assert.equal(
|
|
|
|
JobsList.emptyState.headline,
|
|
|
|
'No Matches',
|
|
|
|
'The message is appropriate'
|
|
|
|
);
|
2019-01-24 04:35:51 +00:00
|
|
|
});
|
|
|
|
|
2021-12-28 14:45:20 +00:00
|
|
|
test('the jobs list is immediately filtered based on query params', async function (assert) {
|
2019-03-13 00:04:16 +00:00
|
|
|
server.create('job', { type: 'batch', createAllocations: false });
|
|
|
|
server.create('job', { type: 'service', createAllocations: false });
|
2019-01-24 04:35:51 +00:00
|
|
|
|
2019-03-14 06:44:53 +00:00
|
|
|
await JobsList.visit({ type: JSON.stringify(['batch']) });
|
2019-01-24 04:35:51 +00:00
|
|
|
|
2021-12-28 16:08:12 +00:00
|
|
|
assert.equal(
|
|
|
|
JobsList.jobs.length,
|
|
|
|
1,
|
|
|
|
'Only one job shown due to query param'
|
|
|
|
);
|
2019-01-24 04:35:51 +00:00
|
|
|
});
|
|
|
|
|
2021-12-28 14:45:20 +00:00
|
|
|
test('when the user has a client token that has a namespace with a policy to run a job', async function (assert) {
|
2021-07-13 12:20:41 +00:00
|
|
|
const READ_AND_WRITE_NAMESPACE = 'read-and-write-namespace';
|
|
|
|
const READ_ONLY_NAMESPACE = 'read-only-namespace';
|
|
|
|
|
|
|
|
server.create('namespace', { id: READ_AND_WRITE_NAMESPACE });
|
|
|
|
server.create('namespace', { id: READ_ONLY_NAMESPACE });
|
|
|
|
|
|
|
|
const policy = server.create('policy', {
|
|
|
|
id: 'something',
|
|
|
|
name: 'something',
|
|
|
|
rulesJSON: {
|
|
|
|
Namespaces: [
|
|
|
|
{
|
|
|
|
Name: READ_AND_WRITE_NAMESPACE,
|
|
|
|
Capabilities: ['submit-job'],
|
|
|
|
},
|
|
|
|
{
|
|
|
|
Name: READ_ONLY_NAMESPACE,
|
|
|
|
Capabilities: ['list-job'],
|
|
|
|
},
|
|
|
|
],
|
|
|
|
},
|
|
|
|
});
|
|
|
|
|
|
|
|
clientToken.policyIds = [policy.id];
|
|
|
|
clientToken.save();
|
|
|
|
|
|
|
|
window.localStorage.nomadTokenSecret = clientToken.secretId;
|
|
|
|
|
|
|
|
await JobsList.visit({ namespace: READ_AND_WRITE_NAMESPACE });
|
|
|
|
assert.notOk(JobsList.runJobButton.isDisabled);
|
|
|
|
|
2022-07-11 16:33:17 +00:00
|
|
|
await JobsList.visit({ namespace: READ_ONLY_NAMESPACE });
|
|
|
|
assert.notOk(JobsList.runJobButton.isDisabled);
|
|
|
|
});
|
|
|
|
|
|
|
|
test('when the user has no client tokens that allow them to run a job', async function (assert) {
|
|
|
|
const READ_AND_WRITE_NAMESPACE = 'read-and-write-namespace';
|
|
|
|
const READ_ONLY_NAMESPACE = 'read-only-namespace';
|
|
|
|
|
|
|
|
server.create('namespace', { id: READ_ONLY_NAMESPACE });
|
|
|
|
|
|
|
|
const policy = server.create('policy', {
|
|
|
|
id: 'something',
|
|
|
|
name: 'something',
|
|
|
|
rulesJSON: {
|
|
|
|
Namespaces: [
|
|
|
|
{
|
|
|
|
Name: READ_ONLY_NAMESPACE,
|
|
|
|
Capabilities: ['list-job'],
|
|
|
|
},
|
|
|
|
],
|
|
|
|
},
|
|
|
|
});
|
|
|
|
|
|
|
|
clientToken.policyIds = [policy.id];
|
|
|
|
clientToken.save();
|
|
|
|
|
|
|
|
window.localStorage.nomadTokenSecret = clientToken.secretId;
|
|
|
|
|
|
|
|
await JobsList.visit({ namespace: READ_AND_WRITE_NAMESPACE });
|
|
|
|
assert.ok(JobsList.runJobButton.isDisabled);
|
|
|
|
|
2021-07-13 12:20:41 +00:00
|
|
|
await JobsList.visit({ namespace: READ_ONLY_NAMESPACE });
|
|
|
|
assert.ok(JobsList.runJobButton.isDisabled);
|
|
|
|
});
|
|
|
|
|
2020-03-31 23:29:34 +00:00
|
|
|
pageSizeSelect({
|
|
|
|
resourceName: 'job',
|
|
|
|
pageObject: JobsList,
|
|
|
|
pageObjectList: JobsList.jobs,
|
|
|
|
async setup() {
|
2021-12-28 16:08:12 +00:00
|
|
|
server.createList('job', JobsList.pageSize, {
|
|
|
|
shallow: true,
|
|
|
|
createAllocations: false,
|
|
|
|
});
|
2020-03-31 23:29:34 +00:00
|
|
|
await JobsList.visit();
|
|
|
|
},
|
2020-03-31 23:11:23 +00:00
|
|
|
});
|
|
|
|
|
2021-04-29 20:00:59 +00:00
|
|
|
async function facetOptions(assert, beforeEach, facet, expectedOptions) {
|
|
|
|
await beforeEach();
|
|
|
|
await facet.toggle();
|
|
|
|
|
|
|
|
let expectation;
|
|
|
|
if (typeof expectedOptions === 'function') {
|
|
|
|
expectation = expectedOptions(server.db.jobs);
|
|
|
|
} else {
|
|
|
|
expectation = expectedOptions;
|
|
|
|
}
|
|
|
|
|
|
|
|
assert.deepEqual(
|
2021-12-28 14:45:20 +00:00
|
|
|
facet.options.map((option) => option.label.trim()),
|
2021-04-29 20:00:59 +00:00
|
|
|
expectation,
|
|
|
|
'Options for facet are as expected'
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
function testSingleSelectFacet(
|
|
|
|
label,
|
|
|
|
{ facet, paramName, beforeEach, filter, expectedOptions, optionToSelect }
|
|
|
|
) {
|
2021-12-28 14:45:20 +00:00
|
|
|
test(`the ${label} facet has the correct options`, async function (assert) {
|
2021-04-29 20:00:59 +00:00
|
|
|
await facetOptions(assert, beforeEach, facet, expectedOptions);
|
|
|
|
});
|
|
|
|
|
2021-12-28 14:45:20 +00:00
|
|
|
test(`the ${label} facet filters the jobs list by ${label}`, async function (assert) {
|
2021-04-29 20:00:59 +00:00
|
|
|
await beforeEach();
|
|
|
|
await facet.toggle();
|
|
|
|
|
|
|
|
const option = facet.options.findOneBy('label', optionToSelect);
|
|
|
|
const selection = option.key;
|
|
|
|
await option.select();
|
|
|
|
|
|
|
|
const expectedJobs = server.db.jobs
|
2021-12-28 14:45:20 +00:00
|
|
|
.filter((job) => filter(job, selection))
|
2021-04-29 20:00:59 +00:00
|
|
|
.sortBy('modifyIndex')
|
|
|
|
.reverse();
|
|
|
|
|
|
|
|
JobsList.jobs.forEach((job, index) => {
|
|
|
|
assert.equal(
|
|
|
|
job.id,
|
|
|
|
expectedJobs[index].id,
|
|
|
|
`Job at ${index} is ${expectedJobs[index].id}`
|
|
|
|
);
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
2021-12-28 14:45:20 +00:00
|
|
|
test(`selecting an option in the ${label} facet updates the ${paramName} query param`, async function (assert) {
|
2019-03-14 06:44:53 +00:00
|
|
|
await beforeEach();
|
|
|
|
await facet.toggle();
|
|
|
|
|
2021-04-29 20:00:59 +00:00
|
|
|
const option = facet.options.objectAt(1);
|
|
|
|
const selection = option.key;
|
|
|
|
await option.select();
|
|
|
|
|
|
|
|
assert.ok(
|
|
|
|
currentURL().includes(`${paramName}=${selection}`),
|
|
|
|
'URL has the correct query param key and value'
|
2019-03-14 06:44:53 +00:00
|
|
|
);
|
2019-01-24 04:35:51 +00:00
|
|
|
});
|
2021-04-29 20:00:59 +00:00
|
|
|
}
|
|
|
|
|
2021-12-28 16:08:12 +00:00
|
|
|
function testFacet(
|
|
|
|
label,
|
|
|
|
{ facet, paramName, beforeEach, filter, expectedOptions }
|
|
|
|
) {
|
2021-12-28 14:45:20 +00:00
|
|
|
test(`the ${label} facet has the correct options`, async function (assert) {
|
2021-04-29 20:00:59 +00:00
|
|
|
await facetOptions(assert, beforeEach, facet, expectedOptions);
|
|
|
|
});
|
2019-01-24 04:35:51 +00:00
|
|
|
|
2021-12-28 14:45:20 +00:00
|
|
|
test(`the ${label} facet filters the jobs list by ${label}`, async function (assert) {
|
2019-03-13 00:04:16 +00:00
|
|
|
let option;
|
2019-01-24 04:35:51 +00:00
|
|
|
|
2019-03-14 06:44:53 +00:00
|
|
|
await beforeEach();
|
|
|
|
await facet.toggle();
|
2019-01-24 04:35:51 +00:00
|
|
|
|
2019-03-14 06:44:53 +00:00
|
|
|
option = facet.options.objectAt(0);
|
|
|
|
await option.toggle();
|
2019-01-24 04:35:51 +00:00
|
|
|
|
2019-03-14 06:44:53 +00:00
|
|
|
const selection = [option.key];
|
|
|
|
const expectedJobs = server.db.jobs
|
2021-12-28 14:45:20 +00:00
|
|
|
.filter((job) => filter(job, selection))
|
2019-03-14 06:44:53 +00:00
|
|
|
.sortBy('modifyIndex')
|
|
|
|
.reverse();
|
2019-01-24 04:35:51 +00:00
|
|
|
|
2019-03-14 06:44:53 +00:00
|
|
|
JobsList.jobs.forEach((job, index) => {
|
|
|
|
assert.equal(
|
|
|
|
job.id,
|
|
|
|
expectedJobs[index].id,
|
|
|
|
`Job at ${index} is ${expectedJobs[index].id}`
|
|
|
|
);
|
2019-01-24 04:35:51 +00:00
|
|
|
});
|
|
|
|
});
|
|
|
|
|
2021-12-28 14:45:20 +00:00
|
|
|
test(`selecting multiple options in the ${label} facet results in a broader search`, async function (assert) {
|
2019-03-13 00:04:16 +00:00
|
|
|
const selection = [];
|
2019-01-24 04:35:51 +00:00
|
|
|
|
2019-03-14 06:44:53 +00:00
|
|
|
await beforeEach();
|
|
|
|
await facet.toggle();
|
2019-01-24 04:35:51 +00:00
|
|
|
|
2019-03-14 06:44:53 +00:00
|
|
|
const option1 = facet.options.objectAt(0);
|
|
|
|
const option2 = facet.options.objectAt(1);
|
|
|
|
await option1.toggle();
|
|
|
|
selection.push(option1.key);
|
|
|
|
await option2.toggle();
|
|
|
|
selection.push(option2.key);
|
2019-01-24 04:35:51 +00:00
|
|
|
|
2019-03-14 06:44:53 +00:00
|
|
|
const expectedJobs = server.db.jobs
|
2021-12-28 14:45:20 +00:00
|
|
|
.filter((job) => filter(job, selection))
|
2019-03-14 06:44:53 +00:00
|
|
|
.sortBy('modifyIndex')
|
|
|
|
.reverse();
|
2019-01-24 04:35:51 +00:00
|
|
|
|
2019-03-14 06:44:53 +00:00
|
|
|
JobsList.jobs.forEach((job, index) => {
|
|
|
|
assert.equal(
|
|
|
|
job.id,
|
|
|
|
expectedJobs[index].id,
|
|
|
|
`Job at ${index} is ${expectedJobs[index].id}`
|
|
|
|
);
|
2019-01-24 04:35:51 +00:00
|
|
|
});
|
|
|
|
});
|
|
|
|
|
2021-12-28 14:45:20 +00:00
|
|
|
test(`selecting options in the ${label} facet updates the ${paramName} query param`, async function (assert) {
|
2019-03-13 00:04:16 +00:00
|
|
|
const selection = [];
|
2019-01-24 04:35:51 +00:00
|
|
|
|
2019-03-14 06:44:53 +00:00
|
|
|
await beforeEach();
|
|
|
|
await facet.toggle();
|
2019-01-24 04:35:51 +00:00
|
|
|
|
2019-03-14 06:44:53 +00:00
|
|
|
const option1 = facet.options.objectAt(0);
|
|
|
|
const option2 = facet.options.objectAt(1);
|
|
|
|
await option1.toggle();
|
|
|
|
selection.push(option1.key);
|
|
|
|
await option2.toggle();
|
|
|
|
selection.push(option2.key);
|
2019-01-24 04:35:51 +00:00
|
|
|
|
2021-04-29 20:00:59 +00:00
|
|
|
assert.ok(
|
|
|
|
currentURL().includes(encodeURIComponent(JSON.stringify(selection))),
|
2019-03-14 06:44:53 +00:00
|
|
|
'URL has the correct query param key and value'
|
|
|
|
);
|
2019-01-24 04:35:51 +00:00
|
|
|
});
|
2020-07-10 00:01:34 +00:00
|
|
|
|
2021-12-28 14:45:20 +00:00
|
|
|
test('the run job button works when filters are set', async function (assert) {
|
|
|
|
['pre-one', 'pre-two', 'pre-three'].forEach((name) => {
|
2021-12-28 16:08:12 +00:00
|
|
|
server.create('job', {
|
|
|
|
name,
|
|
|
|
createAllocations: false,
|
|
|
|
childrenCount: 0,
|
|
|
|
});
|
2020-07-10 00:01:34 +00:00
|
|
|
});
|
|
|
|
|
|
|
|
await JobsList.visit();
|
|
|
|
|
|
|
|
await JobsList.facets.prefix.toggle();
|
|
|
|
await JobsList.facets.prefix.options[0].toggle();
|
|
|
|
|
|
|
|
await JobsList.runJobButton.click();
|
|
|
|
assert.equal(currentURL(), '/jobs/run');
|
|
|
|
});
|
2019-03-13 00:04:16 +00:00
|
|
|
}
|
|
|
|
});
|