mirror of
https://github.com/kemko/nomad.git
synced 2026-01-03 00:45:43 +03:00
Unit test coverage for the ScaleEventsChart data domain logic
This commit is contained in:
@@ -12,7 +12,7 @@ export default class ScaleEventsChart extends Component {
|
||||
|
||||
@computed('events.[]')
|
||||
get data() {
|
||||
const data = this.events.filterBy('hasCount');
|
||||
const data = this.events.filterBy('hasCount').sortBy('time');
|
||||
|
||||
// Extend the domain of the chart to the current time
|
||||
data.push({
|
||||
@@ -29,7 +29,7 @@ export default class ScaleEventsChart extends Component {
|
||||
});
|
||||
}
|
||||
|
||||
return data.sortBy('time');
|
||||
return data;
|
||||
}
|
||||
|
||||
@computed('events.[]')
|
||||
|
||||
68
ui/tests/unit/components/scale-events-chart-test.js
Normal file
68
ui/tests/unit/components/scale-events-chart-test.js
Normal file
@@ -0,0 +1,68 @@
|
||||
import { module, test } from 'qunit';
|
||||
import { setupTest } from 'ember-qunit';
|
||||
import sinon from 'sinon';
|
||||
|
||||
module('Unit | Component | scale-events-chart', function(hooks) {
|
||||
setupTest(hooks);
|
||||
|
||||
hooks.beforeEach(function() {
|
||||
this.refTime = new Date();
|
||||
this.clock = sinon.useFakeTimers(this.refTime);
|
||||
});
|
||||
|
||||
hooks.afterEach(function() {
|
||||
this.clock.restore();
|
||||
delete this.refTime;
|
||||
});
|
||||
|
||||
test('the current date is appended as a datum for the line chart to render', function(assert) {
|
||||
const chart = this.owner.factoryFor('component:scale-events-chart').create();
|
||||
const events = [
|
||||
{ time: new Date('2020-08-02T04:06:00'), count: 2, hasCount: true },
|
||||
{ time: new Date('2020-08-01T04:06:00'), count: 2, hasCount: true },
|
||||
];
|
||||
|
||||
chart.set('events', events);
|
||||
|
||||
assert.equal(chart.data.length, events.length + 1);
|
||||
assert.deepEqual(chart.data.slice(0, events.length), events.sortBy('time'));
|
||||
|
||||
const appendedDatum = chart.data[chart.data.length - 1];
|
||||
assert.equal(appendedDatum.count, events.sortBy('time').lastObject.count);
|
||||
assert.equal(+appendedDatum.time, +this.refTime);
|
||||
});
|
||||
|
||||
test('if the earliest annotation is outside the domain of the events, the earliest annotation time is added as a datum for the line chart to render', function(assert) {
|
||||
const chart = this.owner.factoryFor('component:scale-events-chart').create();
|
||||
const annotationOutside = [
|
||||
{ time: new Date('2020-08-01T04:06:00'), hasCount: false, error: true },
|
||||
{ time: new Date('2020-08-02T04:06:00'), count: 2, hasCount: true },
|
||||
{ time: new Date('2020-08-03T04:06:00'), count: 2, hasCount: true },
|
||||
];
|
||||
const annotationInside = [
|
||||
{ time: new Date('2020-08-02T04:06:00'), count: 2, hasCount: true },
|
||||
{ time: new Date('2020-08-02T12:06:00'), hasCount: false, error: true },
|
||||
{ time: new Date('2020-08-03T04:06:00'), count: 2, hasCount: true },
|
||||
];
|
||||
|
||||
chart.set('events', annotationOutside);
|
||||
|
||||
assert.equal(chart.data.length, annotationOutside.length + 1);
|
||||
assert.deepEqual(
|
||||
chart.data.slice(1, annotationOutside.length),
|
||||
annotationOutside.filterBy('hasCount')
|
||||
);
|
||||
|
||||
const appendedDatum = chart.data[0];
|
||||
assert.equal(appendedDatum.count, annotationOutside[1].count);
|
||||
assert.equal(+appendedDatum.time, +annotationOutside[0].time);
|
||||
|
||||
chart.set('events', annotationInside);
|
||||
|
||||
assert.equal(chart.data.length, annotationOutside.length);
|
||||
assert.deepEqual(
|
||||
chart.data.slice(0, annotationOutside.length - 1),
|
||||
annotationOutside.filterBy('hasCount')
|
||||
);
|
||||
});
|
||||
});
|
||||
Reference in New Issue
Block a user