-
Notifications
You must be signed in to change notification settings - Fork 4
Expand file tree
/
Copy pathsnapshot.spec.ts
More file actions
60 lines (51 loc) · 1.97 KB
/
snapshot.spec.ts
File metadata and controls
60 lines (51 loc) · 1.97 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
import { test, expect } from "@playwright/test";
import path from "path";
import fs from "fs";
import {
iteratePagesAndContexts
} from "../data/pagesAndContexts";
import { pagesAndContexts } from "../../src/config/pages-and-contexts";
test.describe.parallel("Snapshot tests", () => {
test.setTimeout(120000);
iteratePagesAndContexts(
(pageName, context, language, url) => {
test(`Snapshot test for ${pageName}, context ${context} and language ${language}`, async ({ page }) => {
let screenshotContext = "";
if (context !== undefined) {
screenshotContext = `-${context}`;
}
const screenshotFilename = `${pageName}-${language}${screenshotContext}.jpeg`;
await page.goto(url);
// Open all summaries on the page
const allSummaries = await page.locator("details summary").all();
for (const summary of allSummaries) {
await summary.click();
}
// Make sure that all the summary details are visible
const allSummaryDetails = await page.locator("details div").all();
for (const details of allSummaryDetails) {
await details.waitFor();
}
const actualScreenshot = await page.screenshot({fullPage: true, type: "jpeg", quality: 20});
expect(actualScreenshot).toMatchSnapshot(screenshotFilename, {threshold: 0.25});
});
}
);
test("All templates have snapshot tests", async () => {
const directoryPath = path.join(__dirname, "/../../views/ipv/page");
const missingTemplates: string[] = [];
fs.readdir(directoryPath, function (err, files) {
if (err) {
throw err;
}
const testedTemplates = Object.keys(pagesAndContexts);
for (const file of files) {
const templateName = path.parse(file).name;
if (!testedTemplates.find(tt => tt === templateName)) {
missingTemplates.push(templateName);
}
}
expect(missingTemplates).toStrictEqual([]);
});
});
});