open-nomad/ui/tests/integration/components/reschedule-event-timeline-test.js

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

188 lines
5.5 KiB
JavaScript
Raw Normal View History

2019-03-13 00:04:16 +00:00
import { module, test } from 'qunit';
import { setupRenderingTest } from 'ember-qunit';
import { find, findAll, render } from '@ember/test-helpers';
import { startMirage } from 'nomad-ui/initializers/ember-cli-mirage';
import hbs from 'htmlbars-inline-precompile';
import { componentA11yAudit } from 'nomad-ui/tests/helpers/a11y-audit';
import moment from 'moment';
2021-12-28 14:45:20 +00:00
module('Integration | Component | reschedule event timeline', function (hooks) {
2019-03-13 00:04:16 +00:00
setupRenderingTest(hooks);
2021-12-28 14:45:20 +00:00
hooks.beforeEach(function () {
2019-03-13 00:04:16 +00:00
this.store = this.owner.lookup('service:store');
this.server = startMirage();
this.server.create('namespace');
this.server.create('node');
this.server.create('job', { createAllocations: false });
});
2021-12-28 14:45:20 +00:00
hooks.afterEach(function () {
2019-03-13 00:04:16 +00:00
this.server.shutdown();
});
2019-03-13 00:04:16 +00:00
const commonTemplate = hbs`
<RescheduleEventTimeline @allocation={{allocation}} />
2019-03-13 00:04:16 +00:00
`;
2021-12-28 14:45:20 +00:00
test('when the allocation is running, the timeline shows past allocations', async function (assert) {
assert.expect(7);
2019-03-13 00:04:16 +00:00
const attempts = 2;
2019-03-13 00:04:16 +00:00
this.server.create('allocation', 'rescheduled', {
rescheduleAttempts: attempts,
rescheduleSuccess: true,
});
await this.store.findAll('allocation');
const allocation = this.store
.peekAll('allocation')
2021-12-28 14:45:20 +00:00
.find((alloc) => !alloc.get('nextAllocation.content'));
this.set('allocation', allocation);
await render(commonTemplate);
assert.equal(
findAll('[data-test-allocation]').length,
attempts + 1,
'Total allocations equals current allocation plus all past allocations'
);
assert.equal(
find('[data-test-allocation]'),
find(`[data-test-allocation="${allocation.id}"]`),
'First allocation is the current allocation'
);
assert.notOk(find('[data-test-stop-warning]'), 'No stop warning');
assert.notOk(find('[data-test-attempt-notice]'), 'No attempt notice');
assert.equal(
find(
`[data-test-allocation="${allocation.id}"] [data-test-allocation-link]`
).textContent.trim(),
allocation.get('shortId'),
'The "this" allocation is correct'
);
assert.equal(
find(
`[data-test-allocation="${allocation.id}"] [data-test-allocation-status]`
).textContent.trim(),
allocation.get('clientStatus'),
'Allocation shows the status'
);
await componentA11yAudit(this.element, assert);
});
2021-12-28 14:45:20 +00:00
test('when the allocation has failed and there is a follow up evaluation, a note with a time is shown', async function (assert) {
assert.expect(3);
2019-03-13 00:04:16 +00:00
const attempts = 2;
this.server.create('allocation', 'rescheduled', {
rescheduleAttempts: attempts,
rescheduleSuccess: false,
});
await this.store.findAll('allocation');
const allocation = this.store
.peekAll('allocation')
2021-12-28 14:45:20 +00:00
.find((alloc) => !alloc.get('nextAllocation.content'));
this.set('allocation', allocation);
await render(commonTemplate);
assert.ok(
find('[data-test-stop-warning]'),
'Stop warning is shown since the last allocation failed'
);
2021-12-28 16:08:12 +00:00
assert.notOk(
find('[data-test-attempt-notice]'),
'Reschdule attempt notice is not shown'
);
await componentA11yAudit(this.element, assert);
});
2021-12-28 14:45:20 +00:00
test('when the allocation has failed and there is no follow up evaluation, a warning is shown', async function (assert) {
assert.expect(3);
2019-03-13 00:04:16 +00:00
const attempts = 2;
this.server.create('allocation', 'rescheduled', {
rescheduleAttempts: attempts,
rescheduleSuccess: false,
});
2021-12-28 16:08:12 +00:00
const lastAllocation = server.schema.allocations.findBy({
nextAllocation: undefined,
});
2019-03-13 00:04:16 +00:00
lastAllocation.update({
followupEvalId: server.create('evaluation', {
2021-12-28 14:45:20 +00:00
waitUntil: moment().add(2, 'hours').toDate(),
2019-03-13 00:04:16 +00:00
}).id,
});
2019-03-25 22:54:48 +00:00
await this.store.findAll('allocation');
2019-03-13 00:04:16 +00:00
2019-03-25 22:54:48 +00:00
let allocation = this.store
.peekAll('allocation')
2021-12-28 14:45:20 +00:00
.find((alloc) => !alloc.get('nextAllocation.content'));
2019-03-25 22:54:48 +00:00
this.set('allocation', allocation);
2019-03-13 00:04:16 +00:00
2019-03-25 22:54:48 +00:00
await render(commonTemplate);
2019-03-13 00:04:16 +00:00
2019-03-25 22:54:48 +00:00
assert.ok(
find('[data-test-attempt-notice]'),
'Reschedule notice is shown since the follow up eval says so'
);
assert.notOk(find('[data-test-stop-warning]'), 'Stop warning is not shown');
await componentA11yAudit(this.element, assert);
});
2021-12-28 14:45:20 +00:00
test('when the allocation has a next allocation already, it is shown in the timeline', async function (assert) {
2019-03-13 00:04:16 +00:00
const attempts = 2;
const originalAllocation = this.server.create('allocation', 'rescheduled', {
rescheduleAttempts: attempts,
rescheduleSuccess: true,
});
2019-03-13 00:04:16 +00:00
await this.store.findAll('allocation');
2021-12-28 16:08:12 +00:00
const allocation = this.store
.peekAll('allocation')
.findBy('id', originalAllocation.id);
this.set('allocation', allocation);
await render(commonTemplate);
assert.equal(
find('[data-test-reschedule-label]').textContent.trim(),
'Next Allocation',
'The first allocation is the next allocation and labeled as such'
);
assert.equal(
2021-12-28 16:08:12 +00:00
find(
'[data-test-allocation] [data-test-allocation-link]'
).textContent.trim(),
allocation.get('nextAllocation.shortId'),
'The next allocation item is for the correct allocation'
);
assert.equal(
findAll('[data-test-allocation]')[1],
find(`[data-test-allocation="${allocation.id}"]`),
'Second allocation is the current allocation'
);
assert.notOk(find('[data-test-stop-warning]'), 'No stop warning');
assert.notOk(find('[data-test-attempt-notice]'), 'No attempt notice');
2019-03-13 00:04:16 +00:00
});
});