30 lines
1.3 KiB
TypeScript
30 lines
1.3 KiB
TypeScript
// R-P7 interim-UI (AD-28) — LeadNewPage unit test. Pure props; asserts the create
|
|
// callback + the identity guard. i18n mocked.
|
|
|
|
import { fireEvent, render } from "@testing-library/react";
|
|
import { describe, expect, it, vi } from "vitest";
|
|
import { LeadNewPage, type LeadNewPageActions } from "./LeadNewPage";
|
|
|
|
vi.mock("react-i18next", () => ({ useTranslation: () => ({ t: (s: string) => s, i18n: { language: "de" } }) }));
|
|
|
|
function actions(over: Partial<LeadNewPageActions> = {}): LeadNewPageActions {
|
|
return { onCreate: vi.fn(), ...over };
|
|
}
|
|
|
|
function renderPage(acts = actions()) {
|
|
render(<LeadNewPage backHref="/acme/leads" submitting={false} errorKey={null} actions={acts} />);
|
|
return acts;
|
|
}
|
|
|
|
describe("LeadNewPage", () => {
|
|
it("keeps create disabled until an identity field is filled, then submits", () => {
|
|
const onCreate = vi.fn();
|
|
renderPage(actions({ onCreate }));
|
|
const submit = document.querySelector("[data-ui-id='ui.leads.new.submit']") as HTMLButtonElement;
|
|
expect(submit.disabled).toBe(true);
|
|
fireEvent.change(document.querySelector("[data-ui-id='ui.leads.new.email']")!, { target: { value: "neu@example.com" } });
|
|
fireEvent.click(submit);
|
|
expect(onCreate).toHaveBeenCalledWith(expect.objectContaining({ quelle: "manual", email: "neu@example.com" }));
|
|
});
|
|
});
|