forked from snowplow/snowplow-javascript-tracker
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathvimeo.test.ts
More file actions
54 lines (48 loc) · 1.98 KB
/
Copy pathvimeo.test.ts
File metadata and controls
54 lines (48 loc) · 1.98 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
import {
VimeoEventType,
InternalVimeoEvent,
CapturableInternalVimeoEvents,
AvailableMediaEventType,
} from '../src/events';
import { filterVimeoEvents } from '../src/utils';
import { InternalVimeoTrackingConfiguration } from '../src/types';
describe('Vimeo Tracking', () => {
describe('captureEvents', () => {
// The video element is irrelevant for this test, but a required parameter
const video = document.createElement('iframe');
const alwaysOnEvents = [InternalVimeoEvent.TIMEUPDATE, InternalVimeoEvent.PROGRESS];
const defaultConfiguration: InternalVimeoTrackingConfiguration = {
video,
id: 'test',
captureEvents: Object.values(AvailableMediaEventType),
vimeoCaptureEvents: [...CapturableInternalVimeoEvents, ...alwaysOnEvents],
};
it('assigns defaults if no captureEvents passed', () => {
const trackingOptions = filterVimeoEvents({ video, id: 'test' });
expect(trackingOptions.captureEvents).toEqual(defaultConfiguration.captureEvents);
trackingOptions.vimeoCaptureEvents?.forEach((event) => {
expect(trackingOptions.vimeoCaptureEvents).toContain(event);
});
});
it("doesn't assign default if empty array is passed", () => {
const trackingOptions = filterVimeoEvents({ video, id: 'test', captureEvents: [] });
expect(trackingOptions).toEqual({
...defaultConfiguration,
captureEvents: [],
vimeoCaptureEvents: alwaysOnEvents,
});
});
it('assigns to captureEvents and vimeoCaptureEvents if valid events passed', () => {
const trackingOptions = filterVimeoEvents({
video,
id: 'test',
captureEvents: [AvailableMediaEventType.Play, VimeoEventType.TextTrackChange],
});
expect(trackingOptions).toEqual({
...defaultConfiguration,
captureEvents: [AvailableMediaEventType.Play],
vimeoCaptureEvents: expect.arrayContaining([InternalVimeoEvent.TEXTTRACKCHANGE, ...alwaysOnEvents]),
});
});
});
});