open-nomad/ui/tests/integration/components/job-page/parts/placement-failures-test.js

Ignoring revisions in .git-blame-ignore-revs. Click here to bypass and see the normal blame view.

101 lines
3.1 KiB
JavaScript
Raw Normal View History

/* eslint-disable qunit/require-expect */
/* Mirage fixtures are random so we can't expect a set number of assertions */
import hbs from 'htmlbars-inline-precompile';
import { findAll, find, render } from '@ember/test-helpers';
2019-03-13 00:04:16 +00:00
import { module, test } from 'qunit';
import { setupRenderingTest } from 'ember-qunit';
import { startMirage } from 'nomad-ui/initializers/ember-cli-mirage';
import { initialize as fragmentSerializerInitializer } from 'nomad-ui/initializers/fragment-serializer';
import { componentA11yAudit } from 'nomad-ui/tests/helpers/a11y-audit';
2021-12-28 16:08:12 +00:00
module(
'Integration | Component | job-page/parts/placement-failures',
function (hooks) {
setupRenderingTest(hooks);
hooks.beforeEach(function () {
fragmentSerializerInitializer(this.owner);
window.localStorage.clear();
this.store = this.owner.lookup('service:store');
this.server = startMirage();
this.server.create('namespace');
});
2021-12-28 16:08:12 +00:00
hooks.afterEach(function () {
this.server.shutdown();
window.localStorage.clear();
});
2019-03-13 00:04:16 +00:00
2021-12-28 16:08:12 +00:00
test('when the job has placement failures, they are called out', async function (assert) {
this.server.create('job', {
failedPlacements: true,
createAllocations: false,
});
await this.store.findAll('job');
2021-12-28 16:08:12 +00:00
const job = this.store.peekAll('job').get('firstObject');
await job.reload();
2021-12-28 16:08:12 +00:00
this.set('job', job);
2021-12-28 16:08:12 +00:00
await render(hbs`
<JobPage::Parts::PlacementFailures @job={{job}} />)
`);
2021-12-28 16:08:12 +00:00
const failedEvaluation = this.get('job.evaluations')
.filterBy('hasPlacementFailures')
.sortBy('modifyIndex')
.reverse()
.get('firstObject');
const failedTGAllocs = failedEvaluation.get('failedTGAllocs');
assert.ok(
2021-12-28 16:08:12 +00:00
find('[data-test-placement-failures]'),
'Placement failures section found'
);
2021-12-28 16:08:12 +00:00
const taskGroupLabels = findAll(
'[data-test-placement-failure-task-group]'
).map((title) => title.textContent.trim());
failedTGAllocs.forEach((alloc) => {
const name = alloc.get('name');
assert.ok(
taskGroupLabels.find((label) => label.includes(name)),
`${name} included in placement failures list`
);
assert.ok(
taskGroupLabels.find((label) =>
label.includes(alloc.get('coalescedFailures') + 1)
),
'The number of unplaced allocs = CoalescedFailures + 1'
);
});
await componentA11yAudit(this.element, assert);
});
2021-12-28 16:08:12 +00:00
test('when the job has no placement failures, the placement failures section is gone', async function (assert) {
this.server.create('job', {
noFailedPlacements: true,
createAllocations: false,
});
await this.store.findAll('job');
2021-12-28 16:08:12 +00:00
const job = this.store.peekAll('job').get('firstObject');
await job.reload();
2021-12-28 16:08:12 +00:00
this.set('job', job);
2021-12-28 16:08:12 +00:00
await render(hbs`
<JobPage::Parts::PlacementFailures @job={{job}} />)
`);
2021-12-28 16:08:12 +00:00
assert.notOk(
find('[data-test-placement-failures]'),
'Placement failures section not found'
);
});
}
);