import Clip from '../../client' import ClipMediaTrackerAdapter from '../../client/trackingAdapter' describe('ClipMediaTrackerAdapter', () => { let videoElement: HTMLVideoElement let clip: Clip let adapter: ClipMediaTrackerAdapter const createClipStub = (overrides: Partial = {}) => ({ opts: { id: 'clip-id', layout: 'in-line', autoplay: false, systemTitle: 'Clip title', }, loops: 2, canAutoplay: false, autoplayPaused: false, started: false, ...overrides, } as Clip) beforeEach(() => { videoElement = document.createElement('video') Object.defineProperty(videoElement, 'duration', { configurable: true, value: 42.5, }) Object.defineProperty(videoElement, 'currentTime', { configurable: true, writable: true, value: 12.25, }) clip = createClipStub() adapter = new ClipMediaTrackerAdapter(videoElement, clip) }) it('exposes media values used by the SDK', () => { expect(adapter.player).toBe(videoElement) expect(adapter.getCurrentTime()).toBe(12.25) expect(adapter.getDuration()).toBe(42.5) expect(adapter.getMediaId()).toBe('clip-id') expect(adapter.getSourceUrl()).toBe('clip-id') expect(adapter.getVideoType()).toBe('clip') expect(adapter.getVideoLayout()).toBe('in-line') expect(adapter.getLoopCount()).toBe(2) expect(adapter.isAutoplay()).toBe(false) }) it('returns zero duration when media duration is not available', () => { Object.defineProperty(videoElement, 'duration', { configurable: true, value: NaN, }) expect(adapter.getDuration()).toBe(0) }) it('adds and removes event listeners on the media element', () => { const callback = jest.fn() adapter.on('playing', callback) videoElement.dispatchEvent(new Event('playing')) expect(callback).toHaveBeenCalledTimes(1) adapter.off('playing', callback) videoElement.dispatchEvent(new Event('playing')) expect(callback).toHaveBeenCalledTimes(1) }) })