55 lines
2.1 KiB
TypeScript
55 lines
2.1 KiB
TypeScript
import { vi, describe, it, expect } from "vitest";
|
|
import "@testing-library/jest-dom";
|
|
import { render } from "@testing-library/react";
|
|
import { BrowserRouter as Router } from "react-router";
|
|
|
|
import { TaskNewPage, type TaskNewPageProps } from "./TaskNewPage";
|
|
|
|
vi.mock("react-i18next", () => ({
|
|
useTranslation: () => ({ t: (str: string) => str, i18n: { language: "de" } }),
|
|
}));
|
|
|
|
function baseProps(overrides: Partial<TaskNewPageProps> = {}): TaskNewPageProps {
|
|
return {
|
|
assignableUsers: [{ id: "u1", label: "Alex Meier" }],
|
|
assignableGroups: [{ id: "g1", label: "Vertrieb" }],
|
|
prefill: null,
|
|
cancelHref: "/acme/tasks",
|
|
...overrides,
|
|
};
|
|
}
|
|
|
|
describe("TaskNewPage (interim-UI)", () => {
|
|
it("renders the create form surface + title/submit/cancel markers", () => {
|
|
const { container } = render(
|
|
<Router>
|
|
<TaskNewPage {...baseProps()} />
|
|
</Router>,
|
|
);
|
|
expect(container.querySelector('[data-ui-id="ui.tasks.new"]')).toBeInTheDocument();
|
|
expect(container.querySelector('[data-ui-id="ui.tasks.new.title"]')).toBeInTheDocument();
|
|
expect(container.querySelector('[data-ui-id="ui.tasks.new.submit"]')).toBeInTheDocument();
|
|
expect(container.querySelector('[data-ui-id="ui.tasks.new.cancel"]')).toBeInTheDocument();
|
|
});
|
|
|
|
it("renders the entity prefill marker + hidden inputs when prefilled", () => {
|
|
const { container } = render(
|
|
<Router>
|
|
<TaskNewPage {...baseProps({ prefill: { entityType: "contact", entityId: "c9" } })} />
|
|
</Router>,
|
|
);
|
|
expect(container.querySelector('[data-ui-id="ui.tasks.new.prefill"]')).toBeInTheDocument();
|
|
expect(container.querySelector('input[type="hidden"][name="entityType"][value="contact"]')).toBeInTheDocument();
|
|
expect(container.querySelector('input[type="hidden"][name="entityId"][value="c9"]')).toBeInTheDocument();
|
|
});
|
|
|
|
it("omits the prefill block when not prefilled", () => {
|
|
const { container } = render(
|
|
<Router>
|
|
<TaskNewPage {...baseProps()} />
|
|
</Router>,
|
|
);
|
|
expect(container.querySelector('[data-ui-id="ui.tasks.new.prefill"]')).not.toBeInTheDocument();
|
|
});
|
|
});
|