diff --git a/tests/e2e/helpers.ts b/tests/e2e/helpers.ts index 439004ec..7b30cbeb 100644 --- a/tests/e2e/helpers.ts +++ b/tests/e2e/helpers.ts @@ -211,6 +211,19 @@ export async function putSettings( return { ok: res.ok(), status: res.status() }; } +/** Upsert the current user's preferences (e.g. reset shared state a spec mutates). */ +export async function putPreferences( + page: Page, + data: Record, +): Promise<{ ok: boolean; status: number }> { + const token = await getAuthToken(page); + const res = await page.request.put("/api/v1/preferences", { + headers: token ? { authorization: `Bearer ${token}` } : {}, + data, + }); + return { ok: res.ok(), status: res.status() }; +} + /** * changePasswordViaApi() — revert a password change without driving the UI. * The current session token survives a password change (the API only revokes diff --git a/tests/e2e/pin-tools.spec.ts b/tests/e2e/pin-tools.spec.ts index 0cc98945..90a92fb0 100644 --- a/tests/e2e/pin-tools.spec.ts +++ b/tests/e2e/pin-tools.spec.ts @@ -1,9 +1,15 @@ -import { expect, test } from "./helpers"; +import { expect, putPreferences, test } from "./helpers"; // Mutates the shared per-user `pinnedTools` preference on the server, so it // pins and then unpins within the single test to leave state clean. test.describe("Pin tools", () => { test("pin a tool, persist across reload, then unpin", async ({ loggedInPage: page }) => { + // Start from a known-empty pin state. CI retries once, and a prior attempt + // that failed after pinning but before unpinning leaves a server-side pin, + // which would fail the "not pinned yet" assertion below on the retry. + expect((await putPreferences(page, { pinnedTools: [] })).ok).toBeTruthy(); + await page.reload(); + // Resize lives under Image > Essentials on the All tab (default). const pinToggle = page.getByTestId("pin-toggle-resize").first(); await expect(pinToggle).toBeVisible();