mirror of
https://github.com/PeWu/topola-viewer.git
synced 2026-05-26 15:16:14 +00:00
Add screenshot tests
This commit is contained in:
37
tests/intro_visual.spec.ts
Normal file
37
tests/intro_visual.spec.ts
Normal file
@@ -0,0 +1,37 @@
|
||||
import {expect, test} from '@playwright/test';
|
||||
import {blockTracking} from './helpers';
|
||||
|
||||
test.describe('Intro page visual validation @visual', () => {
|
||||
test.beforeEach(async ({page, context}) => {
|
||||
await blockTracking(context);
|
||||
await page.goto('/');
|
||||
});
|
||||
|
||||
test('intro-page', async ({page}) => {
|
||||
// Clean dynamic elements right before snapping the screenshot.
|
||||
await page.evaluate(() => {
|
||||
// 1. Overwrite dynamic footer versioning.
|
||||
const versionEl = document.querySelector('.version');
|
||||
if (versionEl) {
|
||||
(versionEl as HTMLElement).innerText =
|
||||
'version: 2026-01-01 00:00 (testcommit)';
|
||||
}
|
||||
|
||||
// 2. Replace dynamic changelog block with static placeholder.
|
||||
const headers = Array.from(document.querySelectorAll('h3'));
|
||||
const whatsNewHeader = headers.find((h) =>
|
||||
h.textContent?.includes("What's new"),
|
||||
);
|
||||
if (whatsNewHeader) {
|
||||
const changelogSpan = whatsNewHeader.nextElementSibling;
|
||||
if (changelogSpan) {
|
||||
changelogSpan.innerHTML =
|
||||
'<h4>2026-01-01</h4><ul><li>Placeholder change entry</li></ul>';
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
// Snap the screenshot.
|
||||
await expect(page).toHaveScreenshot('intro-page.png');
|
||||
});
|
||||
});
|
||||
Reference in New Issue
Block a user