e2e(standalone): settings change not intercepted

This commit is contained in:
Elian Doran
2026-04-19 18:42:57 +03:00
parent 1e4c6eb12c
commit 7fd50a2c6e

View File

@@ -162,18 +162,25 @@ export default class App {
}
async setOption(key: string, value: string) {
const csrfToken = await this.page.evaluate(() => {
return (window as any).glob.csrfToken;
});
expect(csrfToken).toBeTruthy();
await expect(
await this.page.request.put(`${getBaseUrl()}/api/options/${key}/${value}`, {
// Issue the request from inside the page so standalone's service worker
// intercepts it and routes to the local SQLite worker. Playwright's own
// request client (page.request.*) bypasses the page entirely, which in
// standalone mode just hits the vite preview server and gets 404.
const result = await this.page.evaluate(async ({ key, value }) => {
const csrfToken = (window as any).glob.csrfToken;
if (!csrfToken) {
return { ok: false, status: 0, error: "missing csrfToken" };
}
const response = await fetch(`/api/options/${encodeURIComponent(key)}/${encodeURIComponent(value)}`, {
method: "PUT",
headers: {
"x-csrf-token": csrfToken
}
})
).toBeOK();
});
return { ok: response.ok, status: response.status };
}, { key, value });
expect(result.ok, `PUT /api/options/${key}/${value} failed (status=${result.status})`).toBe(true);
}
dropdown(_locator: Locator): DropdownLocator {