|
| 1 | +import React from "react" |
| 2 | + |
| 3 | +import { expect, test } from "../../../../playwright/coverage-fixture" |
| 4 | +import UpdateTodoListToolBlock from "../UpdateTodoListToolBlock" |
| 5 | +import { SelectDropdown } from "@/components/ui/select-dropdown" |
| 6 | + |
| 7 | +const themes = [ |
| 8 | + { |
| 9 | + name: "dark", |
| 10 | + bodyClass: "vscode-dark", |
| 11 | + themeId: "Default Dark Modern", |
| 12 | + expected: { |
| 13 | + background: "rgb(30, 30, 30)", |
| 14 | + description: "rgb(157, 157, 157)", |
| 15 | + dropdownBorder: "rgb(60, 60, 60)", |
| 16 | + hoverBackground: "rgb(42, 45, 46)", |
| 17 | + focusBorder: "rgb(0, 127, 212)", |
| 18 | + error: "rgb(244, 135, 113)", |
| 19 | + panelBorder: "rgb(43, 43, 43)", |
| 20 | + }, |
| 21 | + }, |
| 22 | + { |
| 23 | + name: "light", |
| 24 | + bodyClass: "vscode-light", |
| 25 | + themeId: "Default Light Modern", |
| 26 | + expected: { |
| 27 | + background: "rgb(255, 255, 255)", |
| 28 | + description: "rgb(113, 113, 113)", |
| 29 | + dropdownBorder: "rgb(206, 206, 206)", |
| 30 | + hoverBackground: "rgb(232, 232, 232)", |
| 31 | + focusBorder: "rgb(0, 144, 241)", |
| 32 | + error: "rgb(161, 38, 13)", |
| 33 | + panelBorder: "rgb(206, 206, 206)", |
| 34 | + }, |
| 35 | + }, |
| 36 | +] as const |
| 37 | + |
| 38 | +for (const theme of themes) { |
| 39 | + test(`renders selectors and confirmation dialogs in the VS Code ${theme.name} theme`, async ({ mount, page }) => { |
| 40 | + await page.evaluate(({ bodyClass, themeId }) => { |
| 41 | + document.documentElement.className = bodyClass |
| 42 | + document.body.className = bodyClass |
| 43 | + document.body.dataset.vscodeThemeId = themeId |
| 44 | + }, theme) |
| 45 | + |
| 46 | + const component = await mount( |
| 47 | + <div className="flex flex-col gap-4 w-96"> |
| 48 | + <SelectDropdown value="code" options={[{ value: "code", label: "Code" }]} onChange={() => undefined} /> |
| 49 | + <UpdateTodoListToolBlock |
| 50 | + todos={[{ id: "todo-1", content: "Ship the follow-up", status: "in_progress" }]} |
| 51 | + onChange={() => undefined} |
| 52 | + /> |
| 53 | + </div>, |
| 54 | + ) |
| 55 | + |
| 56 | + await component.evaluate(async () => { |
| 57 | + await document.fonts.ready |
| 58 | + await new Promise<void>((resolve) => requestAnimationFrame(() => resolve())) |
| 59 | + }) |
| 60 | + |
| 61 | + await expect(component).toHaveScreenshot(`chat-controls-resting-${theme.name}.png`) |
| 62 | + |
| 63 | + const trigger = component.getByTestId("dropdown-trigger") |
| 64 | + await expect(trigger).toHaveCSS("border-color", theme.expected.dropdownBorder) |
| 65 | + await trigger.hover() |
| 66 | + await expect(trigger).toHaveCSS("background-color", theme.expected.hoverBackground) |
| 67 | + await expect(trigger).toHaveCSS("border-color", theme.expected.focusBorder) |
| 68 | + await page.keyboard.press("Tab") |
| 69 | + await expect(trigger).toBeFocused() |
| 70 | + await expect |
| 71 | + .poll(() => trigger.evaluate((element) => getComputedStyle(element).boxShadow)) |
| 72 | + .toContain(theme.expected.focusBorder) |
| 73 | + |
| 74 | + await expect(component).toHaveScreenshot(`chat-controls-focus-${theme.name}.png`) |
| 75 | + |
| 76 | + await component.getByRole("button", { name: "Edit" }).click() |
| 77 | + await component.getByTitle("Remove").click() |
| 78 | + const dialog = page.getByRole("alertdialog") |
| 79 | + await expect(dialog).toBeVisible() |
| 80 | + await expect(dialog).toHaveCSS("background-color", theme.expected.background) |
| 81 | + await expect(dialog).toHaveCSS("border-color", theme.expected.panelBorder) |
| 82 | + await expect(page.getByText("Are you sure you want to delete this todo item?")).toHaveCSS( |
| 83 | + "color", |
| 84 | + theme.expected.description, |
| 85 | + ) |
| 86 | + await expect(page.getByRole("button", { name: "Delete" })).toHaveCSS("color", theme.expected.error) |
| 87 | + |
| 88 | + await expect(dialog).toHaveScreenshot(`chat-controls-delete-dialog-${theme.name}.png`) |
| 89 | + }) |
| 90 | +} |
0 commit comments