From 18710caafb744545c195da48ea9f3aeb7657ae48 Mon Sep 17 00:00:00 2001 From: Wolfram Hofmeister Date: Wed, 4 Dec 2024 15:23:08 +0100 Subject: [PATCH] Add missing unit test cases Co-authored-by: Mukul Mishra --- spec/tests/ConvivaAnalytics.spec.ts | 14 +++++++++ spec/tests/ConvivaAnalyticsTracker.spec.ts | 35 +++++++++++++++++++++- 2 files changed, 48 insertions(+), 1 deletion(-) diff --git a/spec/tests/ConvivaAnalytics.spec.ts b/spec/tests/ConvivaAnalytics.spec.ts index 5a16b53..e4ebf48 100644 --- a/spec/tests/ConvivaAnalytics.spec.ts +++ b/spec/tests/ConvivaAnalytics.spec.ts @@ -522,6 +522,20 @@ describe(ConvivaAnalytics, () => { Conviva.Constants.ErrorSeverity.WARNING ); }) + + it('reports ad break ended when restoring content', () => { + playerEventHelper.fireRestoringContentEvent(); + + expect(MockHelper.latestVideoAnalytics.reportAdBreakEnded).toHaveBeenCalledTimes(1); + }); + + it('reports the playback metric on ad finished', () => { + (MockHelper.latestVideoAnalytics.reportPlaybackMetric as jest.Mock).mockReset(); + + playerEventHelper.fireAdBreakFinishedEvent(); + + expect(MockHelper.latestVideoAnalytics.reportPlaybackMetric).toHaveBeenCalledTimes(1); + }); }); }) diff --git a/spec/tests/ConvivaAnalyticsTracker.spec.ts b/spec/tests/ConvivaAnalyticsTracker.spec.ts index fd1f811..0011cf3 100644 --- a/spec/tests/ConvivaAnalyticsTracker.spec.ts +++ b/spec/tests/ConvivaAnalyticsTracker.spec.ts @@ -77,6 +77,40 @@ describe(ConvivaAnalyticsTracker, () => { expect(invokedTimesAfter).toBe(invokedTimesBefore); }) + it('should report ad break ended on RestoringContent event', () => { + const { playerMock, playerEventHelper } = MockHelper.createPlayerMock(); + const convivaAnalyticsTracker = new ConvivaAnalyticsTracker('test-key'); + + convivaAnalyticsTracker.attachPlayer(playerMock); + playerEventHelper.firePlayEvent(); + convivaAnalyticsTracker.trackRestoringContent(); + + expect(MockHelper.latestVideoAnalytics.reportAdBreakEnded).toHaveBeenCalledTimes(1); + }); + + it('should not report the player state on AdBreakFinished events if there is still an active ad', () => { + const { playerMock, playerEventHelper } = MockHelper.createPlayerMock(); + const convivaAnalyticsTracker = new ConvivaAnalyticsTracker('test-key'); + + convivaAnalyticsTracker.attachPlayer(playerMock); + playerEventHelper.fireAdBreakFinishedEvent(); + convivaAnalyticsTracker.trackAdBreakFinished(); + + expect(MockHelper.latestVideoAnalytics.reportPlaybackMetric).not.toHaveBeenCalled(); + }); + + it('should report the player state on AdBreakFinished events if there is no active ad', () => { + const { playerMock, playerEventHelper } = MockHelper.createPlayerMock(); + const convivaAnalyticsTracker = new ConvivaAnalyticsTracker('test-key'); + + convivaAnalyticsTracker.attachPlayer(playerMock); + playerEventHelper.firePlayEvent(); + convivaAnalyticsTracker.trackRestoringContent(); + convivaAnalyticsTracker.trackAdBreakFinished(); + + expect(MockHelper.latestVideoAnalytics.reportPlaybackMetric).toHaveBeenCalled(); + }); + describe('trackPlaybackStateChanged', () => { let convivaAnalyticsTracker: ConvivaAnalyticsTracker; @@ -112,7 +146,6 @@ describe(ConvivaAnalyticsTracker, () => { PlayerEvent.StallEnded, PlayerEvent.PlaybackFinished, PlayerEvent.AdStarted, - PlayerEvent.AdBreakFinished, ])('should clear timer for stalling when reported player event is %s', (event) => { const stallTrackingStopTimeoutSpy = jest.spyOn(convivaAnalyticsTracker['stallTrackingTimeout'], 'clear');