UI: Fix client sorting (#6817)
There are two changes here, and some caveats/commentary:
1. The “State“ table column was actually sorting only by status. The state was not an actual property, just something calculated in each client row, as a product of status, isEligible, and isDraining. This PR adds isDraining as a component of compositeState so it can be used for sorting.
2. The Sortable mixin declares dependent keys that cause the sort to be live-updating, but only if the members of the array change, such as if a new client is added, but not if any of the sortable properties change. This PR adds a SortableFactory function that generates a mixin whose listSorted computed property includes dependent keys for the sortable properties, so the table will live-update if any of the sortable properties change, not just the array members. There’s a warning if you use SortableFactory without dependent keys and via the original Sortable interface, so we can eventually migrate away from it.
2019-12-12 19:06:54 +00:00
|
|
|
import { currentURL, settled } 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-04-01 00:13:44 +00:00
|
|
|
import pageSizeSelect from './behaviors/page-size-select';
|
2018-07-10 08:11:27 +00:00
|
|
|
import ClientsList from 'nomad-ui/tests/pages/clients/list';
|
2017-09-19 14:47:10 +00:00
|
|
|
|
2019-03-13 00:04:16 +00:00
|
|
|
module('Acceptance | clients list', function(hooks) {
|
|
|
|
setupApplicationTest(hooks);
|
2019-03-13 01:09:19 +00:00
|
|
|
setupMirage(hooks);
|
2017-09-19 14:47:10 +00:00
|
|
|
|
2020-04-01 00:13:44 +00:00
|
|
|
hooks.beforeEach(function() {
|
|
|
|
window.localStorage.clear();
|
|
|
|
});
|
|
|
|
|
2019-03-14 06:44:53 +00:00
|
|
|
test('/clients should list one page of clients', async function(assert) {
|
2019-03-13 00:04:16 +00:00
|
|
|
// Make sure to make more nodes than 1 page to assert that pagination is working
|
2020-04-01 00:13:44 +00:00
|
|
|
const nodesCount = ClientsList.pageSize + 1;
|
2017-09-19 14:47:10 +00:00
|
|
|
|
2019-03-13 00:04:16 +00:00
|
|
|
server.createList('node', nodesCount);
|
|
|
|
server.createList('agent', 1);
|
2017-09-19 14:47:10 +00:00
|
|
|
|
2019-03-14 06:44:53 +00:00
|
|
|
await ClientsList.visit();
|
2017-09-19 14:47:10 +00:00
|
|
|
|
2020-04-01 00:13:44 +00:00
|
|
|
assert.equal(ClientsList.nodes.length, ClientsList.pageSize);
|
2018-07-10 08:11:27 +00:00
|
|
|
assert.ok(ClientsList.hasPagination, 'Pagination found on the page');
|
2017-09-19 14:47:10 +00:00
|
|
|
|
|
|
|
const sortedNodes = server.db.nodes.sortBy('modifyIndex').reverse();
|
|
|
|
|
2018-07-10 08:11:27 +00:00
|
|
|
ClientsList.nodes.forEach((node, index) => {
|
|
|
|
assert.equal(node.id, sortedNodes[index].id.split('-')[0], 'Clients are ordered');
|
|
|
|
});
|
2019-07-17 20:02:58 +00:00
|
|
|
|
|
|
|
assert.equal(document.title, 'Clients - Nomad');
|
2017-09-19 14:47:10 +00:00
|
|
|
});
|
|
|
|
|
2019-03-14 06:44:53 +00:00
|
|
|
test('each client record should show high-level info of the client', async function(assert) {
|
2019-06-19 17:11:17 +00:00
|
|
|
const node = server.create('node', 'draining');
|
|
|
|
server.createList('agent', 1);
|
2017-09-19 14:47:10 +00:00
|
|
|
|
2019-03-14 06:44:53 +00:00
|
|
|
await ClientsList.visit();
|
2017-09-19 14:47:10 +00:00
|
|
|
|
2018-07-10 08:11:27 +00:00
|
|
|
const nodeRow = ClientsList.nodes.objectAt(0);
|
2017-09-19 14:47:10 +00:00
|
|
|
const allocations = server.db.allocations.where({ nodeId: node.id });
|
|
|
|
|
2018-07-10 08:11:27 +00:00
|
|
|
assert.equal(nodeRow.id, node.id.split('-')[0], 'ID');
|
|
|
|
assert.equal(nodeRow.name, node.name, 'Name');
|
UI: Fix client sorting (#6817)
There are two changes here, and some caveats/commentary:
1. The “State“ table column was actually sorting only by status. The state was not an actual property, just something calculated in each client row, as a product of status, isEligible, and isDraining. This PR adds isDraining as a component of compositeState so it can be used for sorting.
2. The Sortable mixin declares dependent keys that cause the sort to be live-updating, but only if the members of the array change, such as if a new client is added, but not if any of the sortable properties change. This PR adds a SortableFactory function that generates a mixin whose listSorted computed property includes dependent keys for the sortable properties, so the table will live-update if any of the sortable properties change, not just the array members. There’s a warning if you use SortableFactory without dependent keys and via the original Sortable interface, so we can eventually migrate away from it.
2019-12-12 19:06:54 +00:00
|
|
|
assert.equal(
|
|
|
|
nodeRow.compositeStatus.text,
|
|
|
|
'draining',
|
|
|
|
'Combined status, draining, and eligbility'
|
|
|
|
);
|
2018-07-10 08:11:27 +00:00
|
|
|
assert.equal(nodeRow.address, node.httpAddr);
|
|
|
|
assert.equal(nodeRow.datacenter, node.datacenter, 'Datacenter');
|
|
|
|
assert.equal(nodeRow.allocations, allocations.length, '# Allocations');
|
2017-09-19 14:47:10 +00:00
|
|
|
});
|
|
|
|
|
2020-05-11 16:28:31 +00:00
|
|
|
test('each client record should show running allocations', async function(assert) {
|
|
|
|
server.createList('agent', 1);
|
|
|
|
|
|
|
|
const node = server.create('node', {
|
|
|
|
modifyIndex: 4,
|
|
|
|
status: 'ready',
|
|
|
|
schedulingEligibility: 'eligible',
|
|
|
|
drain: false,
|
|
|
|
});
|
|
|
|
|
|
|
|
server.create('job', { createAllocations: false });
|
|
|
|
|
|
|
|
const running = server.createList('allocation', 2, { clientStatus: 'running' });
|
|
|
|
server.createList('allocation', 3, { clientStatus: 'pending' });
|
|
|
|
server.createList('allocation', 10, { clientStatus: 'complete' });
|
|
|
|
|
|
|
|
await ClientsList.visit();
|
|
|
|
|
|
|
|
const nodeRow = ClientsList.nodes.objectAt(0);
|
|
|
|
|
|
|
|
assert.equal(nodeRow.id, node.id.split('-')[0], 'ID');
|
|
|
|
assert.equal(
|
|
|
|
nodeRow.compositeStatus.text,
|
|
|
|
'ready',
|
|
|
|
'Combined status, draining, and eligbility'
|
|
|
|
);
|
|
|
|
assert.equal(nodeRow.allocations, running.length, '# Allocations');
|
|
|
|
});
|
|
|
|
|
UI: Fix client sorting (#6817)
There are two changes here, and some caveats/commentary:
1. The “State“ table column was actually sorting only by status. The state was not an actual property, just something calculated in each client row, as a product of status, isEligible, and isDraining. This PR adds isDraining as a component of compositeState so it can be used for sorting.
2. The Sortable mixin declares dependent keys that cause the sort to be live-updating, but only if the members of the array change, such as if a new client is added, but not if any of the sortable properties change. This PR adds a SortableFactory function that generates a mixin whose listSorted computed property includes dependent keys for the sortable properties, so the table will live-update if any of the sortable properties change, not just the array members. There’s a warning if you use SortableFactory without dependent keys and via the original Sortable interface, so we can eventually migrate away from it.
2019-12-12 19:06:54 +00:00
|
|
|
test('client status, draining, and eligibility are collapsed into one column that stays sorted', async function(assert) {
|
2019-06-19 17:11:17 +00:00
|
|
|
server.createList('agent', 1);
|
|
|
|
|
|
|
|
server.create('node', {
|
|
|
|
modifyIndex: 4,
|
|
|
|
status: 'ready',
|
|
|
|
schedulingEligibility: 'eligible',
|
|
|
|
drain: false,
|
|
|
|
});
|
|
|
|
server.create('node', {
|
|
|
|
modifyIndex: 3,
|
|
|
|
status: 'initializing',
|
|
|
|
schedulingEligibility: 'eligible',
|
|
|
|
drain: false,
|
|
|
|
});
|
|
|
|
server.create('node', {
|
|
|
|
modifyIndex: 2,
|
|
|
|
status: 'down',
|
|
|
|
schedulingEligibility: 'eligible',
|
|
|
|
drain: false,
|
|
|
|
});
|
|
|
|
server.create('node', {
|
|
|
|
modifyIndex: 1,
|
|
|
|
status: 'ready',
|
|
|
|
schedulingEligibility: 'ineligible',
|
|
|
|
drain: false,
|
|
|
|
});
|
|
|
|
server.create('node', 'draining', {
|
|
|
|
modifyIndex: 0,
|
|
|
|
status: 'ready',
|
|
|
|
});
|
|
|
|
|
|
|
|
await ClientsList.visit();
|
|
|
|
|
UI: Fix client sorting (#6817)
There are two changes here, and some caveats/commentary:
1. The “State“ table column was actually sorting only by status. The state was not an actual property, just something calculated in each client row, as a product of status, isEligible, and isDraining. This PR adds isDraining as a component of compositeState so it can be used for sorting.
2. The Sortable mixin declares dependent keys that cause the sort to be live-updating, but only if the members of the array change, such as if a new client is added, but not if any of the sortable properties change. This PR adds a SortableFactory function that generates a mixin whose listSorted computed property includes dependent keys for the sortable properties, so the table will live-update if any of the sortable properties change, not just the array members. There’s a warning if you use SortableFactory without dependent keys and via the original Sortable interface, so we can eventually migrate away from it.
2019-12-12 19:06:54 +00:00
|
|
|
ClientsList.nodes[0].compositeStatus.as(readyClient => {
|
2019-06-19 17:11:17 +00:00
|
|
|
assert.equal(readyClient.text, 'ready');
|
|
|
|
assert.ok(readyClient.isUnformatted, 'expected no status class');
|
|
|
|
assert.equal(readyClient.tooltip, 'ready / not draining / eligible');
|
|
|
|
});
|
|
|
|
|
UI: Fix client sorting (#6817)
There are two changes here, and some caveats/commentary:
1. The “State“ table column was actually sorting only by status. The state was not an actual property, just something calculated in each client row, as a product of status, isEligible, and isDraining. This PR adds isDraining as a component of compositeState so it can be used for sorting.
2. The Sortable mixin declares dependent keys that cause the sort to be live-updating, but only if the members of the array change, such as if a new client is added, but not if any of the sortable properties change. This PR adds a SortableFactory function that generates a mixin whose listSorted computed property includes dependent keys for the sortable properties, so the table will live-update if any of the sortable properties change, not just the array members. There’s a warning if you use SortableFactory without dependent keys and via the original Sortable interface, so we can eventually migrate away from it.
2019-12-12 19:06:54 +00:00
|
|
|
assert.equal(ClientsList.nodes[1].compositeStatus.text, 'initializing');
|
|
|
|
assert.equal(ClientsList.nodes[2].compositeStatus.text, 'down');
|
|
|
|
|
|
|
|
assert.equal(ClientsList.nodes[3].compositeStatus.text, 'ineligible');
|
|
|
|
assert.ok(ClientsList.nodes[3].compositeStatus.isWarning, 'expected warning class');
|
|
|
|
|
|
|
|
assert.equal(ClientsList.nodes[4].compositeStatus.text, 'draining');
|
|
|
|
assert.ok(ClientsList.nodes[4].compositeStatus.isInfo, 'expected info class');
|
|
|
|
|
|
|
|
await ClientsList.sortBy('compositeStatus');
|
|
|
|
|
|
|
|
assert.deepEqual(ClientsList.nodes.mapBy('compositeStatus.text'), [
|
|
|
|
'ready',
|
|
|
|
'initializing',
|
|
|
|
'ineligible',
|
|
|
|
'draining',
|
|
|
|
'down',
|
|
|
|
]);
|
|
|
|
|
|
|
|
// Simulate a client state change arriving through polling
|
|
|
|
let readyClient = this.owner
|
|
|
|
.lookup('service:store')
|
|
|
|
.peekAll('node')
|
|
|
|
.findBy('modifyIndex', 4);
|
|
|
|
readyClient.set('schedulingEligibility', 'ineligible');
|
|
|
|
|
|
|
|
await settled();
|
|
|
|
|
|
|
|
assert.deepEqual(ClientsList.nodes.mapBy('compositeStatus.text'), [
|
|
|
|
'initializing',
|
|
|
|
'ineligible',
|
|
|
|
'ineligible',
|
|
|
|
'draining',
|
|
|
|
'down',
|
|
|
|
]);
|
2019-06-19 17:11:17 +00:00
|
|
|
});
|
|
|
|
|
2019-03-14 06:44:53 +00:00
|
|
|
test('each client should link to the client detail page', async function(assert) {
|
2019-06-19 17:11:17 +00:00
|
|
|
server.createList('node', 1);
|
|
|
|
server.createList('agent', 1);
|
|
|
|
|
2019-03-13 00:04:16 +00:00
|
|
|
const node = server.db.nodes[0];
|
2017-09-19 14:47:10 +00:00
|
|
|
|
2019-03-14 06:44:53 +00:00
|
|
|
await ClientsList.visit();
|
|
|
|
await ClientsList.nodes.objectAt(0).clickRow();
|
2017-09-19 14:47:10 +00:00
|
|
|
|
2017-10-28 01:23:41 +00:00
|
|
|
assert.equal(currentURL(), `/clients/${node.id}`);
|
2017-09-19 14:47:10 +00:00
|
|
|
});
|
|
|
|
|
2019-03-14 06:44:53 +00:00
|
|
|
test('when there are no clients, there is an empty message', async function(assert) {
|
2019-03-13 00:04:16 +00:00
|
|
|
server.createList('agent', 1);
|
2017-09-30 01:33:57 +00:00
|
|
|
|
2019-03-14 06:44:53 +00:00
|
|
|
await ClientsList.visit();
|
2017-09-30 01:33:57 +00:00
|
|
|
|
2018-07-10 08:11:27 +00:00
|
|
|
assert.ok(ClientsList.isEmpty);
|
|
|
|
assert.equal(ClientsList.empty.headline, 'No Clients');
|
2017-09-30 01:33:57 +00:00
|
|
|
});
|
|
|
|
|
2019-03-14 06:44:53 +00:00
|
|
|
test('when there are clients, but no matches for a search term, there is an empty message', async function(assert) {
|
2019-03-13 00:04:16 +00:00
|
|
|
server.createList('agent', 1);
|
|
|
|
server.create('node', { name: 'node' });
|
2017-09-30 01:33:57 +00:00
|
|
|
|
2019-03-14 06:44:53 +00:00
|
|
|
await ClientsList.visit();
|
2017-09-30 01:33:57 +00:00
|
|
|
|
2019-03-14 06:44:53 +00:00
|
|
|
await ClientsList.search('client');
|
2018-07-10 08:11:27 +00:00
|
|
|
assert.ok(ClientsList.isEmpty);
|
|
|
|
assert.equal(ClientsList.empty.headline, 'No Matches');
|
2017-09-30 01:33:57 +00:00
|
|
|
});
|
|
|
|
|
2019-03-14 06:44:53 +00:00
|
|
|
test('when accessing clients is forbidden, show a message with a link to the tokens page', async function(assert) {
|
2019-03-13 00:04:16 +00:00
|
|
|
server.create('agent');
|
|
|
|
server.create('node', { name: 'node' });
|
|
|
|
server.pretender.get('/v1/nodes', () => [403, {}, null]);
|
2017-10-24 23:08:01 +00:00
|
|
|
|
2019-03-14 06:44:53 +00:00
|
|
|
await ClientsList.visit();
|
2017-10-24 23:08:01 +00:00
|
|
|
|
2018-07-10 08:11:27 +00:00
|
|
|
assert.equal(ClientsList.error.title, 'Not Authorized');
|
2017-10-24 23:08:01 +00:00
|
|
|
|
2019-03-14 06:44:53 +00:00
|
|
|
await ClientsList.error.seekHelp();
|
2017-10-24 23:08:01 +00:00
|
|
|
|
|
|
|
assert.equal(currentURL(), '/settings/tokens');
|
|
|
|
});
|
2019-02-12 19:26:36 +00:00
|
|
|
|
2020-04-01 00:13:44 +00:00
|
|
|
pageSizeSelect({
|
|
|
|
resourceName: 'client',
|
|
|
|
pageObject: ClientsList,
|
|
|
|
pageObjectList: ClientsList.nodes,
|
|
|
|
async setup() {
|
|
|
|
server.createList('node', ClientsList.pageSize);
|
|
|
|
server.createList('agent', 1);
|
|
|
|
await ClientsList.visit();
|
|
|
|
},
|
|
|
|
});
|
|
|
|
|
2019-03-13 00:04:16 +00:00
|
|
|
testFacet('Class', {
|
|
|
|
facet: ClientsList.facets.class,
|
|
|
|
paramName: 'class',
|
|
|
|
expectedOptions(nodes) {
|
|
|
|
return Array.from(new Set(nodes.mapBy('nodeClass'))).sort();
|
|
|
|
},
|
2019-03-14 06:44:53 +00:00
|
|
|
async beforeEach() {
|
2019-03-13 00:04:16 +00:00
|
|
|
server.create('agent');
|
|
|
|
server.createList('node', 2, { nodeClass: 'nc-one' });
|
|
|
|
server.createList('node', 2, { nodeClass: 'nc-two' });
|
|
|
|
server.createList('node', 2, { nodeClass: 'nc-three' });
|
2019-03-14 06:44:53 +00:00
|
|
|
await ClientsList.visit();
|
2019-03-13 00:04:16 +00:00
|
|
|
},
|
|
|
|
filter: (node, selection) => selection.includes(node.nodeClass),
|
|
|
|
});
|
2019-02-12 19:26:36 +00:00
|
|
|
|
2019-06-19 17:11:17 +00:00
|
|
|
testFacet('State', {
|
|
|
|
facet: ClientsList.facets.state,
|
|
|
|
paramName: 'state',
|
|
|
|
expectedOptions: ['Initializing', 'Ready', 'Down', 'Ineligible', 'Draining'],
|
2019-03-14 06:44:53 +00:00
|
|
|
async beforeEach() {
|
2019-03-13 00:04:16 +00:00
|
|
|
server.create('agent');
|
2019-06-19 17:11:17 +00:00
|
|
|
|
2019-03-13 00:04:16 +00:00
|
|
|
server.createList('node', 2, { status: 'initializing' });
|
|
|
|
server.createList('node', 2, { status: 'ready' });
|
|
|
|
server.createList('node', 2, { status: 'down' });
|
2019-06-19 17:11:17 +00:00
|
|
|
|
|
|
|
server.createList('node', 2, { schedulingEligibility: 'eligible', drain: false });
|
|
|
|
server.createList('node', 2, { schedulingEligibility: 'ineligible', drain: false });
|
|
|
|
server.createList('node', 2, { schedulingEligibility: 'ineligible', drain: true });
|
|
|
|
|
2019-03-14 06:44:53 +00:00
|
|
|
await ClientsList.visit();
|
2019-03-13 00:04:16 +00:00
|
|
|
},
|
2019-06-19 17:11:17 +00:00
|
|
|
filter: (node, selection) => {
|
|
|
|
if (selection.includes('draining') && !node.drain) return false;
|
|
|
|
if (selection.includes('ineligible') && node.schedulingEligibility === 'eligible')
|
|
|
|
return false;
|
|
|
|
|
|
|
|
return selection.includes(node.status);
|
|
|
|
},
|
2019-03-13 00:04:16 +00:00
|
|
|
});
|
2019-02-12 19:26:36 +00:00
|
|
|
|
2019-03-13 00:04:16 +00:00
|
|
|
testFacet('Datacenters', {
|
|
|
|
facet: ClientsList.facets.datacenter,
|
|
|
|
paramName: 'dc',
|
|
|
|
expectedOptions(nodes) {
|
|
|
|
return Array.from(new Set(nodes.mapBy('datacenter'))).sort();
|
|
|
|
},
|
2019-03-14 06:44:53 +00:00
|
|
|
async beforeEach() {
|
2019-03-13 00:04:16 +00:00
|
|
|
server.create('agent');
|
|
|
|
server.createList('node', 2, { datacenter: 'pdx-1' });
|
|
|
|
server.createList('node', 2, { datacenter: 'nyc-1' });
|
|
|
|
server.createList('node', 2, { datacenter: 'ams-1' });
|
2019-03-14 06:44:53 +00:00
|
|
|
await ClientsList.visit();
|
2019-03-13 00:04:16 +00:00
|
|
|
},
|
|
|
|
filter: (node, selection) => selection.includes(node.datacenter),
|
|
|
|
});
|
2019-02-12 19:26:36 +00:00
|
|
|
|
2020-03-13 18:31:06 +00:00
|
|
|
testFacet('Volumes', {
|
|
|
|
facet: ClientsList.facets.volume,
|
|
|
|
paramName: 'volume',
|
|
|
|
expectedOptions(nodes) {
|
|
|
|
const flatten = (acc, val) => acc.concat(Object.keys(val));
|
|
|
|
return Array.from(new Set(nodes.mapBy('hostVolumes').reduce(flatten, [])));
|
|
|
|
},
|
|
|
|
async beforeEach() {
|
|
|
|
server.create('agent');
|
|
|
|
server.createList('node', 2, { hostVolumes: { One: { Name: 'One' } } });
|
|
|
|
server.createList('node', 2, { hostVolumes: { One: { Name: 'One' }, Two: { Name: 'Two' } } });
|
|
|
|
server.createList('node', 2, { hostVolumes: { Two: { Name: 'Two' } } });
|
|
|
|
await ClientsList.visit();
|
|
|
|
},
|
|
|
|
filter: (node, selection) =>
|
|
|
|
Object.keys(node.hostVolumes).find(volume => selection.includes(volume)),
|
|
|
|
});
|
|
|
|
|
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.create('agent');
|
|
|
|
server.createList('node', 2, { status: 'ready' });
|
2019-02-12 19:26:36 +00:00
|
|
|
|
2019-03-14 06:44:53 +00:00
|
|
|
await ClientsList.visit();
|
2019-02-12 19:26:36 +00:00
|
|
|
|
2019-06-19 17:11:17 +00:00
|
|
|
await ClientsList.facets.state.toggle();
|
|
|
|
await ClientsList.facets.state.options.objectAt(0).toggle();
|
2019-02-12 19:26:36 +00:00
|
|
|
assert.ok(ClientsList.isEmpty, 'There is an empty message');
|
|
|
|
assert.equal(ClientsList.empty.headline, 'No Matches', 'The message is appropriate');
|
|
|
|
});
|
|
|
|
|
2019-03-14 06:44:53 +00:00
|
|
|
test('the clients list is immediately filtered based on query params', async function(assert) {
|
2019-03-13 00:04:16 +00:00
|
|
|
server.create('agent');
|
|
|
|
server.create('node', { nodeClass: 'omg-large' });
|
|
|
|
server.create('node', { nodeClass: 'wtf-tiny' });
|
2019-02-12 19:26:36 +00:00
|
|
|
|
2019-03-14 06:44:53 +00:00
|
|
|
await ClientsList.visit({ class: JSON.stringify(['wtf-tiny']) });
|
2019-02-12 19:26:36 +00:00
|
|
|
|
|
|
|
assert.equal(ClientsList.nodes.length, 1, 'Only one client 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.nodes);
|
|
|
|
} else {
|
|
|
|
expectation = expectedOptions;
|
|
|
|
}
|
|
|
|
|
|
|
|
assert.deepEqual(
|
|
|
|
facet.options.map(option => option.label.trim()),
|
|
|
|
expectation,
|
|
|
|
'Options for facet are as expected'
|
|
|
|
);
|
2019-02-12 19:26:36 +00:00
|
|
|
});
|
|
|
|
|
2019-03-14 06:44:53 +00:00
|
|
|
test(`the ${label} facet filters the nodes list by ${label}`, async function(assert) {
|
2019-03-13 00:04:16 +00:00
|
|
|
let option;
|
2019-02-12 19:26:36 +00:00
|
|
|
|
2019-03-14 06:44:53 +00:00
|
|
|
await beforeEach();
|
2019-02-12 19:26:36 +00:00
|
|
|
|
2019-03-14 06:44:53 +00:00
|
|
|
await facet.toggle();
|
|
|
|
option = facet.options.objectAt(0);
|
|
|
|
await option.toggle();
|
2019-02-12 19:26:36 +00:00
|
|
|
|
2019-03-14 06:44:53 +00:00
|
|
|
const selection = [option.key];
|
|
|
|
const expectedNodes = server.db.nodes
|
|
|
|
.filter(node => filter(node, selection))
|
|
|
|
.sortBy('modifyIndex')
|
|
|
|
.reverse();
|
2019-02-12 19:26:36 +00:00
|
|
|
|
2019-03-14 06:44:53 +00:00
|
|
|
ClientsList.nodes.forEach((node, index) => {
|
|
|
|
assert.equal(
|
|
|
|
node.id,
|
|
|
|
expectedNodes[index].id.split('-')[0],
|
|
|
|
`Node at ${index} is ${expectedNodes[index].id}`
|
|
|
|
);
|
2019-02-12 19:26:36 +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-02-12 19:26:36 +00:00
|
|
|
|
2019-03-14 06:44:53 +00:00
|
|
|
await beforeEach();
|
|
|
|
await facet.toggle();
|
2019-02-12 19:26:36 +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-02-12 19:26:36 +00:00
|
|
|
|
2019-03-14 06:44:53 +00:00
|
|
|
const expectedNodes = server.db.nodes
|
|
|
|
.filter(node => filter(node, selection))
|
|
|
|
.sortBy('modifyIndex')
|
|
|
|
.reverse();
|
2019-02-12 19:26:36 +00:00
|
|
|
|
2019-03-14 06:44:53 +00:00
|
|
|
ClientsList.nodes.forEach((node, index) => {
|
|
|
|
assert.equal(
|
|
|
|
node.id,
|
|
|
|
expectedNodes[index].id.split('-')[0],
|
|
|
|
`Node at ${index} is ${expectedNodes[index].id}`
|
|
|
|
);
|
2019-02-12 19:26:36 +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-02-12 19:26:36 +00:00
|
|
|
|
2019-03-14 06:44:53 +00:00
|
|
|
await beforeEach();
|
|
|
|
await facet.toggle();
|
|
|
|
|
|
|
|
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);
|
|
|
|
|
|
|
|
assert.equal(
|
|
|
|
currentURL(),
|
|
|
|
`/clients?${paramName}=${encodeURIComponent(JSON.stringify(selection))}`,
|
|
|
|
'URL has the correct query param key and value'
|
|
|
|
);
|
2019-02-12 19:26:36 +00:00
|
|
|
});
|
2019-03-13 00:04:16 +00:00
|
|
|
}
|
|
|
|
});
|