Skip to content

Commit 7cac40f

Browse files
committed
test(ui): emit custom theme race verdict
1 parent b5dbaf4 commit 7cac40f

1 file changed

Lines changed: 54 additions & 0 deletions

File tree

‎ui/src/e2e/appearance-settings-defaults.e2e.test.ts‎

Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -113,6 +113,28 @@ async function readPersistedSettings(page: Page): Promise<Record<string, unknown
113113
}, settingsStorageKey);
114114
}
115115

116+
async function readThemeImportRaceState(page: Page) {
117+
const importer = page.locator(".settings-theme-import");
118+
const message = importer.locator(".settings-theme-import__message");
119+
const settings = await readPersistedSettings(page);
120+
return {
121+
renderedThemeMode: await page.locator("html").getAttribute("data-theme"),
122+
titleColor: await page
123+
.locator(".page-title")
124+
.evaluate((element) => getComputedStyle(element).color),
125+
clawSelected:
126+
(await page
127+
.locator("#settings-appearance-theme .settings-theme-card--claw")
128+
.getAttribute("aria-pressed")) === "true",
129+
customThemeMetadataCount: await importer.locator(".settings-theme-import__meta").count(),
130+
importUrl: await importer.locator("input").inputValue(),
131+
message: (await message.count()) > 0 ? ((await message.textContent())?.trim() ?? "") : "",
132+
importButtonDisabled: await importer.locator("button.primary").isDisabled(),
133+
persistedTheme: settings.theme ?? null,
134+
hasPersistedCustomTheme: settings.customTheme !== undefined,
135+
};
136+
}
137+
116138
async function captureViewport(page: Page, filename: string): Promise<void> {
117139
if (!captureUiProofEnabled) {
118140
return;
@@ -516,6 +538,7 @@ describeControlUiE2e("Control UI Appearance defaults mocked Gateway E2E", () =>
516538
await expect
517539
.poll(() => importer.locator(".settings-theme-import__meta-value").textContent())
518540
.toContain("Existing Test Theme");
541+
const beforeReplace = await readThemeImportRaceState(page);
519542
await captureViewport(page, "04-custom-theme-before-replace.png");
520543

521544
await importField.fill("replacement");
@@ -528,6 +551,7 @@ describeControlUiE2e("Control UI Appearance defaults mocked Gateway E2E", () =>
528551
.poll(() => themeSection.locator(".settings-theme-card--claw").getAttribute("aria-pressed"))
529552
.toBe("true");
530553
await expect.poll(() => importer.locator(".settings-theme-import__meta").count()).toBe(0);
554+
const afterClear = await readThemeImportRaceState(page);
531555
await captureViewport(page, "05-custom-theme-cleared-with-replace-pending.png");
532556

533557
releaseReplacement();
@@ -545,6 +569,36 @@ describeControlUiE2e("Control UI Appearance defaults mocked Gateway E2E", () =>
545569
await expect
546570
.poll(() => importer.locator(".settings-theme-import__message").textContent())
547571
.toContain("removed");
572+
const afterDelayedResponse = await readThemeImportRaceState(page);
573+
expect(beforeReplace).toMatchObject({
574+
clawSelected: false,
575+
customThemeMetadataCount: 1,
576+
persistedTheme: "custom",
577+
hasPersistedCustomTheme: true,
578+
});
579+
expect(afterClear).toMatchObject({
580+
renderedThemeMode: "dark",
581+
clawSelected: true,
582+
customThemeMetadataCount: 0,
583+
importUrl: "replacement",
584+
importButtonDisabled: false,
585+
persistedTheme: "claw",
586+
hasPersistedCustomTheme: false,
587+
});
588+
expect(beforeReplace.titleColor).not.toBe(afterClear.titleColor);
589+
expect(afterDelayedResponse).toEqual({
590+
...afterClear,
591+
message: "Custom theme removed.",
592+
});
593+
console.info(
594+
`[control-ui-e2e] THEME_IMPORT_RACE_VERDICT ${JSON.stringify({
595+
scenario: "delayed-replace-then-clear",
596+
beforeReplace,
597+
afterClear,
598+
afterDelayedResponse,
599+
pass: true,
600+
})}`,
601+
);
548602
await captureViewport(page, "06-custom-theme-clear-remains-final.png");
549603
} finally {
550604
releaseReplacement();

0 commit comments

Comments
 (0)