2018-02-02 01:21:45 +00:00
|
|
|
import { assign } from '@ember/polyfills';
|
|
|
|
import hbs from 'htmlbars-inline-precompile';
|
2021-12-28 15:42:35 +00:00
|
|
|
import { click, findAll, find, render } from '@ember/test-helpers';
|
2019-03-13 00:04:16 +00:00
|
|
|
import { module, test } from 'qunit';
|
2018-02-02 01:21:45 +00:00
|
|
|
import sinon from 'sinon';
|
|
|
|
import { startMirage } from 'nomad-ui/initializers/ember-cli-mirage';
|
2019-07-23 19:40:32 +00:00
|
|
|
import { setupRenderingTest } from 'ember-qunit';
|
2020-08-25 15:56:02 +00:00
|
|
|
import { componentA11yAudit } from 'nomad-ui/tests/helpers/a11y-audit';
|
2021-03-29 23:16:48 +00:00
|
|
|
import { formatScheduledHertz, formatScheduledBytes } from 'nomad-ui/utils/units';
|
2018-02-02 01:21:45 +00:00
|
|
|
|
2021-12-28 14:45:20 +00:00
|
|
|
module('Integration | Component | job-page/parts/task-groups', 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
|
|
|
window.localStorage.clear();
|
|
|
|
this.store = this.owner.lookup('service:store');
|
|
|
|
this.server = startMirage();
|
|
|
|
this.server.create('namespace');
|
2018-02-02 01:21:45 +00:00
|
|
|
});
|
|
|
|
|
2021-12-28 14:45:20 +00:00
|
|
|
hooks.afterEach(function () {
|
2019-03-13 00:04:16 +00:00
|
|
|
this.server.shutdown();
|
2018-02-02 01:21:45 +00:00
|
|
|
});
|
|
|
|
|
2019-03-13 00:04:16 +00:00
|
|
|
const props = (job, options = {}) =>
|
|
|
|
assign(
|
|
|
|
{
|
|
|
|
job,
|
|
|
|
sortProperty: 'name',
|
|
|
|
sortDescending: true,
|
|
|
|
gotoTaskGroup: () => {},
|
|
|
|
},
|
|
|
|
options
|
|
|
|
);
|
|
|
|
|
2021-12-28 14:45:20 +00:00
|
|
|
test('the job detail page should list all task groups', async function (assert) {
|
2019-03-13 00:04:16 +00:00
|
|
|
this.server.create('job', {
|
|
|
|
createAllocations: false,
|
2018-02-02 01:21:45 +00:00
|
|
|
});
|
|
|
|
|
2021-12-28 14:45:20 +00:00
|
|
|
await this.store.findAll('job').then((jobs) => {
|
|
|
|
jobs.forEach((job) => job.reload());
|
2019-03-13 00:04:16 +00:00
|
|
|
});
|
2018-02-02 01:21:45 +00:00
|
|
|
|
2019-07-23 19:40:32 +00:00
|
|
|
const job = this.store.peekAll('job').get('firstObject');
|
|
|
|
this.setProperties(props(job));
|
|
|
|
|
2021-12-28 15:42:35 +00:00
|
|
|
await render(hbs`
|
2020-07-09 17:30:11 +00:00
|
|
|
<JobPage::Parts::TaskGroups
|
2021-03-29 23:16:48 +00:00
|
|
|
@job={{this.job}}
|
|
|
|
@sortProperty={{this.sortProperty}}
|
|
|
|
@sortDescending={{this.sortDescending}}
|
|
|
|
@gotoTaskGroup={{this.gotoTaskGroup}} />
|
2019-07-23 19:40:32 +00:00
|
|
|
`);
|
|
|
|
|
|
|
|
assert.equal(
|
|
|
|
findAll('[data-test-task-group]').length,
|
|
|
|
job.get('taskGroups.length'),
|
|
|
|
'One row per task group'
|
|
|
|
);
|
2020-08-25 15:56:02 +00:00
|
|
|
|
|
|
|
await componentA11yAudit(this.element, assert);
|
2018-02-02 01:21:45 +00:00
|
|
|
});
|
|
|
|
|
2021-12-28 14:45:20 +00:00
|
|
|
test('each row in the task group table should show basic information about the task group', async function (assert) {
|
2019-03-13 00:04:16 +00:00
|
|
|
this.server.create('job', {
|
|
|
|
createAllocations: false,
|
2018-02-02 01:21:45 +00:00
|
|
|
});
|
|
|
|
|
2021-12-28 14:45:20 +00:00
|
|
|
const job = await this.store.findAll('job').then(async (jobs) => {
|
2019-07-23 19:40:32 +00:00
|
|
|
return await jobs.get('firstObject').reload();
|
2019-03-13 00:04:16 +00:00
|
|
|
});
|
2018-02-02 01:21:45 +00:00
|
|
|
|
2019-07-23 19:40:32 +00:00
|
|
|
const taskGroups = await job.get('taskGroups');
|
2021-12-28 14:45:20 +00:00
|
|
|
const taskGroup = taskGroups.sortBy('name').reverse().get('firstObject');
|
2019-07-23 19:40:32 +00:00
|
|
|
|
|
|
|
this.setProperties(props(job));
|
|
|
|
|
2021-12-28 15:42:35 +00:00
|
|
|
await render(hbs`
|
2020-07-09 17:30:11 +00:00
|
|
|
<JobPage::Parts::TaskGroups
|
2021-03-29 23:16:48 +00:00
|
|
|
@job={{this.job}}
|
|
|
|
@sortProperty={{this.sortProperty}}
|
|
|
|
@sortDescending={{this.sortDescending}}
|
|
|
|
@gotoTaskGroup={{this.gotoTaskGroup}} />
|
2019-07-23 19:40:32 +00:00
|
|
|
`);
|
|
|
|
|
|
|
|
const taskGroupRow = find('[data-test-task-group]');
|
|
|
|
|
|
|
|
assert.equal(
|
|
|
|
taskGroupRow.querySelector('[data-test-task-group-name]').textContent.trim(),
|
|
|
|
taskGroup.get('name'),
|
|
|
|
'Name'
|
|
|
|
);
|
|
|
|
assert.equal(
|
|
|
|
taskGroupRow.querySelector('[data-test-task-group-count]').textContent.trim(),
|
|
|
|
taskGroup.get('count'),
|
|
|
|
'Count'
|
|
|
|
);
|
2020-02-12 19:49:28 +00:00
|
|
|
assert.equal(
|
|
|
|
taskGroupRow.querySelector('[data-test-task-group-volume]').textContent.trim(),
|
|
|
|
taskGroup.get('volumes.length') ? 'Yes' : '',
|
|
|
|
'Volumes'
|
|
|
|
);
|
2019-07-23 19:40:32 +00:00
|
|
|
assert.equal(
|
|
|
|
taskGroupRow.querySelector('[data-test-task-group-cpu]').textContent.trim(),
|
2021-03-29 23:16:48 +00:00
|
|
|
`${formatScheduledHertz(taskGroup.get('reservedCPU'), 'MHz')}`,
|
2019-07-23 19:40:32 +00:00
|
|
|
'Reserved CPU'
|
|
|
|
);
|
|
|
|
assert.equal(
|
|
|
|
taskGroupRow.querySelector('[data-test-task-group-mem]').textContent.trim(),
|
2021-03-29 23:16:48 +00:00
|
|
|
`${formatScheduledBytes(taskGroup.get('reservedMemory'), 'MiB')}`,
|
2019-07-23 19:40:32 +00:00
|
|
|
'Reserved Memory'
|
|
|
|
);
|
|
|
|
assert.equal(
|
|
|
|
taskGroupRow.querySelector('[data-test-task-group-disk]').textContent.trim(),
|
2021-03-29 23:16:48 +00:00
|
|
|
`${formatScheduledBytes(taskGroup.get('reservedEphemeralDisk'), 'MiB')}`,
|
2019-07-23 19:40:32 +00:00
|
|
|
'Reserved Disk'
|
|
|
|
);
|
2018-02-02 01:21:45 +00:00
|
|
|
});
|
|
|
|
|
2021-12-28 14:45:20 +00:00
|
|
|
test('gotoTaskGroup is called when task group rows are clicked', async function (assert) {
|
2019-03-13 00:04:16 +00:00
|
|
|
this.server.create('job', {
|
|
|
|
createAllocations: false,
|
|
|
|
});
|
2018-02-02 01:21:45 +00:00
|
|
|
|
2021-12-28 14:45:20 +00:00
|
|
|
const job = await this.store.findAll('job').then(async (jobs) => {
|
2019-07-23 19:40:32 +00:00
|
|
|
return await jobs.get('firstObject').reload();
|
2019-03-13 00:04:16 +00:00
|
|
|
});
|
|
|
|
|
2019-07-23 19:40:32 +00:00
|
|
|
const taskGroupSpy = sinon.spy();
|
|
|
|
|
|
|
|
const taskGroups = await job.get('taskGroups');
|
2021-12-28 14:45:20 +00:00
|
|
|
const taskGroup = taskGroups.sortBy('name').reverse().get('firstObject');
|
2019-07-23 19:40:32 +00:00
|
|
|
|
|
|
|
this.setProperties(
|
|
|
|
props(job, {
|
|
|
|
gotoTaskGroup: taskGroupSpy,
|
|
|
|
})
|
|
|
|
);
|
|
|
|
|
2021-12-28 15:42:35 +00:00
|
|
|
await render(hbs`
|
2020-07-09 17:30:11 +00:00
|
|
|
<JobPage::Parts::TaskGroups
|
2021-03-29 23:16:48 +00:00
|
|
|
@job={{this.job}}
|
|
|
|
@sortProperty={{this.sortProperty}}
|
|
|
|
@sortDescending={{this.sortDescending}}
|
|
|
|
@gotoTaskGroup={{this.gotoTaskGroup}} />
|
2019-07-23 19:40:32 +00:00
|
|
|
`);
|
|
|
|
|
|
|
|
await click('[data-test-task-group]');
|
|
|
|
|
|
|
|
assert.ok(
|
|
|
|
taskGroupSpy.withArgs(taskGroup).calledOnce,
|
|
|
|
'Clicking the task group row calls the gotoTaskGroup action'
|
|
|
|
);
|
2018-02-02 01:21:45 +00:00
|
|
|
});
|
|
|
|
});
|