2018-02-01 00:12:50 +00:00
|
|
|
import hbs from 'htmlbars-inline-precompile';
|
2019-07-23 19:40:32 +00:00
|
|
|
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';
|
2018-02-01 00:12:50 +00:00
|
|
|
import { startMirage } from 'nomad-ui/initializers/ember-cli-mirage';
|
|
|
|
import { initialize as fragmentSerializerInitializer } from 'nomad-ui/initializers/fragment-serializer';
|
2020-08-25 15:56:02 +00:00
|
|
|
import { componentA11yAudit } from 'nomad-ui/tests/helpers/a11y-audit';
|
2018-02-01 00:12:50 +00:00
|
|
|
|
2021-12-28 14:45:20 +00:00
|
|
|
module('Integration | Component | job-page/parts/placement-failures', function (hooks) {
|
2019-03-13 00:04:16 +00:00
|
|
|
setupRenderingTest(hooks);
|
2018-02-01 00:12:50 +00:00
|
|
|
|
2021-12-28 14:45:20 +00:00
|
|
|
hooks.beforeEach(function () {
|
2019-03-13 00:04:16 +00:00
|
|
|
fragmentSerializerInitializer(this.owner);
|
|
|
|
window.localStorage.clear();
|
|
|
|
this.store = this.owner.lookup('service:store');
|
|
|
|
this.server = startMirage();
|
|
|
|
this.server.create('namespace');
|
2018-02-01 00:12:50 +00:00
|
|
|
});
|
|
|
|
|
2021-12-28 14:45:20 +00:00
|
|
|
hooks.afterEach(function () {
|
2019-03-13 00:04:16 +00:00
|
|
|
this.server.shutdown();
|
|
|
|
window.localStorage.clear();
|
|
|
|
});
|
|
|
|
|
2021-12-28 14:45:20 +00:00
|
|
|
test('when the job has placement failures, they are called out', async function (assert) {
|
2019-03-13 00:04:16 +00:00
|
|
|
this.server.create('job', { failedPlacements: true, createAllocations: false });
|
2019-07-23 19:40:32 +00:00
|
|
|
await this.store.findAll('job');
|
|
|
|
|
|
|
|
const job = this.store.peekAll('job').get('firstObject');
|
|
|
|
await job.reload();
|
|
|
|
|
|
|
|
this.set('job', job);
|
|
|
|
|
|
|
|
await render(hbs`
|
2020-07-09 17:30:11 +00:00
|
|
|
<JobPage::Parts::PlacementFailures @job={{job}} />)
|
2019-07-23 19:40:32 +00:00
|
|
|
`);
|
|
|
|
|
|
|
|
const failedEvaluation = this.get('job.evaluations')
|
|
|
|
.filterBy('hasPlacementFailures')
|
|
|
|
.sortBy('modifyIndex')
|
|
|
|
.reverse()
|
|
|
|
.get('firstObject');
|
|
|
|
const failedTGAllocs = failedEvaluation.get('failedTGAllocs');
|
|
|
|
|
|
|
|
assert.ok(find('[data-test-placement-failures]'), 'Placement failures section found');
|
2018-02-01 00:12:50 +00:00
|
|
|
|
2021-12-28 14:45:20 +00:00
|
|
|
const taskGroupLabels = findAll('[data-test-placement-failure-task-group]').map((title) =>
|
2019-07-23 19:40:32 +00:00
|
|
|
title.textContent.trim()
|
|
|
|
);
|
|
|
|
|
2021-12-28 14:45:20 +00:00
|
|
|
failedTGAllocs.forEach((alloc) => {
|
2019-07-23 19:40:32 +00:00
|
|
|
const name = alloc.get('name');
|
|
|
|
assert.ok(
|
2021-12-28 14:45:20 +00:00
|
|
|
taskGroupLabels.find((label) => label.includes(name)),
|
2019-07-23 19:40:32 +00:00
|
|
|
`${name} included in placement failures list`
|
|
|
|
);
|
|
|
|
assert.ok(
|
2021-12-28 14:45:20 +00:00
|
|
|
taskGroupLabels.find((label) => label.includes(alloc.get('coalescedFailures') + 1)),
|
2019-07-23 19:40:32 +00:00
|
|
|
'The number of unplaced allocs = CoalescedFailures + 1'
|
|
|
|
);
|
2018-02-01 00:12:50 +00:00
|
|
|
});
|
2020-08-25 15:56:02 +00:00
|
|
|
|
|
|
|
await componentA11yAudit(this.element, assert);
|
2018-02-01 00:12:50 +00:00
|
|
|
});
|
|
|
|
|
2021-12-28 14:45:20 +00:00
|
|
|
test('when the job has no placement failures, the placement failures section is gone', async function (assert) {
|
2019-03-13 00:04:16 +00:00
|
|
|
this.server.create('job', { noFailedPlacements: true, createAllocations: false });
|
2019-07-23 19:40:32 +00:00
|
|
|
await this.store.findAll('job');
|
|
|
|
|
|
|
|
const job = this.store.peekAll('job').get('firstObject');
|
|
|
|
await job.reload();
|
|
|
|
|
|
|
|
this.set('job', job);
|
|
|
|
|
|
|
|
await render(hbs`
|
2020-07-09 17:30:11 +00:00
|
|
|
<JobPage::Parts::PlacementFailures @job={{job}} />)
|
2019-07-23 19:40:32 +00:00
|
|
|
`);
|
|
|
|
|
|
|
|
assert.notOk(find('[data-test-placement-failures]'), 'Placement failures section not found');
|
2018-02-01 00:12:50 +00:00
|
|
|
});
|
|
|
|
});
|