// @vitest-environment jsdom import "@testing-library/jest-dom/vitest"; import React from "react"; import { MemoryRouter } from "react-router"; import { fireEvent, render } from "@testing-library/react"; import { describe, expect, it, vi } from "vitest"; import { EMAIL_INBOX_INTERIM_VISUAL_SCREENS, EmailInboxInterimVisualFixture } from "./email-inbox-interim.visual-fixture"; vi.mock("react-i18next", () => ({ useTranslation: () => ({ t: (key: string, values?: Record) => (values ? `${key}:${Object.values(values).join("/")}` : key), i18n: { language: "de" }, }), })); vi.mock("~/locale/format", () => ({ useLocaleFormatters: () => ({ locale: "de", number: (value: number) => String(value), currency: (value: number, currency: string) => `${value.toFixed(2)} ${currency}`, currencyFromCents: (value: number, currency: string) => `${(value / 100).toFixed(2)} ${currency}`, percent: (value: number) => `${value}%`, compact: (value: number) => String(value), date: (value: Date | number | string) => new Date(value).toISOString(), dateTime: (value: Date | number | string) => new Date(value).toISOString(), relativeTime: (value: number, unit: string) => `${value} ${unit}`, relativeDate: (value: Date | number | string) => new Date(value).toISOString(), }), })); describe("AK-UI-01 email inbox interim visual baseline", () => { it("renders the interim list, empty, and no-mailbox states from ~/ui", () => { const { container } = render(
{EMAIL_INBOX_INTERIM_VISUAL_SCREENS.map((screen) => ( ))}
); expect(container.querySelectorAll("[data-ui-id='ui.email.inbox']")).toHaveLength(3); expect(container.querySelectorAll("[data-ui-id='ui.email.inbox.list']")).toHaveLength(1); expect(container.querySelectorAll("[data-ui-id='ui.email.inbox.empty']")).toHaveLength(1); expect(container.querySelectorAll("[data-ui-id='ui.email.inbox.noMailbox']")).toHaveLength(1); const stableMarkup = container.innerHTML.replace(/]*>[\s\S]*?<\/svg>/gu, ''); expect(stableMarkup).toMatchSnapshot(); }); it("opens the archive confirmation as a real ~/ui dialog", async () => { const { findByText, container } = render( ); const firstRowCheckbox = container.querySelector("tbody [aria-label='emailInbox.list.selectRow']"); expect(firstRowCheckbox).not.toBeNull(); fireEvent.click(firstRowCheckbox as HTMLButtonElement); const archiveButton = container.querySelector("[data-ui-id='ui.email.inbox.bulk.archive']"); expect(archiveButton).not.toBeNull(); expect(archiveButton).toBeEnabled(); fireEvent.click(archiveButton as HTMLButtonElement); expect(await findByText("emailInbox.list.archiveDialog.title")).toBeInTheDocument(); expect(document.querySelector("[data-ui-id='ui.email.inbox.archiveDialog']")).not.toBeNull(); }); });