Skip to content

Commit

Permalink
Added screenshot testing for /privacy
Browse files Browse the repository at this point in the history
  • Loading branch information
EthanThatOneKid committed Oct 12, 2022
1 parent 4529afc commit a39fff3
Show file tree
Hide file tree
Showing 7 changed files with 50 additions and 0 deletions.
50 changes: 50 additions & 0 deletions src/routes/(site)/privacy/page.test.ts
@@ -1,8 +1,58 @@
import type { TestInfo } from '@playwright/test';
import { expect, test } from '@playwright/test';
import path from 'node:path';

test.describe.configure({ mode: 'parallel' });

// setupSnapshot is a helper that creates handles the necessary boilerplate
// for snapshot testing. It returns a function that can be called after the
// snapshot test has executed.
//
// See:
// https://github.com/microsoft/playwright/issues/14527#issuecomment-1143352769
export function setupSnapshot(testInfo: TestInfo) {
const snapshotDir = testInfo.snapshotDir;
const snapshotSuffix = testInfo.snapshotSuffix;
const projectName = testInfo.project.name;

testInfo.snapshotDir = path.resolve(snapshotDir, '..', 'screenshots');
testInfo.snapshotSuffix = '';
testInfo.project.name = '';

return {
data: { projectName },
cleanupSnapshot() {
testInfo.snapshotDir = snapshotDir;
testInfo.snapshotSuffix = snapshotSuffix;
testInfo.project.name = projectName;
},
};
}

test('privacy page has expected h1', async ({ page }) => {
await page.goto('/privacy');
expect(await page.textContent('h1')).toBe('Privacy Policy');
});

test('events page matches screenshot', async ({ page }, testInfo) => {
const { cleanupSnapshot, data } = setupSnapshot(testInfo);

if (testInfo.project.use.viewport) {
await page.setViewportSize(testInfo.project.use.viewport);
}

if (testInfo.project.use.colorScheme) {
await page.emulateMedia({
colorScheme: testInfo.project.use.colorScheme,
});
}

await page.goto('/privacy', { waitUntil: 'networkidle' });
expect(await page.screenshot({ fullPage: true })).toMatchSnapshot({
name: `page-${data.projectName}.png`,
maxDiffPixelRatio: 0.1,
threshold: 1,
});

cleanupSnapshot();
});
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.

0 comments on commit a39fff3

Please sign in to comment.