2017-12-19 09:06:54 -06:00
|
|
|
import { makeRegions, dedupAnnotations } from "../events_processing";
|
2017-10-23 08:46:36 -05:00
|
|
|
|
2017-12-19 09:06:54 -06:00
|
|
|
describe("Annotations", () => {
|
|
|
|
describe("Annotations regions", () => {
|
2017-10-23 08:46:36 -05:00
|
|
|
let testAnnotations: any[];
|
|
|
|
|
|
|
|
beforeEach(() => {
|
|
|
|
testAnnotations = [
|
2017-12-19 09:06:54 -06:00
|
|
|
{ id: 1, time: 1 },
|
|
|
|
{ id: 2, time: 2 },
|
|
|
|
{ id: 3, time: 3, regionId: 3 },
|
|
|
|
{ id: 4, time: 5, regionId: 3 },
|
|
|
|
{ id: 5, time: 4, regionId: 5 },
|
|
|
|
{ id: 6, time: 8, regionId: 5 }
|
2017-10-23 08:46:36 -05:00
|
|
|
];
|
|
|
|
});
|
|
|
|
|
2017-12-19 09:06:54 -06:00
|
|
|
it("should convert single region events to regions", () => {
|
|
|
|
const range = { from: 0, to: 10 };
|
2017-10-23 08:46:36 -05:00
|
|
|
const expectedAnnotations = [
|
2017-12-19 09:06:54 -06:00
|
|
|
{ id: 3, regionId: 3, isRegion: true, time: 3, timeEnd: 5 },
|
|
|
|
{ id: 5, regionId: 5, isRegion: true, time: 4, timeEnd: 8 },
|
|
|
|
{ id: 1, time: 1 },
|
|
|
|
{ id: 2, time: 2 }
|
2017-10-23 08:46:36 -05:00
|
|
|
];
|
|
|
|
|
2017-12-19 09:06:54 -06:00
|
|
|
let regions = makeRegions(testAnnotations, { range: range });
|
2017-10-23 08:46:36 -05:00
|
|
|
expect(regions).toEqual(expectedAnnotations);
|
|
|
|
});
|
|
|
|
|
2017-12-19 09:06:54 -06:00
|
|
|
it("should cut regions to current time range", () => {
|
|
|
|
const range = { from: 0, to: 8 };
|
|
|
|
testAnnotations = [{ id: 5, time: 4, regionId: 5 }];
|
2017-10-23 08:46:36 -05:00
|
|
|
const expectedAnnotations = [
|
2017-12-19 09:06:54 -06:00
|
|
|
{ id: 5, regionId: 5, isRegion: true, time: 4, timeEnd: 7 }
|
2017-10-23 08:46:36 -05:00
|
|
|
];
|
|
|
|
|
2017-12-19 09:06:54 -06:00
|
|
|
let regions = makeRegions(testAnnotations, { range: range });
|
2017-10-23 08:46:36 -05:00
|
|
|
expect(regions).toEqual(expectedAnnotations);
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
2017-12-19 09:06:54 -06:00
|
|
|
describe("Annotations deduplication", () => {
|
|
|
|
it("should remove duplicated annotations", () => {
|
2017-10-23 08:46:36 -05:00
|
|
|
const testAnnotations = [
|
2017-12-19 09:06:54 -06:00
|
|
|
{ id: 1, time: 1 },
|
|
|
|
{ id: 2, time: 2 },
|
|
|
|
{ id: 2, time: 2 },
|
|
|
|
{ id: 5, time: 5 },
|
|
|
|
{ id: 5, time: 5 }
|
2017-10-23 08:46:36 -05:00
|
|
|
];
|
|
|
|
const expectedAnnotations = [
|
2017-12-19 09:06:54 -06:00
|
|
|
{ id: 1, time: 1 },
|
|
|
|
{ id: 2, time: 2 },
|
|
|
|
{ id: 5, time: 5 }
|
2017-10-23 08:46:36 -05:00
|
|
|
];
|
|
|
|
|
|
|
|
let deduplicated = dedupAnnotations(testAnnotations);
|
|
|
|
expect(deduplicated).toEqual(expectedAnnotations);
|
|
|
|
});
|
|
|
|
|
|
|
|
it('should leave non "panel-alert" event if present', () => {
|
|
|
|
const testAnnotations = [
|
2017-12-19 09:06:54 -06:00
|
|
|
{ id: 1, time: 1 },
|
|
|
|
{ id: 2, time: 2 },
|
|
|
|
{ id: 2, time: 2, eventType: "panel-alert" },
|
|
|
|
{ id: 5, time: 5 },
|
|
|
|
{ id: 5, time: 5 }
|
2017-10-23 08:46:36 -05:00
|
|
|
];
|
|
|
|
const expectedAnnotations = [
|
2017-12-19 09:06:54 -06:00
|
|
|
{ id: 1, time: 1 },
|
|
|
|
{ id: 2, time: 2 },
|
|
|
|
{ id: 5, time: 5 }
|
2017-10-23 08:46:36 -05:00
|
|
|
];
|
|
|
|
|
|
|
|
let deduplicated = dedupAnnotations(testAnnotations);
|
|
|
|
expect(deduplicated).toEqual(expectedAnnotations);
|
|
|
|
});
|
|
|
|
});
|
|
|
|
});
|