-
+
{{#if this.sortedAllocations}}
{{/if}}
-
+
\ No newline at end of file
diff --git a/ui/tests/acceptance/job-allocations-test.js b/ui/tests/acceptance/job-allocations-test.js
index 7c86653c339..73fcc7207ed 100644
--- a/ui/tests/acceptance/job-allocations-test.js
+++ b/ui/tests/acceptance/job-allocations-test.js
@@ -124,4 +124,151 @@ module('Acceptance | job allocations', function(hooks) {
assert.ok(Allocations.error.isPresent, 'Error message is shown');
assert.equal(Allocations.error.title, 'Not Found', 'Error message is for 404');
});
+
+ testFacet('Status', {
+ facet: Allocations.facets.status,
+ paramName: 'status',
+ expectedOptions: ['Pending', 'Running', 'Complete', 'Failed', 'Lost'],
+ async beforeEach() {
+ ['pending', 'running', 'complete', 'failed', 'lost'].forEach(s => {
+ server.createList('allocation', 5, { clientStatus: s });
+ });
+ await Allocations.visit({ id: job.id });
+ },
+ filter: (alloc, selection) => alloc.jobId == job.id && selection.includes(alloc.clientStatus),
+ });
+
+ testFacet('Client', {
+ facet: Allocations.facets.client,
+ paramName: 'client',
+ expectedOptions(allocs) {
+ return Array.from(
+ new Set(
+ allocs
+ .filter(alloc => alloc.jobId == job.id)
+ .mapBy('nodeId')
+ .map(id => id.split('-')[0])
+ )
+ ).sort();
+ },
+ async beforeEach() {
+ server.createList('node', 5);
+ server.createList('allocation', 20);
+
+ await Allocations.visit({ id: job.id });
+ },
+ filter: (alloc, selection) =>
+ alloc.jobId == job.id && selection.includes(alloc.nodeId.split('-')[0]),
+ });
+
+ testFacet('Task Group', {
+ facet: Allocations.facets.taskGroup,
+ paramName: 'taskGroup',
+ expectedOptions(allocs) {
+ return Array.from(
+ new Set(allocs.filter(alloc => alloc.jobId == job.id).mapBy('taskGroup'))
+ ).sort();
+ },
+ async beforeEach() {
+ job = server.create('job', {
+ type: 'service',
+ status: 'running',
+ groupsCount: 5,
+ });
+
+ await Allocations.visit({ id: job.id });
+ },
+ filter: (alloc, selection) => alloc.jobId == job.id && selection.includes(alloc.taskGroup),
+ });
});
+
+function testFacet(label, { facet, paramName, beforeEach, filter, expectedOptions }) {
+ test(`facet ${label} | 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.allocations);
+ } else {
+ expectation = expectedOptions;
+ }
+
+ assert.deepEqual(
+ facet.options.map(option => option.label.trim()),
+ expectation,
+ 'Options for facet are as expected'
+ );
+ });
+
+ test(`facet ${label} | the ${label} facet filters the allocations list by ${label}`, async function(assert) {
+ let option;
+
+ await beforeEach();
+
+ await facet.toggle();
+ option = facet.options.objectAt(0);
+ await option.toggle();
+
+ const selection = [option.key];
+ const expectedAllocs = server.db.allocations
+ .filter(alloc => filter(alloc, selection))
+ .sortBy('modifyIndex')
+ .reverse();
+
+ Allocations.allocations.forEach((alloc, index) => {
+ assert.equal(
+ alloc.id,
+ expectedAllocs[index].id,
+ `Allocation at ${index} is ${expectedAllocs[index].id}`
+ );
+ });
+ });
+
+ test(`facet ${label} | selecting multiple options in the ${label} facet results in a broader search`, async function(assert) {
+ const selection = [];
+
+ 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);
+
+ const expectedAllocs = server.db.allocations
+ .filter(alloc => filter(alloc, selection))
+ .sortBy('modifyIndex')
+ .reverse();
+
+ Allocations.allocations.forEach((alloc, index) => {
+ assert.equal(
+ alloc.id,
+ expectedAllocs[index].id,
+ `Allocation at ${index} is ${expectedAllocs[index].id}`
+ );
+ });
+ });
+
+ test(`facet ${label} | selecting options in the ${label} facet updates the ${paramName} query param`, async function(assert) {
+ const selection = [];
+
+ 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(),
+ `/jobs/${job.id}/allocations?${paramName}=${encodeURIComponent(JSON.stringify(selection))}`,
+ 'URL has the correct query param key and value'
+ );
+ });
+}
diff --git a/ui/tests/pages/jobs/job/allocations.js b/ui/tests/pages/jobs/job/allocations.js
index adb48aa704e..8b15cb932cb 100644
--- a/ui/tests/pages/jobs/job/allocations.js
+++ b/ui/tests/pages/jobs/job/allocations.js
@@ -11,6 +11,7 @@ import {
import allocations from 'nomad-ui/tests/pages/components/allocations';
import error from 'nomad-ui/tests/pages/components/error';
+import { multiFacet } from 'nomad-ui/tests/pages/components/facet';
export default create({
visit: visitable('/jobs/:id/allocations'),
@@ -22,6 +23,12 @@ export default create({
...allocations(),
+ facets: {
+ status: multiFacet('[data-test-allocation-status-facet]'),
+ client: multiFacet('[data-test-allocation-client-facet]'),
+ taskGroup: multiFacet('[data-test-allocation-task-group-facet]'),
+ },
+
isEmpty: isPresent('[data-test-empty-allocations-list]'),
emptyState: {
headline: text('[data-test-empty-allocations-list-headline]'),