-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathresponsive.spec.ts
More file actions
51 lines (41 loc) · 1.65 KB
/
responsive.spec.ts
File metadata and controls
51 lines (41 loc) · 1.65 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
/**
* Responsive sidebar and dark mode E2E tests.
*/
import { test, expect } from "@playwright/test";
import { registerUser } from "./helpers/auth";
test.describe("Responsive & Theme", () => {
test("mobile viewport: hamburger opens sidebar, nav link closes it", async ({
page,
}) => {
// Set mobile viewport
await page.setViewportSize({ width: 375, height: 812 });
await registerUser(page);
// Desktop sidebar should be hidden
const desktopSidebar = page.locator("aside.hidden");
await expect(desktopSidebar).not.toBeVisible();
// Hamburger should be visible
const hamburger = page.getByLabel("Toggle menu");
await expect(hamburger).toBeVisible();
// Click hamburger → sidebar opens
await hamburger.click();
const navLink = page.getByRole("link", { name: "Documents" }).first();
await expect(navLink).toBeVisible({ timeout: 5000 });
// Click a nav link → sidebar closes and navigates
await navLink.click();
await expect(page).toHaveURL(/\/documents/);
});
test("dark mode toggle changes theme and persists", async ({ page }) => {
await registerUser(page);
// Toggle to dark mode
const themeToggle = page.getByLabel("Toggle theme");
await expect(themeToggle).toBeVisible();
await themeToggle.click();
// Check html has dark class
const htmlClass = await page.locator("html").getAttribute("class");
expect(htmlClass).toContain("dark");
// Navigate to another page — theme should persist
await page.goto("/documents");
const htmlClassAfterNav = await page.locator("html").getAttribute("class");
expect(htmlClassAfterNav).toContain("dark");
});
});