2018-01-31 22:01:13 +00:00
|
|
|
import { assign } from '@ember/polyfills';
|
|
|
|
import hbs from 'htmlbars-inline-precompile';
|
2019-07-23 19:40:32 +00:00
|
|
|
import { findAll, find, click, render } from '@ember/test-helpers';
|
2018-01-31 22:01:13 +00:00
|
|
|
import sinon from 'sinon';
|
2019-03-13 00:04:16 +00:00
|
|
|
import { module, test } from 'qunit';
|
|
|
|
import { setupRenderingTest } from 'ember-qunit';
|
2018-01-31 22:01:13 +00:00
|
|
|
import { startMirage } from 'nomad-ui/initializers/ember-cli-mirage';
|
2020-08-25 15:56:02 +00:00
|
|
|
import { componentA11yAudit } from 'nomad-ui/tests/helpers/a11y-audit';
|
2018-01-31 22:01:13 +00:00
|
|
|
|
2021-12-28 14:45:20 +00:00
|
|
|
module('Integration | Component | job-page/parts/children', function (hooks) {
|
2019-03-13 00:04:16 +00:00
|
|
|
setupRenderingTest(hooks);
|
|
|
|
|
2021-12-28 14:45:20 +00:00
|
|
|
hooks.beforeEach(function () {
|
2018-01-31 22:01:13 +00:00
|
|
|
window.localStorage.clear();
|
2019-03-13 00:04:16 +00:00
|
|
|
this.store = this.owner.lookup('service:store');
|
2018-01-31 22:01:13 +00:00
|
|
|
this.server = startMirage();
|
|
|
|
this.server.create('namespace');
|
2019-03-13 00:04:16 +00:00
|
|
|
});
|
|
|
|
|
2021-12-28 14:45:20 +00:00
|
|
|
hooks.afterEach(function () {
|
2018-02-02 17:51:44 +00:00
|
|
|
this.server.shutdown();
|
|
|
|
window.localStorage.clear();
|
2018-01-31 22:01:13 +00:00
|
|
|
});
|
|
|
|
|
2019-03-13 00:04:16 +00:00
|
|
|
const props = (job, options = {}) =>
|
|
|
|
assign(
|
|
|
|
{
|
|
|
|
job,
|
|
|
|
sortProperty: 'name',
|
|
|
|
sortDescending: true,
|
|
|
|
currentPage: 1,
|
|
|
|
gotoJob: () => {},
|
|
|
|
},
|
|
|
|
options
|
|
|
|
);
|
2018-01-31 22:01:13 +00:00
|
|
|
|
2021-12-28 14:45:20 +00:00
|
|
|
test('lists each child', async function (assert) {
|
2019-03-13 00:04:16 +00:00
|
|
|
this.server.create('job', 'periodic', {
|
|
|
|
id: 'parent',
|
|
|
|
childrenCount: 3,
|
|
|
|
createAllocations: false,
|
2018-01-31 22:01:13 +00:00
|
|
|
});
|
|
|
|
|
2019-07-23 19:40:32 +00:00
|
|
|
await this.store.findAll('job');
|
|
|
|
|
|
|
|
const parent = this.store.peekAll('job').findBy('plainId', 'parent');
|
2018-01-31 22:01:13 +00:00
|
|
|
|
2019-07-23 19:40:32 +00:00
|
|
|
this.setProperties(props(parent));
|
|
|
|
|
|
|
|
await render(hbs`
|
2020-07-09 17:30:11 +00:00
|
|
|
<JobPage::Parts::Children
|
|
|
|
@job={{job}}
|
|
|
|
@sortProperty={{sortProperty}}
|
|
|
|
@sortDescending={{sortDescending}}
|
|
|
|
@currentPage={{currentPage}}
|
|
|
|
@gotoJob={{gotoJob}} />
|
2019-07-23 19:40:32 +00:00
|
|
|
`);
|
|
|
|
|
|
|
|
assert.equal(
|
|
|
|
findAll('[data-test-job-name]').length,
|
|
|
|
parent.get('children.length'),
|
|
|
|
'A row for each child'
|
|
|
|
);
|
|
|
|
});
|
2018-01-31 22:01:13 +00:00
|
|
|
|
2021-12-28 14:45:20 +00:00
|
|
|
test('eventually paginates', async function (assert) {
|
2020-09-19 04:42:04 +00:00
|
|
|
const pageSize = 10;
|
|
|
|
window.localStorage.nomadPageSize = pageSize;
|
|
|
|
|
2019-03-13 00:04:16 +00:00
|
|
|
this.server.create('job', 'periodic', {
|
|
|
|
id: 'parent',
|
|
|
|
childrenCount: 11,
|
|
|
|
createAllocations: false,
|
2018-01-31 22:01:13 +00:00
|
|
|
});
|
|
|
|
|
2019-07-23 19:40:32 +00:00
|
|
|
await this.store.findAll('job');
|
|
|
|
|
|
|
|
const parent = this.store.peekAll('job').findBy('plainId', 'parent');
|
|
|
|
|
|
|
|
this.setProperties(props(parent));
|
2018-01-31 22:01:13 +00:00
|
|
|
|
2019-07-23 19:40:32 +00:00
|
|
|
await render(hbs`
|
2020-07-09 17:30:11 +00:00
|
|
|
<JobPage::Parts::Children
|
|
|
|
@job={{job}}
|
|
|
|
@sortProperty={{sortProperty}}
|
|
|
|
@sortDescending={{sortDescending}}
|
|
|
|
@currentPage={{currentPage}}
|
|
|
|
@gotoJob={{gotoJob}} />
|
2019-07-23 19:40:32 +00:00
|
|
|
`);
|
|
|
|
|
|
|
|
const childrenCount = parent.get('children.length');
|
2020-09-19 04:42:04 +00:00
|
|
|
assert.ok(childrenCount > pageSize, 'Parent has more children than one page size');
|
|
|
|
assert.equal(findAll('[data-test-job-name]').length, pageSize, 'Table length maxes out at 10');
|
2019-07-23 19:40:32 +00:00
|
|
|
assert.ok(find('.pagination-next'), 'Next button is rendered');
|
|
|
|
|
|
|
|
assert.ok(
|
|
|
|
new RegExp(`1.10.+?${childrenCount}`).test(find('.pagination-numbers').textContent.trim())
|
|
|
|
);
|
2020-08-25 15:56:02 +00:00
|
|
|
|
|
|
|
await componentA11yAudit(this.element, assert);
|
2019-07-23 19:40:32 +00:00
|
|
|
});
|
2019-03-13 00:04:16 +00:00
|
|
|
|
2021-12-28 14:45:20 +00:00
|
|
|
test('is sorted based on the sortProperty and sortDescending properties', async function (assert) {
|
2019-03-13 00:04:16 +00:00
|
|
|
this.server.create('job', 'periodic', {
|
|
|
|
id: 'parent',
|
|
|
|
childrenCount: 3,
|
|
|
|
createAllocations: false,
|
|
|
|
});
|
|
|
|
|
2019-07-23 19:40:32 +00:00
|
|
|
await this.store.findAll('job');
|
|
|
|
|
|
|
|
const parent = this.store.peekAll('job').findBy('plainId', 'parent');
|
|
|
|
|
|
|
|
this.setProperties(props(parent));
|
|
|
|
|
|
|
|
await render(hbs`
|
2020-07-09 17:30:11 +00:00
|
|
|
<JobPage::Parts::Children
|
|
|
|
@job={{job}}
|
|
|
|
@sortProperty={{sortProperty}}
|
|
|
|
@sortDescending={{sortDescending}}
|
|
|
|
@currentPage={{currentPage}}
|
|
|
|
@gotoJob={{gotoJob}} />
|
2019-07-23 19:40:32 +00:00
|
|
|
`);
|
|
|
|
|
|
|
|
const sortedChildren = parent.get('children').sortBy('name');
|
|
|
|
const childRows = findAll('[data-test-job-name]');
|
|
|
|
|
|
|
|
sortedChildren.reverse().forEach((child, index) => {
|
|
|
|
assert.equal(
|
|
|
|
childRows[index].textContent.trim(),
|
|
|
|
child.get('name'),
|
|
|
|
`Child ${index} is ${child.get('name')}`
|
|
|
|
);
|
|
|
|
});
|
|
|
|
|
|
|
|
await this.set('sortDescending', false);
|
|
|
|
|
|
|
|
sortedChildren.forEach((child, index) => {
|
|
|
|
assert.equal(
|
|
|
|
childRows[index].textContent.trim(),
|
|
|
|
child.get('name'),
|
|
|
|
`Child ${index} is ${child.get('name')}`
|
|
|
|
);
|
2019-03-13 00:04:16 +00:00
|
|
|
});
|
2018-01-31 22:01:13 +00:00
|
|
|
});
|
|
|
|
|
2021-12-28 14:45:20 +00:00
|
|
|
test('gotoJob is called when a job row is clicked', async function (assert) {
|
2019-03-13 00:04:16 +00:00
|
|
|
const gotoJobSpy = sinon.spy();
|
2018-01-31 22:01:13 +00:00
|
|
|
|
2019-03-13 00:04:16 +00:00
|
|
|
this.server.create('job', 'periodic', {
|
|
|
|
id: 'parent',
|
|
|
|
childrenCount: 1,
|
|
|
|
createAllocations: false,
|
2018-01-31 22:01:13 +00:00
|
|
|
});
|
|
|
|
|
2019-07-23 19:40:32 +00:00
|
|
|
await this.store.findAll('job');
|
2018-01-31 22:01:13 +00:00
|
|
|
|
2019-07-23 19:40:32 +00:00
|
|
|
const parent = this.store.peekAll('job').findBy('plainId', 'parent');
|
2019-03-13 00:04:16 +00:00
|
|
|
|
2019-07-23 19:40:32 +00:00
|
|
|
this.setProperties(
|
|
|
|
props(parent, {
|
|
|
|
gotoJob: gotoJobSpy,
|
|
|
|
})
|
|
|
|
);
|
2019-03-13 00:04:16 +00:00
|
|
|
|
2019-07-23 19:40:32 +00:00
|
|
|
await render(hbs`
|
2020-07-09 17:30:11 +00:00
|
|
|
<JobPage::Parts::Children
|
|
|
|
@job={{job}}
|
|
|
|
@sortProperty={{sortProperty}}
|
|
|
|
@sortDescending={{sortDescending}}
|
|
|
|
@currentPage={{currentPage}}
|
|
|
|
@gotoJob={{gotoJob}} />
|
2019-07-23 19:40:32 +00:00
|
|
|
`);
|
|
|
|
|
|
|
|
await click('tr.job-row');
|
|
|
|
|
|
|
|
assert.ok(
|
|
|
|
gotoJobSpy.withArgs(parent.get('children.firstObject')).calledOnce,
|
|
|
|
'Clicking the job row calls the gotoJob action'
|
|
|
|
);
|
2018-01-31 22:01:13 +00:00
|
|
|
});
|
|
|
|
});
|