Skip to content

Commit

Permalink
Add test for signaling playback state update after AdBreakFinished
Browse files Browse the repository at this point in the history
  • Loading branch information
wasp898 committed Nov 26, 2024
1 parent 2a3959e commit 36476fe
Showing 1 changed file with 20 additions and 0 deletions.
20 changes: 20 additions & 0 deletions spec/tests/ConvivaAnalyticsTracker.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import { PlayerEvent, PlayerEventBase } from "bitmovin-player";
import { ConvivaAnalyticsTracker } from "../../src/ts/ConvivaAnalyticsTracker";
import { MockHelper } from "../helper/MockHelper";
import * as Conviva from '@convivainc/conviva-js-coresdk';
import { PlayerStateHelper } from "../../src/ts/helper/PlayerStateHelper";

jest.mock('@convivainc/conviva-js-coresdk', () => {
const { MockHelper } = jest.requireActual('../helper/MockHelper');
Expand Down Expand Up @@ -212,6 +213,25 @@ describe(ConvivaAnalyticsTracker, () => {

expect(reportAdBreakStartedSpy).toHaveBeenCalledTimes(2);
})

it('should only signal that playback has resumed after the actual AdBreakFinished', () => {
const { AdType, Playback, PlayerState } = Conviva.Constants;
const reportPlaybackSpy = jest.spyOn(convivaAnalyticsTracker['convivaVideoAnalytics'], 'reportPlaybackMetric');
jest.spyOn(PlayerStateHelper, 'getPlayerState').mockReturnValue(PlayerState.PLAYING);

convivaAnalyticsTracker.trackAdBreakStarted(AdType.CLIENT_SIDE);
convivaAnalyticsTracker.trackAdStarted({}, AdType.CLIENT_SIDE);
convivaAnalyticsTracker.trackAdFinished();

jest.runAllTimers();

expect(reportAdBreakEndedSpy).toHaveBeenCalledTimes(1);
expect(reportPlaybackSpy).not.toHaveBeenCalledWith(Playback.PLAYER_STATE, PlayerState.PLAYING);

convivaAnalyticsTracker.trackAdBreakFinished();

expect(reportPlaybackSpy).toHaveBeenCalledWith(Playback.PLAYER_STATE, PlayerState.PLAYING);
})
});
})

Expand Down

0 comments on commit 36476fe

Please sign in to comment.