2020-08-05 04:28:11 +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 moment from 'moment';
|
|
|
|
import setupCodeMirror from 'nomad-ui/tests/helpers/codemirror';
|
2020-08-25 15:56:02 +00:00
|
|
|
import { componentA11yAudit } from 'nomad-ui/tests/helpers/a11y-audit';
|
2020-08-05 04:28:11 +00:00
|
|
|
|
2021-12-28 14:45:20 +00:00
|
|
|
module('Integration | Component | scale-events-chart', function (hooks) {
|
2020-08-05 04:28:11 +00:00
|
|
|
setupRenderingTest(hooks);
|
|
|
|
setupCodeMirror(hooks);
|
|
|
|
|
|
|
|
const events = [
|
|
|
|
{
|
|
|
|
time: new Date('2020-08-05T04:06:00'),
|
|
|
|
count: 2,
|
|
|
|
hasCount: true,
|
|
|
|
meta: {},
|
|
|
|
message: '',
|
|
|
|
error: false,
|
|
|
|
},
|
|
|
|
{
|
|
|
|
time: new Date('2020-08-06T04:06:00'),
|
|
|
|
count: 3,
|
|
|
|
hasCount: true,
|
|
|
|
meta: {},
|
|
|
|
message: '',
|
|
|
|
error: false,
|
|
|
|
},
|
|
|
|
{
|
|
|
|
time: new Date('2020-08-07T04:06:00'),
|
|
|
|
count: 4,
|
|
|
|
hasCount: true,
|
|
|
|
meta: {},
|
|
|
|
message: '',
|
|
|
|
error: false,
|
|
|
|
},
|
|
|
|
{
|
|
|
|
time: new Date('2020-08-06T04:06:00'),
|
|
|
|
hasCount: false,
|
|
|
|
meta: { prop: { deep: true }, five: 5 },
|
|
|
|
message: 'Something went wrong',
|
|
|
|
error: true,
|
|
|
|
},
|
|
|
|
{
|
|
|
|
time: new Date('2020-08-05T04:06:00'),
|
|
|
|
hasCount: false,
|
|
|
|
meta: {},
|
|
|
|
message: 'Something insightful',
|
|
|
|
error: false,
|
|
|
|
},
|
|
|
|
];
|
|
|
|
|
2021-12-28 14:45:20 +00:00
|
|
|
test('each event is rendered as an annotation', async function (assert) {
|
2021-12-28 19:30:38 +00:00
|
|
|
assert.expect(2);
|
|
|
|
|
2020-08-05 04:28:11 +00:00
|
|
|
this.set('events', events);
|
|
|
|
await render(hbs`<ScaleEventsChart @events={{this.events}} />`);
|
|
|
|
|
|
|
|
assert.equal(
|
|
|
|
findAll('[data-test-annotation]').length,
|
2021-12-28 14:45:20 +00:00
|
|
|
events.filter((ev) => ev.count == null).length
|
2020-08-05 04:28:11 +00:00
|
|
|
);
|
2020-08-25 15:56:02 +00:00
|
|
|
await componentA11yAudit(this.element, assert);
|
2020-08-05 04:28:11 +00:00
|
|
|
});
|
|
|
|
|
2021-12-28 14:45:20 +00:00
|
|
|
test('clicking an annotation presents details for the event', async function (assert) {
|
2021-12-28 19:30:38 +00:00
|
|
|
assert.expect(6);
|
|
|
|
|
2021-12-28 14:45:20 +00:00
|
|
|
const annotation = events.rejectBy('hasCount').sortBy('time').reverse()[0];
|
2020-08-05 04:28:11 +00:00
|
|
|
|
|
|
|
this.set('events', events);
|
|
|
|
await render(hbs`<ScaleEventsChart @events={{this.events}} />`);
|
|
|
|
|
|
|
|
assert.notOk(find('[data-test-event-details]'));
|
|
|
|
await click('[data-test-annotation] button');
|
|
|
|
|
|
|
|
assert.ok(find('[data-test-event-details]'));
|
|
|
|
assert.equal(
|
|
|
|
find('[data-test-timestamp]').textContent,
|
|
|
|
moment(annotation.time).format('MMM DD HH:mm:ss ZZ')
|
|
|
|
);
|
|
|
|
assert.equal(find('[data-test-message]').textContent, annotation.message);
|
|
|
|
assert.equal(
|
|
|
|
getCodeMirrorInstance('[data-test-json-viewer]').getValue(),
|
|
|
|
JSON.stringify(annotation.meta, null, 2)
|
|
|
|
);
|
2020-08-25 15:56:02 +00:00
|
|
|
|
|
|
|
await componentA11yAudit(this.element, assert);
|
2020-08-05 04:28:11 +00:00
|
|
|
});
|
|
|
|
|
2021-12-28 14:45:20 +00:00
|
|
|
test('clicking an active annotation closes event details', async function (assert) {
|
2020-08-05 04:28:11 +00:00
|
|
|
this.set('events', events);
|
|
|
|
|
|
|
|
await render(hbs`<ScaleEventsChart @events={{this.events}} />`);
|
|
|
|
assert.notOk(find('[data-test-event-details]'));
|
|
|
|
|
|
|
|
await click('[data-test-annotation] button');
|
|
|
|
assert.ok(find('[data-test-event-details]'));
|
|
|
|
|
|
|
|
await click('[data-test-annotation] button');
|
|
|
|
assert.notOk(find('[data-test-event-details]'));
|
|
|
|
});
|
|
|
|
});
|