106 lines
4.4 KiB
TypeScript
106 lines
4.4 KiB
TypeScript
// @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 { buildComposePrefill, buildEmailComposeVM } from "@hivegrid/view-models";
|
|
import { EmailComposePage } from "./EmailComposePage";
|
|
import { EMAIL_COMPOSE_INTERIM_VISUAL_SCREENS, EmailComposeInterimVisualFixture } from "./email-compose-interim.visual-fixture";
|
|
|
|
vi.mock("react-i18next", () => ({
|
|
useTranslation: () => ({
|
|
t: (key: string, values?: Record<string, unknown>) => (values ? `${key}:${Object.values(values).join("/")}` : key),
|
|
i18n: { language: "de" },
|
|
}),
|
|
}));
|
|
|
|
describe("AK-UI-03 email compose interim visual baseline", () => {
|
|
it("renders the interim blank, reply, and no-mailbox states from ~/ui", () => {
|
|
const { container } = render(
|
|
<MemoryRouter>
|
|
<main data-ui-id="ui.email.compose.interim.visualBaseline">
|
|
{EMAIL_COMPOSE_INTERIM_VISUAL_SCREENS.map((screen) => (
|
|
<EmailComposeInterimVisualFixture key={screen} screen={screen} />
|
|
))}
|
|
</main>
|
|
</MemoryRouter>
|
|
);
|
|
|
|
expect(container.querySelectorAll("[data-ui-id='ui.email.compose']")).toHaveLength(3);
|
|
// blank + reply render the form; no-mailbox renders the connect state instead.
|
|
expect(container.querySelectorAll("[data-ui-id='ui.email.compose.send']")).toHaveLength(2);
|
|
expect(container.querySelectorAll("[data-ui-id='ui.email.compose.bcc']")).toHaveLength(2);
|
|
expect(container.querySelectorAll("[data-ui-id='ui.email.compose.noMailbox']")).toHaveLength(1);
|
|
expect(container.querySelectorAll("[data-ui-id='ui.email.compose.connect']")).toHaveLength(1);
|
|
|
|
const stableMarkup = container.innerHTML.replace(/<svg\b[^>]*>[\s\S]*?<\/svg>/gu, '<svg data-visual-icon="true"></svg>');
|
|
expect(stableMarkup).toMatchSnapshot();
|
|
});
|
|
|
|
it("blocks sending until the recipient field parses to at least one address", () => {
|
|
const { container } = render(
|
|
<MemoryRouter>
|
|
<EmailComposeInterimVisualFixture screen="blank" />
|
|
</MemoryRouter>
|
|
);
|
|
|
|
const send = container.querySelector("[data-ui-id='ui.email.compose.send']");
|
|
expect(send).toBeDisabled();
|
|
|
|
const to = container.querySelector("[data-ui-id='ui.email.compose.to']") as HTMLInputElement;
|
|
fireEvent.change(to, { target: { value: "kein-at-zeichen" } });
|
|
expect(send).toBeDisabled();
|
|
|
|
fireEvent.change(to, { target: { value: "erika@example.test" } });
|
|
expect(send).toBeEnabled();
|
|
});
|
|
|
|
it("prefills the reply recipient and hands the quoted original back on send", () => {
|
|
const onSend = vi.fn();
|
|
const vm = buildEmailComposeVM({
|
|
mailboxes: [{ id: "mailbox-1", emailAddress: "info@handwerk.test", provider: "gmail", isDefaultForUser: true }],
|
|
defaultMailboxId: "mailbox-1",
|
|
templates: [],
|
|
backHref: "/acme/emails/msg-1",
|
|
prefill: buildComposePrefill({
|
|
mode: "reply",
|
|
original: {
|
|
id: "msg-1",
|
|
direction: "inbound",
|
|
fromAddress: "erika@example.test",
|
|
fromName: "Erika Beispiel",
|
|
toSummary: "info@handwerk.test",
|
|
subject: "Angebot",
|
|
sentAtIso: "2020-01-03T09:30:00.000Z",
|
|
safeBodyHtml: "<p>Danke</p>",
|
|
},
|
|
}),
|
|
});
|
|
|
|
const { container } = render(
|
|
<MemoryRouter>
|
|
<EmailComposePage vm={vm} actions={{ onSend, onBack: () => undefined, onOpenSettings: () => undefined }} />
|
|
</MemoryRouter>
|
|
);
|
|
|
|
const to = container.querySelector("[data-ui-id='ui.email.compose.to']") as HTMLInputElement;
|
|
expect(to.value).toBe("erika@example.test");
|
|
|
|
fireEvent.change(container.querySelector("[data-ui-id='ui.email.compose.bcc']") as HTMLInputElement, {
|
|
target: { value: "chef@handwerk.test" },
|
|
});
|
|
fireEvent.click(container.querySelector("[data-ui-id='ui.email.compose.send']") as HTMLButtonElement);
|
|
|
|
expect(onSend).toHaveBeenCalledTimes(1);
|
|
const payload = onSend.mock.calls[0]?.[0] as Record<string, unknown>;
|
|
expect(payload.to).toBe("erika@example.test");
|
|
// bcc reached the action contract but had no field before AK-UI-03.
|
|
expect(payload.bcc).toBe("chef@handwerk.test");
|
|
expect(payload.replyToMessageId).toBe("msg-1");
|
|
expect(String(payload.quotedHtml)).toContain("<blockquote");
|
|
expect(payload.attachments).toEqual([]);
|
|
});
|
|
});
|