Skip to content

Commit

Permalink
Test coverage for preemption on the client detail page
Browse files Browse the repository at this point in the history
  • Loading branch information
DingoEatingFuzz committed Apr 22, 2019
1 parent 5aa938e commit d092723
Show file tree
Hide file tree
Showing 3 changed files with 71 additions and 2 deletions.
4 changes: 2 additions & 2 deletions ui/app/templates/clients/client.hbs
Original file line number Diff line number Diff line change
Expand Up @@ -97,11 +97,11 @@
<div class="boxed-section-head">
<div>
Allocations
<button role="button" class="badge is-white" onclick={{action "setPreemptionFilter" false}}>
<button role="button" class="badge is-white" onclick={{action "setPreemptionFilter" false}} data-test-filter-all>
{{model.allocations.length}}
</button>
{{#if preemptions.length}}
<button role="button" class="badge is-warning" onclick={{action "setPreemptionFilter" true}}>
<button role="button" class="badge is-warning" onclick={{action "setPreemptionFilter" true}} data-test-filter-preemptions>
{{preemptions.length}} {{pluralize "preemption" preemptions.length}}
</button>
{{/if}}
Expand Down
62 changes: 62 additions & 0 deletions ui/tests/acceptance/client-detail-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,8 @@ import Jobs from 'nomad-ui/tests/pages/jobs/list';

let node;

const wasPreemptedFilter = allocation => !!allocation.preemptedByAllocation;

module('Acceptance | client detail', function(hooks) {
setupApplicationTest(hooks);
setupMirage(hooks);
Expand All @@ -24,6 +26,7 @@ module('Acceptance | client detail', function(hooks) {
server.create('agent');
server.create('job', { createAllocations: false });
server.createList('allocation', 3, { nodeId: node.id, clientStatus: 'running' });
server.create('allocation', 'preempted', { nodeId: node.id, clientStatus: 'running' });
});

test('/clients/:id should have a breadcrumb trail linking back to clients', async function(assert) {
Expand Down Expand Up @@ -219,6 +222,65 @@ module('Acceptance | client detail', function(hooks) {
);
});

test('the allocation section should show the count of preempted allocations on the client', async function(assert) {
const allocations = server.db.allocations.where({ nodeId: node.id });

await ClientDetail.visit({ id: node.id });

assert.equal(
ClientDetail.allocationFilter.allCount,
allocations.length,
'All filter/badge shows all allocations count'
);
assert.ok(
ClientDetail.allocationFilter.preemptionsCount.startsWith(
allocations.filter(wasPreemptedFilter).length
),
'Preemptions filter/badge shows preempted allocations count'
);
});

test('clicking the preemption badge filters the allocations table and sets a query param', async function(assert) {
const allocations = server.db.allocations.where({ nodeId: node.id });

await ClientDetail.visit({ id: node.id });
await ClientDetail.allocationFilter.preemptions();

assert.equal(
ClientDetail.allocations.length,
allocations.filter(wasPreemptedFilter).length,
'Only preempted allocations are shown'
);
assert.equal(
currentURL(),
`/clients/${node.id}?preemptions=true`,
'Filter is persisted in the URL'
);
});

test('clicking the total allocations badge resets the filter and removes the query param', async function(assert) {
const allocations = server.db.allocations.where({ nodeId: node.id });

await ClientDetail.visit({ id: node.id });
await ClientDetail.allocationFilter.preemptions();
await ClientDetail.allocationFilter.all();

assert.equal(ClientDetail.allocations.length, allocations.length, 'All allocations are shown');
assert.equal(currentURL(), `/clients/${node.id}`, 'Filter is persisted in the URL');
});

test('navigating directly to the client detail page with the preemption query param set will filter the allocations table', async function(assert) {
const allocations = server.db.allocations.where({ nodeId: node.id });

await ClientDetail.visit({ id: node.id, preemptions: true });

assert.equal(
ClientDetail.allocations.length,
allocations.filter(wasPreemptedFilter).length,
'Only preempted allocations are shown'
);
});

test('/clients/:id should list all attributes for the node', async function(assert) {
await ClientDetail.visit({ id: node.id });

Expand Down
7 changes: 7 additions & 0 deletions ui/tests/pages/clients/detail.js
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,13 @@ export default create({

...allocations(),

allocationFilter: {
preemptions: clickable('[data-test-filter-preemptions]'),
all: clickable('[data-test-filter-all]'),
preemptionsCount: text('[data-test-filter-preemptions]'),
allCount: text('[data-test-filter-all]'),
},

attributesTable: isPresent('[data-test-attributes]'),
metaTable: isPresent('[data-test-meta]'),
emptyMetaMessage: isPresent('[data-test-empty-meta-message]'),
Expand Down

0 comments on commit d092723

Please sign in to comment.