From c8a911145060f3478e6d2484537c92ddfbfe81cb Mon Sep 17 00:00:00 2001 From: asakusuma Date: Wed, 18 Aug 2021 10:37:07 -0700 Subject: [PATCH] Test timestamps when showing tab --- .../modules/spaniel-observer-tests.ts | 22 ++++++++++++++++++- 1 file changed, 21 insertions(+), 1 deletion(-) diff --git a/test/playwright/modules/spaniel-observer-tests.ts b/test/playwright/modules/spaniel-observer-tests.ts index dc5e74b..0f4b1b3 100644 --- a/test/playwright/modules/spaniel-observer-tests.ts +++ b/test/playwright/modules/spaniel-observer-tests.ts @@ -1,6 +1,6 @@ import { expect, test } from '@playwright/test'; import { SpanielObserverEntry } from '../../../src/interfaces'; -import { getPageAssertions, getPageTime, pageHide, timestampsAreClose } from '../utils'; +import { getPageAssertions, getPageTime, pageHide, pageShow, timestampsAreClose } from '../utils'; function runTests() { test('time for initial events are close to page load time', async ({ page }) => { @@ -32,6 +32,26 @@ function runTests() { timestampsAreClose(loadTime + delay, a.time); } }); + + test('tab shown entries have correct fields', async ({ page }) => { + const loadTime = await getPageTime(page); + const delay = 1500; + const pause = 500; + await page.waitForTimeout(delay); + await pageHide(page); + await page.waitForTimeout(pause); + await pageShow(page); + await page.waitForTimeout(delay); + const assertions = await getPageAssertions(page); + expect(assertions.length).toEqual(6); + // Tab shown events + for (let i = 4; i < assertions.length; i++) { + const a = assertions[i]; + expect(a.isIntersecting).toBeTruthy(); + expect(a.entering).toBeTruthy(); + timestampsAreClose(loadTime + delay + pause, a.time); + } + }); } export function spanielObserverModule() {