mirror of
https://github.com/PR0M3TH3AN/bitvid.git
synced 2026-10-27 07:52:24 +00:00
Add shared Playwright UI test helpers
This commit is contained in:
1 parent
59f09e5149
commit
710c9d8ded
4 files changed
+56
-32
No files matched your search
@@ -0,0 +1,38 @@
|
||||
import type { Page } from "@playwright/test";
|
||||
|
||||
export async function applyReducedMotion(page: Page): Promise<void> {
|
||||
await page.emulateMedia({ reducedMotion: "reduce" });
|
||||
await page.addStyleTag({
|
||||
content: `
|
||||
* {
|
||||
animation-duration: 0s !important;
|
||||
animation-delay: 0s !important;
|
||||
transition-duration: 0s !important;
|
||||
transition-delay: 0s !important;
|
||||
}
|
||||
`,
|
||||
});
|
||||
}
|
||||
|
||||
export function failOnConsoleErrors(page: Page): void {
|
||||
page.on("console", (message) => {
|
||||
if (message.type() === "error") {
|
||||
throw new Error(`Console error: ${message.text()}`);
|
||||
}
|
||||
});
|
||||
|
||||
page.on("pageerror", (error) => {
|
||||
throw error;
|
||||
});
|
||||
}
|
||||
|
||||
export async function forceOpenModal(page: Page, selector: string): Promise<void> {
|
||||
await page.evaluate((modalSelector) => {
|
||||
const element = document.querySelector(modalSelector);
|
||||
if (!element) {
|
||||
return;
|
||||
}
|
||||
element.classList.remove("hidden");
|
||||
element.setAttribute("data-open", "true");
|
||||
}, selector);
|
||||
}
|
||||
@@ -1,9 +1,11 @@
|
||||
import { expect, test } from "@playwright/test";
|
||||
import type { Locator } from "@playwright/test";
|
||||
import { applyReducedMotion, failOnConsoleErrors } from "./helpers/uiTestUtils";
|
||||
|
||||
test.describe("popover layout scenarios", () => {
|
||||
test.beforeEach(async ({ page }) => {
|
||||
await page.emulateMedia({ reducedMotion: "reduce" });
|
||||
await applyReducedMotion(page);
|
||||
failOnConsoleErrors(page);
|
||||
await page.goto("/docs/popover-scenarios.html", { waitUntil: "networkidle" });
|
||||
});
|
||||
|
||||
@@ -150,13 +152,6 @@ test.describe("popover layout scenarios", () => {
|
||||
});
|
||||
|
||||
test("stress tests popover triggers without console errors", async ({ page }) => {
|
||||
const consoleErrors: string[] = [];
|
||||
page.on("console", (message) => {
|
||||
if (message.type() === "error") {
|
||||
consoleErrors.push(message.text());
|
||||
}
|
||||
});
|
||||
|
||||
await page.locator('[data-test-open-modal]').click();
|
||||
await expect(page.locator('[data-test-modal]')).toBeVisible();
|
||||
|
||||
@@ -180,15 +175,14 @@ test.describe("popover layout scenarios", () => {
|
||||
await page.click("body");
|
||||
await page.waitForTimeout(60);
|
||||
await expect(page.locator('[data-popover-state="open"]')).toHaveCount(0);
|
||||
expect(consoleErrors).toHaveLength(0);
|
||||
consoleErrors.length = 0;
|
||||
}
|
||||
});
|
||||
});
|
||||
|
||||
test.describe("popover demo alignments", () => {
|
||||
test.beforeEach(async ({ page }) => {
|
||||
await page.emulateMedia({ reducedMotion: "reduce" });
|
||||
await applyReducedMotion(page);
|
||||
failOnConsoleErrors(page);
|
||||
await page.goto("/views/dev/popover-demo.html", { waitUntil: "networkidle" });
|
||||
});
|
||||
|
||||
|
||||
@@ -1,8 +1,10 @@
|
||||
import { expect, test } from "@playwright/test";
|
||||
import { applyReducedMotion, failOnConsoleErrors } from "./helpers/uiTestUtils";
|
||||
|
||||
test.describe("toast service in full DOM", () => {
|
||||
test("renders, expires, and dismisses toasts", async ({ page }) => {
|
||||
await page.emulateMedia({ reducedMotion: "reduce" });
|
||||
await applyReducedMotion(page);
|
||||
failOnConsoleErrors(page);
|
||||
await page.goto("/docs/kitchen-sink.html", { waitUntil: "networkidle" });
|
||||
|
||||
await page.addScriptTag({
|
||||
|
||||
+10
-20
@@ -1,19 +1,15 @@
|
||||
import { expect, test } from "@playwright/test";
|
||||
import {
|
||||
applyReducedMotion,
|
||||
failOnConsoleErrors,
|
||||
forceOpenModal,
|
||||
} from "./helpers/uiTestUtils";
|
||||
|
||||
test.describe("login modal flows", () => {
|
||||
test.beforeEach(async ({ page }) => {
|
||||
await page.emulateMedia({ reducedMotion: "reduce" });
|
||||
await applyReducedMotion(page);
|
||||
failOnConsoleErrors(page);
|
||||
await page.goto("/components/login-modal.html", { waitUntil: "networkidle" });
|
||||
await page.addStyleTag({
|
||||
content: `
|
||||
* {
|
||||
animation-duration: 0s !important;
|
||||
animation-delay: 0s !important;
|
||||
transition-duration: 0s !important;
|
||||
transition-delay: 0s !important;
|
||||
}
|
||||
`,
|
||||
});
|
||||
|
||||
await page.addScriptTag({
|
||||
type: "module",
|
||||
@@ -175,7 +171,8 @@ test.describe("component modal pages", () => {
|
||||
|
||||
for (const pageName of modalPages) {
|
||||
test(`closes ${pageName} modal`, async ({ page }) => {
|
||||
await page.emulateMedia({ reducedMotion: "reduce" });
|
||||
await applyReducedMotion(page);
|
||||
failOnConsoleErrors(page);
|
||||
await page.goto(`/components/${pageName}.html`, {
|
||||
waitUntil: "networkidle",
|
||||
});
|
||||
@@ -183,14 +180,7 @@ test.describe("component modal pages", () => {
|
||||
const modal = page.locator(".bv-modal");
|
||||
await expect(modal).toHaveCount(1);
|
||||
|
||||
await page.evaluate(() => {
|
||||
const element = document.querySelector(".bv-modal");
|
||||
if (!element) {
|
||||
return;
|
||||
}
|
||||
element.classList.remove("hidden");
|
||||
element.setAttribute("data-open", "true");
|
||||
});
|
||||
await forceOpenModal(page, ".bv-modal");
|
||||
|
||||
await expect(modal).not.toHaveClass(/hidden/);
|
||||
|
||||
|
||||
Reference in new issue
Block a user