From 2a3959e730110bda6e871e682da255d63037d425 Mon Sep 17 00:00:00 2001 From: Giuseppe Samela Date: Tue, 26 Nov 2024 16:11:23 +0100 Subject: [PATCH] Add one more test case --- spec/tests/ConvivaAnalyticsTracker.spec.ts | 22 ++++++++++++++++++++-- 1 file changed, 20 insertions(+), 2 deletions(-) diff --git a/spec/tests/ConvivaAnalyticsTracker.spec.ts b/spec/tests/ConvivaAnalyticsTracker.spec.ts index 68878d9..27bc096 100644 --- a/spec/tests/ConvivaAnalyticsTracker.spec.ts +++ b/spec/tests/ConvivaAnalyticsTracker.spec.ts @@ -168,11 +168,27 @@ describe(ConvivaAnalyticsTracker, () => { expect(reportAdBreakEndedSpy).toHaveBeenCalledTimes(1); }) - it('should not report ad break ended if AdFinished is followed by a new AdStarted', () => { + it('should not report ad break ended twice if AdBreakFinished is emitted after the ad finished timer has already expired', () => { convivaAnalyticsTracker.trackAdBreakStarted(Conviva.Constants.AdType.CLIENT_SIDE); convivaAnalyticsTracker.trackAdStarted({}, Conviva.Constants.AdType.CLIENT_SIDE); convivaAnalyticsTracker.trackAdFinished(); + jest.runAllTimers(); + + expect(reportAdBreakEndedSpy).toHaveBeenCalledTimes(1); + + convivaAnalyticsTracker.trackAdBreakFinished(); + + expect(reportAdBreakEndedSpy).toHaveBeenCalledTimes(1); + }) + + it('should not report ad break ended if AdFinished is followed by a new AdStarted', () => { + convivaAnalyticsTracker.trackAdBreakStarted(Conviva.Constants.AdType.CLIENT_SIDE); + convivaAnalyticsTracker.trackAdStarted({}, Conviva.Constants.AdType.CLIENT_SIDE); + + expect(reportAdBreakStartedSpy).toHaveBeenCalledTimes(1); + + convivaAnalyticsTracker.trackAdFinished(); convivaAnalyticsTracker.trackAdStarted({}, Conviva.Constants.AdType.CLIENT_SIDE); jest.runAllTimers(); @@ -184,11 +200,13 @@ describe(ConvivaAnalyticsTracker, () => { it('should report ad break started again after wrongly reporting ad break ended', () => { convivaAnalyticsTracker.trackAdBreakStarted(Conviva.Constants.AdType.CLIENT_SIDE); convivaAnalyticsTracker.trackAdStarted({}, Conviva.Constants.AdType.CLIENT_SIDE); + + expect(reportAdBreakStartedSpy).toHaveBeenCalledTimes(1); + convivaAnalyticsTracker.trackAdFinished(); jest.runAllTimers(); expect(reportAdBreakEndedSpy).toHaveBeenCalledTimes(1); - expect(reportAdBreakStartedSpy).toHaveBeenCalledTimes(1); convivaAnalyticsTracker.trackAdStarted({}, Conviva.Constants.AdType.CLIENT_SIDE);