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';
|
2018-07-11 01:42:19 +00:00
|
|
|
import JobsList from 'nomad-ui/tests/pages/jobs/list';
|
2017-09-19 14:47:10 +00:00
|
|
|
|
2020-01-20 20:57:01 +00:00
|
|
|
let managementToken, clientToken;
|
|
|
|
|
2019-03-13 00:04:16 +00:00
|
|
|
module('Acceptance | jobs list', function(hooks) {
|
|
|
|
setupApplicationTest(hooks);
|
2019-03-13 01:09:19 +00:00
|
|
|
setupMirage(hooks);
|
2019-03-13 00:04:16 +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');
|
|
|
|
|
|
|
|
window.localStorage.nomadTokenSecret = managementToken.secretId;
|
2019-03-13 00:04:16 +00:00
|
|
|
});
|
2017-09-19 14:47:10 +00:00
|
|
|
|
2019-03-14 06:44:53 +00:00
|
|
|
test('visiting /jobs', async function(assert) {
|
|
|
|
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
|
|
|
});
|
|
|
|
|
2019-03-14 06:44:53 +00:00
|
|
|
test('/jobs should list the first page of jobs sorted by modify index', async function(assert) {
|
2019-03-13 00:04:16 +00:00
|
|
|
const jobsCount = JobsList.pageSize + 1;
|
|
|
|
server.createList('job', jobsCount, { createAllocations: false });
|
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
|
|
|
|
|
|
|
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
|
|
|
});
|
|
|
|
|
2019-03-14 06:44:53 +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');
|
|
|
|
assert.equal(jobRow.link, `/ui/jobs/${job.id}`, 'Detail Link');
|
|
|
|
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
|
|
|
});
|
|
|
|
|
2019-03-14 06:44:53 +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
|
|
|
|
|
|
|
assert.equal(currentURL(), `/jobs/${job.id}`);
|
|
|
|
});
|
2017-09-30 00:41:12 +00:00
|
|
|
|
2019-03-14 06:44:53 +00:00
|
|
|
test('the new job button transitions to the new job page', async function(assert) {
|
|
|
|
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');
|
|
|
|
});
|
|
|
|
|
2020-01-20 20:57:01 +00:00
|
|
|
test('the job run button is disabled when the token lacks permission', async function(assert) {
|
|
|
|
window.localStorage.nomadTokenSecret = clientToken.secretId;
|
|
|
|
await JobsList.visit();
|
|
|
|
|
|
|
|
assert.ok(JobsList.runJobButton.isDisabled);
|
|
|
|
|
|
|
|
await JobsList.runJobButton.click();
|
|
|
|
assert.equal(currentURL(), '/jobs');
|
|
|
|
});
|
|
|
|
|
|
|
|
test('the job run button state can change between namespaces', async function(assert) {
|
|
|
|
server.createList('namespace', 2);
|
|
|
|
const job1 = server.create('job', { namespaceId: server.db.namespaces[0].id });
|
|
|
|
const job2 = server.create('job', { namespaceId: server.db.namespaces[1].id });
|
|
|
|
|
|
|
|
window.localStorage.nomadTokenSecret = clientToken.secretId;
|
|
|
|
|
|
|
|
const policy = server.create('policy', {
|
|
|
|
id: 'something',
|
|
|
|
name: 'something',
|
|
|
|
rulesJSON: {
|
|
|
|
Namespaces: [
|
|
|
|
{
|
|
|
|
Name: job1.namespaceId,
|
|
|
|
Capabilities: ['list-jobs', 'submit-job'],
|
|
|
|
},
|
|
|
|
{
|
|
|
|
Name: job2.namespaceId,
|
|
|
|
Capabilities: ['list-jobs'],
|
|
|
|
},
|
|
|
|
],
|
|
|
|
},
|
|
|
|
});
|
|
|
|
|
|
|
|
clientToken.policyIds = [policy.id];
|
|
|
|
clientToken.save();
|
|
|
|
|
|
|
|
await JobsList.visit();
|
|
|
|
assert.notOk(JobsList.runJobButton.isDisabled);
|
|
|
|
|
|
|
|
const secondNamespace = server.db.namespaces[1];
|
|
|
|
await JobsList.visit({ namespace: secondNamespace.id });
|
|
|
|
assert.ok(JobsList.runJobButton.isDisabled);
|
|
|
|
});
|
|
|
|
|
|
|
|
test('the anonymous policy is fetched to check whether to show the job run button', async function(assert) {
|
|
|
|
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);
|
|
|
|
});
|
|
|
|
|
2019-03-14 06:44:53 +00:00
|
|
|
test('when there are no jobs, there is an empty message', async function(assert) {
|
|
|
|
await JobsList.visit();
|
2017-09-30 00:41:12 +00:00
|
|
|
|
2018-07-11 01:42:19 +00:00
|
|
|
assert.ok(JobsList.isEmpty, 'There is an empty message');
|
|
|
|
assert.equal(JobsList.emptyState.headline, 'No Jobs', 'The message is appropriate');
|
2017-09-30 00:41:12 +00:00
|
|
|
});
|
|
|
|
|
2019-03-14 06:44:53 +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
|
|
|
|
2019-03-14 06:44:53 +00:00
|
|
|
await JobsList.search('dog');
|
2018-07-11 01:42:19 +00:00
|
|
|
assert.ok(JobsList.isEmpty, 'The empty message is shown');
|
|
|
|
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
|
|
|
|
2019-03-14 06:44:53 +00:00
|
|
|
test('searching resets the current page', async function(assert) {
|
2019-03-13 00:04:16 +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();
|
|
|
|
|
2018-10-30 21:17:23 +00:00
|
|
|
assert.equal(currentURL(), '/jobs?page=2', 'Page query param captures page=2');
|
2019-03-14 06:44:53 +00:00
|
|
|
|
|
|
|
await JobsList.search('foobar');
|
|
|
|
|
2018-10-30 21:17:23 +00:00
|
|
|
assert.equal(currentURL(), '/jobs?search=foobar', 'No page query param');
|
|
|
|
});
|
|
|
|
|
2019-03-14 06:44:53 +00:00
|
|
|
test('when the namespace query param is set, only matching jobs are shown and the namespace value is forwarded to app state', async function(assert) {
|
2019-03-13 00:04:16 +00:00
|
|
|
server.createList('namespace', 2);
|
|
|
|
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();
|
2017-10-11 20:44:27 +00:00
|
|
|
|
2018-07-11 01:42:19 +00:00
|
|
|
assert.equal(JobsList.jobs.length, 1, 'One job in the default namespace');
|
|
|
|
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
|
|
|
|
2018-07-11 01:42:19 +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
|
|
|
|
2019-03-14 06:44:53 +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) {
|
|
|
|
return job.periodic ? 'periodic' : job.parameterized ? 'parameterized' : job.type;
|
|
|
|
}
|
2019-01-24 04:35:51 +00:00
|
|
|
|
2019-03-14 06:44:53 +00:00
|
|
|
test('the jobs list page has appropriate faceted search options', async function(assert) {
|
|
|
|
await JobsList.visit();
|
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');
|
|
|
|
});
|
|
|
|
|
2019-03-13 00:04:16 +00:00
|
|
|
testFacet('Type', {
|
|
|
|
facet: JobsList.facets.type,
|
|
|
|
paramName: 'type',
|
|
|
|
expectedOptions: ['Batch', 'Parameterized', 'Periodic', 'Service', 'System'],
|
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,
|
|
|
|
});
|
|
|
|
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,
|
|
|
|
});
|
2019-03-13 00:04:16 +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,
|
|
|
|
});
|
|
|
|
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
|
|
|
},
|
|
|
|
filter: (job, selection) => job.datacenters.find(dc => selection.includes(dc)),
|
|
|
|
});
|
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',
|
|
|
|
].forEach(name => {
|
|
|
|
server.create('job', { name, 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.find(prefix => job.name.startsWith(prefix)),
|
|
|
|
});
|
2019-01-24 04:35:51 +00:00
|
|
|
|
2019-03-14 06:44:53 +00:00
|
|
|
test('when the facet selections result in no matches, the empty state states why', async function(assert) {
|
2019-03-13 00:04:16 +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');
|
|
|
|
assert.equal(JobsList.emptyState.headline, 'No Matches', 'The message is appropriate');
|
|
|
|
});
|
|
|
|
|
2019-03-14 06:44:53 +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
|
|
|
|
|
|
|
assert.equal(JobsList.jobs.length, 1, 'Only one job shown due to query param');
|
|
|
|
});
|
|
|
|
|
2019-03-13 00:04:16 +00:00
|
|
|
function testFacet(label, { facet, paramName, beforeEach, filter, expectedOptions }) {
|
2019-03-14 06:44:53 +00:00
|
|
|
test(`the ${label} facet has the correct options`, async function(assert) {
|
|
|
|
await beforeEach();
|
|
|
|
await facet.toggle();
|
|
|
|
|
|
|
|
let expectation;
|
|
|
|
if (typeof expectedOptions === 'function') {
|
|
|
|
expectation = expectedOptions(server.db.jobs);
|
|
|
|
} else {
|
|
|
|
expectation = expectedOptions;
|
|
|
|
}
|
|
|
|
|
|
|
|
assert.deepEqual(
|
|
|
|
facet.options.map(option => option.label.trim()),
|
|
|
|
expectation,
|
|
|
|
'Options for facet are as expected'
|
|
|
|
);
|
2019-01-24 04:35:51 +00:00
|
|
|
});
|
|
|
|
|
2019-03-14 06:44:53 +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
|
|
|
|
.filter(job => filter(job, selection))
|
|
|
|
.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
|
|
|
});
|
|
|
|
});
|
|
|
|
|
2019-03-14 06:44:53 +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
|
|
|
|
.filter(job => filter(job, selection))
|
|
|
|
.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
|
|
|
});
|
|
|
|
});
|
|
|
|
|
2019-03-14 06:44:53 +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
|
|
|
|
2019-03-14 06:44:53 +00:00
|
|
|
assert.equal(
|
|
|
|
currentURL(),
|
|
|
|
`/jobs?${paramName}=${encodeURIComponent(JSON.stringify(selection))}`,
|
|
|
|
'URL has the correct query param key and value'
|
|
|
|
);
|
2019-01-24 04:35:51 +00:00
|
|
|
});
|
2019-03-13 00:04:16 +00:00
|
|
|
}
|
|
|
|
});
|