Skip to content

Commit

Permalink
Test timestamps when showing tab
Browse files Browse the repository at this point in the history
  • Loading branch information
asakusuma committed Aug 18, 2021
1 parent ee6b2ef commit c8a9111
Showing 1 changed file with 21 additions and 1 deletion.
22 changes: 21 additions & 1 deletion test/playwright/modules/spaniel-observer-tests.ts
Original file line number Diff line number Diff line change
@@ -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 }) => {
Expand Down Expand Up @@ -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<SpanielObserverEntry>(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() {
Expand Down

0 comments on commit c8a9111

Please sign in to comment.