import { expect, type Page, test } from "@playwright/test"; import type { Routine } from "@rakazo/contracts"; import { activeBotId, captureScreenshot, completeOnboarding, openUserSettings, rpc, signup, } from "./helpers"; async function useAppearance(page: Page, appearance: "light" | "dark") { const settings = await openUserSettings(page); await settings.getByTestId(`ui-appearance-${appearance}`).click(); await expect(page.locator("html")).toHaveAttribute("data-theme", appearance); await settings.getByRole("button", { name: "Close user settings" }).click(); await expect(settings).toBeHidden(); } test("a routine said in passing becomes one quiet line with Edit and Undo", async ({ page, }, testInfo) => { const stamp = Date.now(); await signup(page, `routine-line-${stamp}@rakazo.test`, "password12", "Routine Line"); await completeOnboarding(page); const botId = activeBotId(page); await page.getByPlaceholder(/Message/).fill("Every Sunday I plan the week, keep me on it."); await page.keyboard.press("Enter"); const line = page.getByTestId("routine-event-line"); await expect(line).toBeVisible({ timeout: 60_000 }); await expect(line).toContainText("Weekly plan"); await expect(line).toContainText("Every Sunday, 6:00 PM"); await expect(page.getByText("i will remind you every sunday at 6 pm.")).toBeVisible({ timeout: 30_000, }); await useAppearance(page, "light"); await line.scrollIntoViewIfNeeded(); await captureScreenshot(page, testInfo, "routine-line-light"); await useAppearance(page, "dark"); await line.scrollIntoViewIfNeeded(); await captureScreenshot(page, testInfo, "routine-line-dark"); await line.getByRole("button", { name: "Edit" }).click(); await expect(page.getByPlaceholder("Name this routine")).toHaveValue("Weekly plan", { timeout: 15_000, }); await page.getByRole("button", { name: "Back" }).click(); await line.getByRole("button", { name: "Undo" }).click(); await expect(line).toContainText("Removed", { timeout: 15_000 }); await expect(line.getByRole("button", { name: "Undo" })).toHaveCount(0); expect(await rpc(page, "routines/list", { botId })).toEqual([]); await page.reload({ waitUntil: "domcontentloaded" }); await expect(page.getByTestId("routine-event-line")).toContainText("Removed", { timeout: 30_000, }); });