annotations_srv_specs.jest.ts 2.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980
  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 = [
  30. { id: 5, regionId: 5, isRegion: true, time: 4, timeEnd: 7 },
  31. ];
  32. let regions = makeRegions(testAnnotations, { range: range });
  33. expect(regions).toEqual(expectedAnnotations);
  34. });
  35. });
  36. describe('Annotations deduplication', () => {
  37. it('should remove duplicated annotations', () => {
  38. const testAnnotations = [
  39. { id: 1, time: 1 },
  40. { id: 2, time: 2 },
  41. { id: 2, time: 2 },
  42. { id: 5, time: 5 },
  43. { id: 5, time: 5 },
  44. ];
  45. const expectedAnnotations = [
  46. { id: 1, time: 1 },
  47. { id: 2, time: 2 },
  48. { id: 5, time: 5 },
  49. ];
  50. let deduplicated = dedupAnnotations(testAnnotations);
  51. expect(deduplicated).toEqual(expectedAnnotations);
  52. });
  53. it('should leave non "panel-alert" event if present', () => {
  54. const testAnnotations = [
  55. { id: 1, time: 1 },
  56. { id: 2, time: 2 },
  57. { id: 2, time: 2, eventType: 'panel-alert' },
  58. { id: 5, time: 5 },
  59. { id: 5, time: 5 },
  60. ];
  61. const expectedAnnotations = [
  62. { id: 1, time: 1 },
  63. { id: 2, time: 2 },
  64. { id: 5, time: 5 },
  65. ];
  66. let deduplicated = dedupAnnotations(testAnnotations);
  67. expect(deduplicated).toEqual(expectedAnnotations);
  68. });
  69. });
  70. });