75 lines
2.5 KiB
TypeScript
75 lines
2.5 KiB
TypeScript
import { fireEvent, render, screen } from "@testing-library/react";
|
|
import { describe, expect, it, vi } from "vitest";
|
|
import { buildProjectSubAreasVM, type ProjectSignaturePanelVM } from "@hivegrid/view-models";
|
|
import { ProjectSubAreasPanel } from "./ProjectSubAreasPanel";
|
|
|
|
vi.mock("react-i18next", () => ({
|
|
useTranslation: () => ({ t: (key: string) => key, i18n: { language: "de" } }),
|
|
}));
|
|
|
|
const signature: ProjectSignaturePanelVM = { status: "empty" };
|
|
|
|
function renderPanel() {
|
|
const vm = buildProjectSubAreasVM(
|
|
{
|
|
project: { id: "p1", projektNummer: "P-1", projektname: "Dach Nord" },
|
|
members: [],
|
|
appointments: [],
|
|
invoices: [
|
|
{
|
|
id: "r1",
|
|
rechnungsnummer: "R-1",
|
|
betrag: "2500.00",
|
|
status: "gestellt",
|
|
datum: "2026-07-15T10:00:00.000Z",
|
|
faelligAm: null,
|
|
dateiId: null,
|
|
},
|
|
],
|
|
checklists: [],
|
|
materials: [
|
|
{
|
|
id: "material-1",
|
|
positionNumber: "01.01",
|
|
text: "Ventil",
|
|
longText: "DN 20",
|
|
quantity: "2",
|
|
unit: "Stk",
|
|
unitPrice: "12.50",
|
|
totalPrice: "25.00",
|
|
lastSyncedAt: "2026-07-16T10:00:00.000Z",
|
|
},
|
|
],
|
|
stageConfig: null,
|
|
openDefects: 0,
|
|
},
|
|
{ acceptanceHref: "/acme/projects/p1/acceptance" }
|
|
);
|
|
|
|
render(<ProjectSubAreasPanel vm={vm} signature={signature} submitting={false} actions={{ onSubmit: vi.fn() }} />);
|
|
}
|
|
|
|
describe("ProjectSubAreasPanel", () => {
|
|
it("formats invoice amounts as euros and keeps the input raw", () => {
|
|
renderPanel();
|
|
fireEvent.click(screen.getByText("projects.subAreas.invoices"));
|
|
|
|
expect((document.body.textContent ?? "").replace(/[\u00a0\u202f]/g, " ")).toContain("2.500,00 €");
|
|
|
|
const amountInput = document.querySelector('input[type="number"]') as HTMLInputElement;
|
|
fireEvent.change(amountInput, { target: { value: "2500.00" } });
|
|
expect(amountInput.value).toBe("2500.00");
|
|
});
|
|
|
|
it("shows synchronized KWP material positions read-only", () => {
|
|
renderPanel();
|
|
fireEvent.click(screen.getByText("projects.subAreas.materials"));
|
|
|
|
expect(screen.getByText("01.01")).toBeTruthy();
|
|
expect(screen.getByText("Ventil")).toBeTruthy();
|
|
expect(screen.getByText("DN 20")).toBeTruthy();
|
|
expect((document.body.textContent ?? "").replace(/[\u00a0\u202f]/g, " ")).toContain("25,00 €");
|
|
expect(screen.queryByRole("button", { name: /save|speichern/iu })).toBeNull();
|
|
});
|
|
});
|