@aller/blink
Version:
A library for tracking user behaviour.
125 lines (110 loc) • 3 kB
text/typescript
import createBlink, { VideoLoadInput } from '../main';
import { VERSION } from '../config/config';
import jest from 'jest-mock';
import { BlinkEvent } from '../types';
describe('Video load integration test', () => {
it('should send a single video load event', () => {
const mockSend = jest.fn();
const blink = createBlink({
send: mockSend,
sendDirect: mockSend,
});
// First send of a pageInit event, to set the general state
blink.pageInit({
url: 'http://some.site',
pageView: 'the-pageview-id',
referrer: 'www.sol.no',
site: 'www.kk.no',
});
const input: VideoLoadInput = {
videoId: '123',
duration: 25.4,
position: 11.2,
time: new Date(2),
title: 'Test video title',
width: 720,
height: 480,
viewable: true,
muted: false,
quality: '720p',
withAdBlock: false,
canBeSticky: false,
};
blink.videoLoad(input);
const expectedEvent: BlinkEvent = {
// generic fields
id: '123',
videoId: '123',
type: 'videoLoad',
pageView: 'the-pageview-id',
referrer: 'www.sol.no',
site: 'www.kk.no',
version: VERSION,
// video specific fields
time: new Date(2),
title: 'Test video title',
width: 720,
height: 480,
videoDuration: 25.4,
videoViewable: true,
videoPlayMuted: false,
videoPlayPosition: 11.2,
videoQuality: '720p',
withAdBlock: false,
canBeSticky: false,
};
expect(mockSend.mock.calls[0][0]).toEqual([expectedEvent]);
});
it('should send a single video load event (with sticky)', () => {
const mockSend = jest.fn();
const blink = createBlink({
send: mockSend,
sendDirect: mockSend,
});
// First send of a pageInit event, to set the general state
blink.pageInit({
url: 'http://some.site',
pageView: 'the-pageview-id',
referrer: 'www.sol.no',
site: 'www.kk.no',
});
const input: VideoLoadInput = {
videoId: '123',
duration: 25.4,
position: 11.2,
time: new Date(2),
title: 'Test video title',
width: 720,
height: 480,
viewable: true,
muted: false,
quality: '720p',
withAdBlock: false,
canBeSticky: true,
};
blink.videoLoad(input);
const expectedEvent: BlinkEvent = {
// generic fields
id: '123',
videoId: '123',
type: 'videoLoad',
pageView: 'the-pageview-id',
referrer: 'www.sol.no',
site: 'www.kk.no',
version: VERSION,
// video specific fields
time: new Date(2),
title: 'Test video title',
width: 720,
height: 480,
videoDuration: 25.4,
videoViewable: true,
videoPlayMuted: false,
videoPlayPosition: 11.2,
videoQuality: '720p',
withAdBlock: false,
canBeSticky: true,
};
expect(mockSend.mock.calls[0][0]).toEqual([expectedEvent]);
});
});