2020-07-28 16:48:42 +00:00
|
|
|
import { module, test } from 'qunit';
|
|
|
|
import { setupRenderingTest } from 'ember-qunit';
|
|
|
|
import { click, find, findAll, render } from '@ember/test-helpers';
|
|
|
|
import hbs from 'htmlbars-inline-precompile';
|
|
|
|
import { startMirage } from 'nomad-ui/initializers/ember-cli-mirage';
|
|
|
|
import setupCodeMirror from 'nomad-ui/tests/helpers/codemirror';
|
|
|
|
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';
|
2020-07-28 16:48:42 +00:00
|
|
|
|
2021-12-28 14:45:20 +00:00
|
|
|
module('Integration | Component | scale-events-accordion', function (hooks) {
|
2020-07-28 16:48:42 +00:00
|
|
|
setupRenderingTest(hooks);
|
|
|
|
setupCodeMirror(hooks);
|
|
|
|
|
2021-12-28 14:45:20 +00:00
|
|
|
hooks.beforeEach(function () {
|
2020-07-28 16:48:42 +00:00
|
|
|
fragmentSerializerInitializer(this.owner);
|
|
|
|
this.store = this.owner.lookup('service:store');
|
|
|
|
this.server = startMirage();
|
|
|
|
this.server.create('node');
|
2021-12-28 14:45:20 +00:00
|
|
|
this.taskGroupWithEvents = async function (events) {
|
2020-07-28 16:48:42 +00:00
|
|
|
const job = this.server.create('job', { createAllocations: false });
|
2020-08-28 00:58:24 +00:00
|
|
|
const group = job.taskGroups.models[0];
|
2021-12-28 16:08:12 +00:00
|
|
|
job.jobScale.taskGroupScales.models
|
|
|
|
.findBy('name', group.name)
|
|
|
|
.update({ events });
|
|
|
|
|
|
|
|
const jobModel = await this.store.find(
|
|
|
|
'job',
|
|
|
|
JSON.stringify([job.id, 'default'])
|
|
|
|
);
|
2020-07-28 16:48:42 +00:00
|
|
|
await jobModel.get('scaleState');
|
|
|
|
return jobModel.taskGroups.findBy('name', group.name);
|
|
|
|
};
|
|
|
|
});
|
|
|
|
|
2021-12-28 14:45:20 +00:00
|
|
|
hooks.afterEach(function () {
|
2020-08-17 13:17:29 +00:00
|
|
|
this.server.shutdown();
|
|
|
|
});
|
|
|
|
|
2020-07-28 16:48:42 +00:00
|
|
|
const commonTemplate = hbs`<ScaleEventsAccordion @events={{this.events}} />`;
|
|
|
|
|
2021-12-28 14:45:20 +00:00
|
|
|
test('it shows an accordion with an entry for each event', async function (assert) {
|
2021-12-28 19:30:38 +00:00
|
|
|
assert.expect(2);
|
|
|
|
|
2020-07-28 16:48:42 +00:00
|
|
|
const eventCount = 5;
|
2021-12-28 16:08:12 +00:00
|
|
|
const taskGroup = await this.taskGroupWithEvents(
|
|
|
|
server.createList('scale-event', eventCount)
|
|
|
|
);
|
2020-07-28 16:48:42 +00:00
|
|
|
this.set('events', taskGroup.scaleState.events);
|
|
|
|
|
|
|
|
await render(commonTemplate);
|
|
|
|
|
2021-12-28 16:08:12 +00:00
|
|
|
assert.equal(
|
|
|
|
findAll('[data-test-scale-events] [data-test-accordion-head]').length,
|
|
|
|
eventCount
|
|
|
|
);
|
2020-08-25 15:56:02 +00:00
|
|
|
await componentA11yAudit(this.element, assert);
|
2020-07-28 16:48:42 +00:00
|
|
|
});
|
|
|
|
|
2021-12-28 14:45:20 +00:00
|
|
|
test('when an event is an error, an error icon is shown', async function (assert) {
|
2021-12-28 19:30:38 +00:00
|
|
|
assert.expect(2);
|
|
|
|
|
2020-07-28 16:48:42 +00:00
|
|
|
const taskGroup = await this.taskGroupWithEvents(
|
|
|
|
server.createList('scale-event', 1, { error: true })
|
|
|
|
);
|
|
|
|
this.set('events', taskGroup.scaleState.events);
|
|
|
|
|
|
|
|
await render(commonTemplate);
|
|
|
|
|
|
|
|
assert.ok(find('[data-test-error]'));
|
2020-08-25 15:56:02 +00:00
|
|
|
await componentA11yAudit(this.element, assert);
|
2020-07-28 16:48:42 +00:00
|
|
|
});
|
|
|
|
|
2021-12-28 14:45:20 +00:00
|
|
|
test('when an event has a count higher than previous count, a danger up arrow is shown', async function (assert) {
|
2021-12-28 19:30:38 +00:00
|
|
|
assert.expect(4);
|
|
|
|
|
2020-07-28 16:48:42 +00:00
|
|
|
const count = 5;
|
|
|
|
const taskGroup = await this.taskGroupWithEvents(
|
2021-12-28 16:08:12 +00:00
|
|
|
server.createList('scale-event', 1, {
|
|
|
|
count,
|
|
|
|
previousCount: count - 1,
|
|
|
|
error: false,
|
|
|
|
})
|
2020-07-28 16:48:42 +00:00
|
|
|
);
|
|
|
|
this.set('events', taskGroup.scaleState.events);
|
|
|
|
|
|
|
|
await render(commonTemplate);
|
|
|
|
|
|
|
|
assert.notOk(find('[data-test-error]'));
|
|
|
|
assert.equal(find('[data-test-count]').textContent, count);
|
|
|
|
assert.ok(
|
2021-12-28 16:08:12 +00:00
|
|
|
find('[data-test-count-icon]')
|
|
|
|
.querySelector('.icon')
|
|
|
|
.classList.contains('is-danger')
|
2020-07-28 16:48:42 +00:00
|
|
|
);
|
2020-08-25 15:56:02 +00:00
|
|
|
await componentA11yAudit(this.element, assert);
|
2020-07-28 16:48:42 +00:00
|
|
|
});
|
|
|
|
|
2021-12-28 14:45:20 +00:00
|
|
|
test('when an event has a count lower than previous count, a primary down arrow is shown', async function (assert) {
|
2020-07-28 16:48:42 +00:00
|
|
|
const count = 5;
|
|
|
|
const taskGroup = await this.taskGroupWithEvents(
|
2021-12-28 16:08:12 +00:00
|
|
|
server.createList('scale-event', 1, {
|
|
|
|
count,
|
|
|
|
previousCount: count + 1,
|
|
|
|
error: false,
|
|
|
|
})
|
2020-07-28 16:48:42 +00:00
|
|
|
);
|
|
|
|
this.set('events', taskGroup.scaleState.events);
|
|
|
|
|
|
|
|
await render(commonTemplate);
|
|
|
|
|
|
|
|
assert.notOk(find('[data-test-error]'));
|
|
|
|
assert.equal(find('[data-test-count]').textContent, count);
|
|
|
|
assert.ok(
|
2021-12-28 16:08:12 +00:00
|
|
|
find('[data-test-count-icon]')
|
|
|
|
.querySelector('.icon')
|
|
|
|
.classList.contains('is-primary')
|
2020-07-28 16:48:42 +00:00
|
|
|
);
|
|
|
|
});
|
|
|
|
|
2021-12-28 14:45:20 +00:00
|
|
|
test('when an event has no count, the count is omitted', async function (assert) {
|
2020-07-28 16:48:42 +00:00
|
|
|
const taskGroup = await this.taskGroupWithEvents(
|
|
|
|
server.createList('scale-event', 1, { count: null })
|
|
|
|
);
|
|
|
|
this.set('events', taskGroup.scaleState.events);
|
|
|
|
|
|
|
|
await render(commonTemplate);
|
|
|
|
|
2020-07-28 18:03:47 +00:00
|
|
|
assert.notOk(find('[data-test-count]'));
|
|
|
|
assert.notOk(find('[data-test-count-icon]'));
|
2020-07-28 16:48:42 +00:00
|
|
|
});
|
|
|
|
|
2021-12-28 14:45:20 +00:00
|
|
|
test('when an event has no meta properties, the accordion entry is not expandable', async function (assert) {
|
2021-12-28 19:30:38 +00:00
|
|
|
assert.expect(2);
|
|
|
|
|
2020-07-28 16:48:42 +00:00
|
|
|
const taskGroup = await this.taskGroupWithEvents(
|
|
|
|
server.createList('scale-event', 1, { meta: {} })
|
|
|
|
);
|
|
|
|
this.set('events', taskGroup.scaleState.events);
|
|
|
|
|
|
|
|
await render(commonTemplate);
|
|
|
|
|
2021-12-28 16:08:12 +00:00
|
|
|
assert.ok(
|
|
|
|
find('[data-test-accordion-toggle]').classList.contains('is-invisible')
|
|
|
|
);
|
2020-08-25 15:56:02 +00:00
|
|
|
await componentA11yAudit(this.element, assert);
|
2020-07-28 16:48:42 +00:00
|
|
|
});
|
|
|
|
|
2021-12-28 14:45:20 +00:00
|
|
|
test('when an event has meta properties, the accordion entry is expanding, presenting the meta properties in a json viewer', async function (assert) {
|
2021-12-28 19:30:38 +00:00
|
|
|
assert.expect(4);
|
|
|
|
|
2020-07-28 16:48:42 +00:00
|
|
|
const meta = {
|
|
|
|
prop: 'one',
|
|
|
|
prop2: 'two',
|
|
|
|
deep: {
|
|
|
|
prop: 'here',
|
|
|
|
'dot.separate.prop': 12,
|
|
|
|
},
|
|
|
|
};
|
2021-12-28 16:08:12 +00:00
|
|
|
const taskGroup = await this.taskGroupWithEvents(
|
|
|
|
server.createList('scale-event', 1, { meta })
|
|
|
|
);
|
2020-07-28 16:48:42 +00:00
|
|
|
this.set('events', taskGroup.scaleState.events);
|
|
|
|
|
|
|
|
await render(commonTemplate);
|
|
|
|
assert.notOk(find('[data-test-accordion-body]'));
|
|
|
|
|
|
|
|
await click('[data-test-accordion-toggle]');
|
|
|
|
assert.ok(find('[data-test-accordion-body]'));
|
|
|
|
|
|
|
|
assert.equal(
|
|
|
|
getCodeMirrorInstance('[data-test-json-viewer]').getValue(),
|
|
|
|
JSON.stringify(meta, null, 2)
|
|
|
|
);
|
2020-08-25 15:56:02 +00:00
|
|
|
await componentA11yAudit(this.element, assert);
|
2020-07-28 16:48:42 +00:00
|
|
|
});
|
|
|
|
});
|