Skip to content

Commit

Permalink
test(integration): add a case for the welcome message
Browse files Browse the repository at this point in the history
Adds a test case for checking that new visitors see a welcome message.

Refs #388
  • Loading branch information
thewilkybarkid committed Aug 24, 2021
1 parent db0815f commit db89b41
Show file tree
Hide file tree
Showing 4 changed files with 48 additions and 1 deletion.
12 changes: 12 additions & 0 deletions integration/src/home.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,18 @@ import { test, expect } from '@playwright/test';
import { screenshot } from './utils';

test.describe('homepage', () => {
test('shows a welcome message to first-time visitors', async ({ page }) => {
await page.goto('/');

const welcome = await page.waitForSelector('[aria-label="welcome"]');

expect(await welcome.innerText()).toContain(
'Welcome to the new PREreview.org',
);

expect(await screenshot(page, welcome)).toMatchSnapshot('welcome.png');
});

test('looks correct', async ({ page }) => {
await page.goto('/');
await page.click(':text("Get started")');
Expand Down
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
31 changes: 30 additions & 1 deletion integration/src/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,13 @@ async function hideTwitterTimelines(page: Page) {
async function resetCarousels(page: Page) {
const carouselControls = await page.$$('.slick-dots :text("1")');

await Promise.all(carouselControls.map(controls => controls.click()));
await Promise.all(
carouselControls.map(async controls => {
if (await isIntersectingViewport(controls)) {
await controls.click();
}
}),
);
}

async function removeTransitions(page: Page) {
Expand All @@ -66,3 +72,26 @@ async function removeTransitions(page: Page) {
`,
});
}

async function isIntersectingViewport(element: ElementHandle<Element>) {
const visibleRatio = await getVisibleRatio(element);

return visibleRatio > 0;
}

async function getVisibleRatio(element: ElementHandle<Element>) {
return await element.evaluate(async element => {
return await new Promise<number>(resolve => {
const observer = new IntersectionObserver(entries => {
resolve(entries[0].intersectionRatio);
observer.disconnect();
});

observer.observe(element);

requestAnimationFrame(() => {
// Do nothing
});
});
});
}

0 comments on commit db89b41

Please sign in to comment.