Repository navigation
Expand file tree
/
Copy pathtest.ts
More file actions
79 lines (72 loc) · 2.64 KB
/
Copy pathtest.ts
File metadata and controls
79 lines (72 loc) · 2.64 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
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
import { readFileSync } from "node:fs";
import { test as base, expect } from "@playwright/test";
import { STATE_FILE, type ServerState } from "./paths";
function readState(): ServerState {
return JSON.parse(readFileSync(STATE_FILE, "utf8"));
}
interface Fixtures {
/** Absolute path to the temp sessions dir the server watches (for mutating tests). */
sessionsDir: string;
}
export const test = base.extend<Fixtures>({
// Override baseURL from the running server discovered in global-setup.
baseURL: async ({}, use) => {
await use(readState().baseURL);
},
sessionsDir: async ({}, use) => {
await use(readState().sessionsDir);
},
// Belt-and-suspenders for the cat gatekeeper: global-setup disables it
// server-side, but settings hydrate asynchronously, so also set localStorage
// before any page script runs to cover the synchronous pre-hydration read.
page: async ({ page }, use) => {
await page.addInitScript(() => {
try {
localStorage.setItem("pi-web:v1:cat:enabled", "false");
// Mirror the server-seeded "show all" artifact filter for the synchronous
// pre-hydration read. Filter tests override this with their own init script.
localStorage.setItem("pi-web:v1:artifacts:include", "");
} catch {
/* ignore */
}
});
await use(page);
},
});
/**
* Resolve the active layout at runtime. Layout follows the 900px breakpoint,
* not the device type — iPad portrait (810px) is mobile, landscape (~1080px)
* is desktop — so callers must check this AFTER navigating to a real page
* (matchMedia on about:blank does not reflect the project viewport).
*/
export async function isMobileLayout(
page: import("@playwright/test").Page,
): Promise<boolean> {
return page.evaluate(() => window.matchMedia("(max-width: 900px)").matches);
}
/**
* Start with the scratchpad (right sidebar) collapsed. On narrow viewports it
* otherwise overlays the header/composer and intercepts clicks. Must be called
* before navigating (it installs an init script read by the page's bootstrap).
*/
export async function collapseScratchpad(
page: import("@playwright/test").Page,
): Promise<void> {
await page.addInitScript(() => {
try {
localStorage.setItem("pi-web:v1:right-sidebar-collapsed", "true");
} catch {
/* ignore */
}
});
}
export async function openSessionOutline(
page: import("@playwright/test").Page,
): Promise<void> {
const outlineTab = page.locator(
'[role="tab"][aria-controls="sidebar-outline-panel"]',
);
await outlineTab.dispatchEvent("click");
await expect(outlineTab).toHaveAttribute("aria-selected", "true");
}
export { expect };