annotations_srv_specs.jest.ts 2.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970
  1. import { makeRegions, dedupAnnotations } from '../events_processing';
  2. describe('Annotations', () => {
  3. describe('Annotations regions', () => {
  4. let testAnnotations: any[];
  5. beforeEach(() => {
  6. testAnnotations = [
  7. { id: 1, time: 1 },
  8. { id: 2, time: 2 },
  9. { id: 3, time: 3, regionId: 3 },
  10. { id: 4, time: 5, regionId: 3 },
  11. { id: 5, time: 4, regionId: 5 },
  12. { id: 6, time: 8, regionId: 5 },
  13. ];
  14. });
  15. it('should convert single region events to regions', () => {
  16. const range = { from: 0, to: 10 };
  17. const expectedAnnotations = [
  18. { id: 3, regionId: 3, isRegion: true, time: 3, timeEnd: 5 },
  19. { id: 5, regionId: 5, isRegion: true, time: 4, timeEnd: 8 },
  20. { id: 1, time: 1 },
  21. { id: 2, time: 2 },
  22. ];
  23. let regions = makeRegions(testAnnotations, { range: range });
  24. expect(regions).toEqual(expectedAnnotations);
  25. });
  26. it('should cut regions to current time range', () => {
  27. const range = { from: 0, to: 8 };
  28. testAnnotations = [{ id: 5, time: 4, regionId: 5 }];
  29. const expectedAnnotations = [{ id: 5, regionId: 5, isRegion: true, time: 4, timeEnd: 7 }];
  30. let regions = makeRegions(testAnnotations, { range: range });
  31. expect(regions).toEqual(expectedAnnotations);
  32. });
  33. });
  34. describe('Annotations deduplication', () => {
  35. it('should remove duplicated annotations', () => {
  36. const testAnnotations = [
  37. { id: 1, time: 1 },
  38. { id: 2, time: 2 },
  39. { id: 2, time: 2 },
  40. { id: 5, time: 5 },
  41. { id: 5, time: 5 },
  42. ];
  43. const expectedAnnotations = [{ id: 1, time: 1 }, { id: 2, time: 2 }, { id: 5, time: 5 }];
  44. let deduplicated = dedupAnnotations(testAnnotations);
  45. expect(deduplicated).toEqual(expectedAnnotations);
  46. });
  47. it('should leave non "panel-alert" event if present', () => {
  48. const testAnnotations = [
  49. { id: 1, time: 1 },
  50. { id: 2, time: 2 },
  51. { id: 2, time: 2, eventType: 'panel-alert' },
  52. { id: 5, time: 5 },
  53. { id: 5, time: 5 },
  54. ];
  55. const expectedAnnotations = [{ id: 1, time: 1 }, { id: 2, time: 2 }, { id: 5, time: 5 }];
  56. let deduplicated = dedupAnnotations(testAnnotations);
  57. expect(deduplicated).toEqual(expectedAnnotations);
  58. });
  59. });
  60. });