675 lines
31 KiB
TypeScript
675 lines
31 KiB
TypeScript
import { fireEvent, render, screen, waitFor } from "@testing-library/react";
|
|
import { describe, expect, it, vi } from "vitest";
|
|
import { buildPlantafelVM, type PlantafelScreenVM } from "@hivegrid/view-models";
|
|
import { PlantafelPage, type PlantafelActionResult, type PlantafelPageProps } from "./PlantafelPage";
|
|
|
|
vi.mock("react-i18next", () => ({
|
|
useTranslation: () => ({ t: (key: string) => key, i18n: { language: "de" } }),
|
|
}));
|
|
|
|
// Radix scrolls the active option into view when a Select opens; jsdom has no
|
|
// such method. Same stub the command-palette test uses.
|
|
HTMLElement.prototype.scrollIntoView = HTMLElement.prototype.scrollIntoView ?? vi.fn();
|
|
|
|
const PROJECT_ID = "rheinmain-shk-v1-project-0315";
|
|
const ASSIGNEE_ID = "rheinmain-shk-v1-employee-0049";
|
|
|
|
function plantafelVM(): PlantafelScreenVM {
|
|
return buildPlantafelVM({
|
|
entries: [
|
|
{
|
|
id: "schedule-1",
|
|
projektId: PROJECT_ID,
|
|
assignedUserId: ASSIGNEE_ID,
|
|
title: "Heizungstausch Auenland Gastronomie Frankfurt",
|
|
startAt: "2026-07-20T09:00:00.000Z",
|
|
endAt: "2026-07-20T12:00:00.000Z",
|
|
status: "confirmed",
|
|
syncStatus: "synced",
|
|
conflicts: [],
|
|
},
|
|
],
|
|
absences: [],
|
|
generatedAt: "2026-07-15T11:17:00.000Z",
|
|
});
|
|
}
|
|
|
|
/** More rows than fit on one page, so the pager has something to page through. */
|
|
function manyEntryVM(count: number): PlantafelScreenVM {
|
|
return buildPlantafelVM({
|
|
entries: Array.from({ length: count }, (_, index) => ({
|
|
id: `schedule-${index + 1}`,
|
|
projektId: PROJECT_ID,
|
|
assignedUserId: ASSIGNEE_ID,
|
|
title: `Einsatz ${String(index + 1).padStart(3, "0")}`,
|
|
// One per day so the chronological default gives a stable, readable order.
|
|
startAt: new Date(Date.UTC(2026, 6, 20, 7, 0) + index * 24 * 60 * 60 * 1000).toISOString(),
|
|
endAt: new Date(Date.UTC(2026, 6, 20, 9, 0) + index * 24 * 60 * 60 * 1000).toISOString(),
|
|
status: "planned" as const,
|
|
syncStatus: "synced" as const,
|
|
conflicts: [],
|
|
})),
|
|
absences: [],
|
|
generatedAt: "2026-07-15T11:17:00.000Z",
|
|
});
|
|
}
|
|
|
|
/** Two entries on different days - enough to tell one order from another. */
|
|
function twoEntryVM(): PlantafelScreenVM {
|
|
return buildPlantafelVM({
|
|
entries: [
|
|
{
|
|
id: "schedule-1",
|
|
projektId: PROJECT_ID,
|
|
assignedUserId: ASSIGNEE_ID,
|
|
title: "Heizungstausch Auenland Gastronomie Frankfurt",
|
|
startAt: "2026-07-20T09:00:00.000Z",
|
|
endAt: "2026-07-20T12:00:00.000Z",
|
|
status: "confirmed",
|
|
syncStatus: "synced",
|
|
conflicts: [],
|
|
},
|
|
{
|
|
id: "schedule-2",
|
|
projektId: PROJECT_ID,
|
|
assignedUserId: ASSIGNEE_ID,
|
|
title: "Wartung Brennwerttherme",
|
|
startAt: "2026-07-22T07:00:00.000Z",
|
|
endAt: "2026-07-22T09:00:00.000Z",
|
|
status: "planned",
|
|
syncStatus: "synced",
|
|
conflicts: [],
|
|
},
|
|
],
|
|
absences: [],
|
|
generatedAt: "2026-07-15T11:17:00.000Z",
|
|
});
|
|
}
|
|
|
|
function pageProps(overrides: Partial<PlantafelPageProps> = {}): PlantafelPageProps {
|
|
const onSubmit = vi.fn();
|
|
const onProjectSearch = vi.fn();
|
|
const onFilterChange = vi.fn();
|
|
const onViewChange = vi.fn();
|
|
const onAnchorChange = vi.fn();
|
|
return {
|
|
vm: plantafelVM(),
|
|
projectLabels: [{ id: PROJECT_ID, label: "RM-2026-700315 · Heizungstausch Auenland" }],
|
|
editableProjectIds: [PROJECT_ID],
|
|
projectOptions: [{ id: PROJECT_ID, label: "RM-2026-700315 · Heizungstausch Auenland" }],
|
|
projectOptionsHasMore: false,
|
|
projectPickerLoading: false,
|
|
assigneeOptions: [{ id: ASSIGNEE_ID, label: "Anna Schneider" }],
|
|
canWrite: true,
|
|
canBulkReassign: false,
|
|
filter: { assignedUserId: null, includePast: false, sort: "start_asc" },
|
|
view: "table",
|
|
// The fixture entry sits on Monday 2026-07-20, so the anchored week contains it.
|
|
anchorIso: "2026-07-22",
|
|
todayIso: "2026-07-22",
|
|
submitting: false,
|
|
actions: { onSubmit, onProjectSearch, onFilterChange, onViewChange, onAnchorChange },
|
|
...overrides,
|
|
};
|
|
}
|
|
|
|
function renderPage(overrides: Partial<PlantafelPageProps> = {}) {
|
|
let props = pageProps(overrides);
|
|
const view = render(<PlantafelPage {...props} />);
|
|
return {
|
|
get props() {
|
|
return props;
|
|
},
|
|
rerender(next: Partial<PlantafelPageProps>) {
|
|
props = { ...props, ...next };
|
|
view.rerender(<PlantafelPage {...props} />);
|
|
},
|
|
};
|
|
}
|
|
|
|
function byUiId(id: string): HTMLElement {
|
|
const element = document.querySelector(`[data-ui-id='${id}']`);
|
|
if (!(element instanceof HTMLElement)) throw new Error(`Missing element ${id}`);
|
|
return element;
|
|
}
|
|
|
|
describe("PlantafelPage", () => {
|
|
it("keeps the schedule table contained and renders a semantic header", () => {
|
|
renderPage();
|
|
|
|
const table = screen.getByRole("table");
|
|
expect(table.querySelector("thead tr")).toBeTruthy();
|
|
expect(table.querySelector("tbody tr")).toBeTruthy();
|
|
expect(byUiId("ui.projects.plantafel.table").className).toContain("min-w-0");
|
|
expect(byUiId("ui.projects.plantafel.tableScroll").className).toContain("overflow-x-auto");
|
|
});
|
|
|
|
it("frames the table like the other list screens instead of wrapping it in a card", () => {
|
|
renderPage();
|
|
|
|
const section = byUiId("ui.projects.plantafel.table");
|
|
// The heading stays; the surrounding card does not - only the table itself
|
|
// keeps a border, exactly as on the forms list.
|
|
expect(section.textContent).toContain("projects.plantafel.entriesTitle");
|
|
expect(section.className).not.toContain("bg-surface-neutral-primary");
|
|
expect(byUiId("ui.projects.plantafel.tableScroll").className).toContain("border-border-default");
|
|
});
|
|
|
|
it("puts the data-freshness line under the table instead of above it", () => {
|
|
renderPage();
|
|
|
|
const stand = byUiId("ui.projects.plantafel.generatedAt");
|
|
const table = byUiId("ui.projects.plantafel.tableScroll");
|
|
// A detail that is only read after the rows must not push them down.
|
|
expect(table.compareDocumentPosition(stand) & Node.DOCUMENT_POSITION_FOLLOWING).toBeTruthy();
|
|
expect(stand.textContent).toContain("projects.plantafel.generatedAt");
|
|
});
|
|
|
|
it("pages an overfull table instead of printing every row at once", () => {
|
|
renderPage({ vm: manyEntryVM(30) });
|
|
const titles = () => [...document.querySelectorAll("tbody tr td:first-child")].map((cell) => cell.textContent ?? "");
|
|
|
|
expect(titles()).toHaveLength(25);
|
|
expect(titles()[0]).toContain("Einsatz 001");
|
|
expect(byUiId("ui.projects.plantafel.pagination.position").textContent).toContain("projects.plantafel.pagination.position");
|
|
expect((byUiId("ui.projects.plantafel.pagination.prev") as HTMLButtonElement).disabled).toBe(true);
|
|
|
|
fireEvent.click(byUiId("ui.projects.plantafel.pagination.next"));
|
|
expect(titles()).toHaveLength(5);
|
|
expect(titles()[0]).toContain("Einsatz 026");
|
|
expect((byUiId("ui.projects.plantafel.pagination.next") as HTMLButtonElement).disabled).toBe(true);
|
|
});
|
|
|
|
it("sends the reader back to page one when the result set is narrowed", () => {
|
|
renderPage({ vm: manyEntryVM(30) });
|
|
|
|
fireEvent.click(byUiId("ui.projects.plantafel.pagination.next"));
|
|
fireEvent.change(byUiId("ui.projects.plantafel.filter.search"), { target: { value: "Einsatz 0" } });
|
|
|
|
// Page two of the old set no longer exists in the narrowed one; landing
|
|
// there would look like an empty result.
|
|
const titles = [...document.querySelectorAll("tbody tr td:first-child")].map((cell) => cell.textContent ?? "");
|
|
expect(titles[0]).toContain("Einsatz 001");
|
|
});
|
|
|
|
it("keeps a single page free of a pager but still dates the table", () => {
|
|
renderPage();
|
|
|
|
expect(document.querySelector("[data-ui-id='ui.projects.plantafel.pagination']")).not.toBeNull();
|
|
expect(byUiId("ui.projects.plantafel.pagination.position").textContent).toContain("projects.plantafel.pagination.position");
|
|
expect((byUiId("ui.projects.plantafel.pagination.prev") as HTMLButtonElement).disabled).toBe(true);
|
|
expect((byUiId("ui.projects.plantafel.pagination.next") as HTMLButtonElement).disabled).toBe(true);
|
|
});
|
|
|
|
it("marks an openable entry with the link colour", () => {
|
|
renderPage();
|
|
|
|
expect(byUiId("ui.projects.plantafel.detail.open.schedule-1").querySelector("span")?.className).toContain("text-text-feedback-link-default");
|
|
});
|
|
|
|
it("selects and clears every selectable row of the page from the header", () => {
|
|
renderPage({ vm: twoEntryVM(), canBulkReassign: true });
|
|
|
|
fireEvent.click(byUiId("ui.projects.plantafel.selectAll"));
|
|
// Both rows are in the selection the bulk action would act on.
|
|
expect(byUiId("ui.projects.plantafel.select.schedule-1").getAttribute("data-state")).toBe("checked");
|
|
expect(byUiId("ui.projects.plantafel.select.schedule-2").getAttribute("data-state")).toBe("checked");
|
|
expect(byUiId("ui.projects.plantafel.bulk").textContent).toContain("projects.plantafel.bulkSelected");
|
|
|
|
fireEvent.click(byUiId("ui.projects.plantafel.selectAll"));
|
|
expect(document.querySelector("[data-ui-id='ui.projects.plantafel.bulk']")).toBeNull();
|
|
});
|
|
|
|
it("offers no select-all where no row may be reassigned", () => {
|
|
renderPage({ canBulkReassign: true, editableProjectIds: [] });
|
|
|
|
expect(document.querySelector("[data-ui-id='ui.projects.plantafel.selectAll']")).toBeNull();
|
|
});
|
|
|
|
it("switches to the calendar view through the header toggle", () => {
|
|
const page = renderPage();
|
|
|
|
fireEvent.click(byUiId("ui.projects.plantafel.viewToggle.calendar"));
|
|
|
|
expect(page.props.actions.onViewChange).toHaveBeenCalledWith("calendar");
|
|
});
|
|
|
|
it("renders the anchored working week from Monday to Sunday and drops the table", () => {
|
|
renderPage({ view: "calendar" });
|
|
|
|
const days = byUiId("ui.projects.plantafel.week").querySelectorAll("[data-date]");
|
|
expect([...days].map((day) => day.getAttribute("data-date"))).toEqual([
|
|
"2026-07-20",
|
|
"2026-07-21",
|
|
"2026-07-22",
|
|
"2026-07-23",
|
|
"2026-07-24",
|
|
"2026-07-25",
|
|
"2026-07-26",
|
|
]);
|
|
expect(document.querySelector("table")).toBeNull();
|
|
// The Monday entry lands in the Monday column, not somewhere else.
|
|
expect(byUiId("ui.projects.plantafel.week.entry.schedule-1").closest("[data-date]")?.getAttribute("data-date")).toBe("2026-07-20");
|
|
});
|
|
|
|
it("navigates whole weeks from the calendar view", () => {
|
|
const page = renderPage({ view: "calendar" });
|
|
|
|
fireEvent.click(byUiId("ui.projects.plantafel.weekNav.next"));
|
|
expect(page.props.actions.onAnchorChange).toHaveBeenCalledWith("2026-07-27");
|
|
|
|
fireEvent.click(byUiId("ui.projects.plantafel.weekNav.previous"));
|
|
expect(page.props.actions.onAnchorChange).toHaveBeenCalledWith("2026-07-13");
|
|
});
|
|
|
|
it("offers search and a monteur picker instead of the quick ranges", () => {
|
|
const page = renderPage();
|
|
|
|
expect(document.querySelector('[data-ui-id="ui.projects.plantafel.filter.search"]')).not.toBeNull();
|
|
expect(document.querySelector('[data-ui-id="ui.projects.plantafel.filter.assignee"]')).not.toBeNull();
|
|
// The old quick-range strip and its checkbox are gone.
|
|
expect(document.body.textContent).not.toContain("projects.plantafel.filterToday");
|
|
expect(document.body.textContent).not.toContain("projects.plantafel.filterMine");
|
|
expect(document.querySelector('[data-ui-id="ui.projects.plantafel.weekNav"]')).toBeNull();
|
|
expect(page.props.actions.onFilterChange).not.toHaveBeenCalled();
|
|
});
|
|
|
|
it("offers the past-appointments switch in the table view only", () => {
|
|
const page = renderPage();
|
|
|
|
// The window is a loader concern, so the switch goes back to the route
|
|
// instead of filtering rows that were never fetched.
|
|
fireEvent.click(byUiId("ui.projects.plantafel.filter.past"));
|
|
expect(page.props.actions.onFilterChange).toHaveBeenCalledWith({ assignedUserId: null, includePast: true, sort: "start_asc" });
|
|
|
|
// Keeps the picked monteur - the two filters must not overwrite each other.
|
|
page.rerender({ filter: { assignedUserId: ASSIGNEE_ID, includePast: true, sort: "start_asc" } });
|
|
fireEvent.click(byUiId("ui.projects.plantafel.filter.past"));
|
|
expect(page.props.actions.onFilterChange).toHaveBeenLastCalledWith({ assignedUserId: ASSIGNEE_ID, includePast: false, sort: "start_asc" });
|
|
|
|
// The calendar reaches the past by paging back, so it has no switch.
|
|
page.rerender({ view: "calendar" });
|
|
expect(document.querySelector('[data-ui-id="ui.projects.plantafel.filter.past"]')).toBeNull();
|
|
});
|
|
|
|
it("adds the week navigation only in the calendar view", () => {
|
|
renderPage({ view: "calendar" });
|
|
|
|
expect(document.querySelector('[data-ui-id="ui.projects.plantafel.weekNav"]')).not.toBeNull();
|
|
// The monteur picker stays; search and sorting are table controls and go.
|
|
expect(document.querySelector('[data-ui-id="ui.projects.plantafel.filter.assignee"]')).not.toBeNull();
|
|
expect(document.querySelector('[data-ui-id="ui.projects.plantafel.filter.search"]')).toBeNull();
|
|
expect(document.querySelector('[data-ui-id="ui.projects.plantafel.filter.sort"]')).toBeNull();
|
|
});
|
|
|
|
it("puts the sorting button directly behind the monteur facet", () => {
|
|
renderPage();
|
|
|
|
const assignee = byUiId("ui.projects.plantafel.filter.assignee");
|
|
const sort = byUiId("ui.projects.plantafel.filter.sort");
|
|
// Same row, and nothing of the bar in between - sorting orders exactly the
|
|
// rows the monteur facet narrows.
|
|
expect(sort.parentElement).toBe(assignee.parentElement);
|
|
expect(assignee.nextElementSibling).toBe(sort);
|
|
});
|
|
|
|
it("orders the table rows by the picked sorting", async () => {
|
|
const page = renderPage();
|
|
const titles = () => [...document.querySelectorAll("tbody tr td:first-child")].map((cell) => cell.textContent ?? "");
|
|
|
|
// The facet button states the active order without being opened, the same
|
|
// way the project list's sort button does.
|
|
expect(byUiId("ui.projects.plantafel.filter.sort").textContent).toContain("projects.plantafel.sortOption.start_asc");
|
|
fireEvent.keyDown(byUiId("ui.projects.plantafel.filter.sort"), { key: "Enter" });
|
|
// The kit's checkbox contributes its own label markup, so match on the
|
|
// caption rather than on the whole node text.
|
|
expect((await screen.findAllByRole("menuitem")).map((option) => option.textContent)).toEqual([
|
|
expect.stringContaining("projects.plantafel.sortOption.start_asc"),
|
|
expect.stringContaining("projects.plantafel.sortOption.start_desc"),
|
|
expect.stringContaining("projects.plantafel.sortOption.title_asc"),
|
|
expect.stringContaining("projects.plantafel.sortOption.assignee_asc"),
|
|
]);
|
|
fireEvent.click(byUiId("ui.projects.plantafel.filter.sort.title_asc"));
|
|
expect(page.props.actions.onFilterChange).toHaveBeenLastCalledWith({ assignedUserId: null, includePast: false, sort: "title_asc" });
|
|
|
|
page.rerender({ vm: twoEntryVM(), filter: { assignedUserId: null, includePast: false, sort: "start_asc" } });
|
|
expect(titles()[0]).toContain("Heizungstausch Auenland Gastronomie Frankfurt");
|
|
|
|
page.rerender({ filter: { assignedUserId: null, includePast: false, sort: "start_desc" } });
|
|
expect(titles()[0]).toContain("Wartung Brennwerttherme");
|
|
});
|
|
|
|
it("narrows the table to the searched appointment, monteur or project", () => {
|
|
renderPage();
|
|
|
|
fireEvent.change(byUiId("ui.projects.plantafel.filter.search"), { target: { value: "schneider" } });
|
|
expect(screen.getByText("Heizungstausch Auenland Gastronomie Frankfurt")).toBeTruthy();
|
|
|
|
// Matches the assignee label too, not just the title.
|
|
fireEvent.change(byUiId("ui.projects.plantafel.filter.search"), { target: { value: "anna" } });
|
|
expect(screen.getByText("Heizungstausch Auenland Gastronomie Frankfurt")).toBeTruthy();
|
|
});
|
|
|
|
it("says so in Klartext when the search matches nothing, instead of looking empty", () => {
|
|
renderPage();
|
|
|
|
fireEvent.change(byUiId("ui.projects.plantafel.filter.search"), { target: { value: "kabelkanal" } });
|
|
|
|
expect(document.querySelector("table")).toBeNull();
|
|
expect(screen.getByText("projects.plantafel.filterNoMatches")).toBeTruthy();
|
|
expect(screen.getByText("projects.plantafel.filterNoMatchesBody")).toBeTruthy();
|
|
// The header count follows the filter rather than contradicting the rows.
|
|
expect(document.body.textContent).toContain("projects.plantafel.entries");
|
|
});
|
|
|
|
it("does not carry a table search over into the week grid", () => {
|
|
const page = renderPage();
|
|
|
|
fireEvent.change(byUiId("ui.projects.plantafel.filter.search"), { target: { value: "kabelkanal" } });
|
|
page.rerender({ view: "calendar" });
|
|
|
|
// The calendar has no search box, so a leftover term must not silently
|
|
// empty the week.
|
|
expect(document.querySelector('[data-ui-id="ui.projects.plantafel.filter.search"]')).toBeNull();
|
|
expect(document.querySelector('[data-ui-id="ui.projects.plantafel.week.entry.schedule-1"]')).not.toBeNull();
|
|
});
|
|
|
|
it("shows human-readable project and assignee labels instead of raw ids", () => {
|
|
renderPage();
|
|
|
|
expect(screen.getAllByText("RM-2026-700315 · Heizungstausch Auenland").length).toBeGreaterThan(0);
|
|
expect(screen.getAllByText("Anna Schneider").length).toBeGreaterThan(0);
|
|
expect(document.body.textContent).not.toContain(PROJECT_ID);
|
|
expect(document.body.textContent).not.toContain(ASSIGNEE_ID);
|
|
});
|
|
|
|
it("creates an appointment from the preserved form", () => {
|
|
const page = renderPage();
|
|
|
|
fireEvent.click(byUiId("ui.projects.plantafel.new"));
|
|
expect(screen.getByRole("dialog", { name: "projects.plantafel.newEntry" })).toBeTruthy();
|
|
expect(byUiId("ui.projects.plantafel.createDialog").className).toContain("min-w-0");
|
|
fireEvent.change(byUiId("ui.projects.plantafel.createDialog.title"), { target: { value: "Wartung" } });
|
|
fireEvent.change(byUiId("ui.projects.plantafel.createDialog.start"), { target: { value: "2026-07-21T09:00" } });
|
|
fireEvent.change(byUiId("ui.projects.plantafel.createDialog.end"), { target: { value: "2026-07-21T11:00" } });
|
|
fireEvent.click(byUiId("ui.projects.plantafel.createDialog.confirm"));
|
|
|
|
expect(page.props.actions.onSubmit).toHaveBeenCalledWith(
|
|
"upsertSchedule",
|
|
expect.objectContaining({
|
|
projektId: PROJECT_ID,
|
|
assignedUserId: ASSIGNEE_ID,
|
|
title: "Wartung",
|
|
startAt: "2026-07-21T09:00",
|
|
endAt: "2026-07-21T11:00",
|
|
status: "planned",
|
|
conflictOverrideReason: "",
|
|
clientMutationId: expect.any(String),
|
|
}),
|
|
);
|
|
expect(byUiId("ui.projects.plantafel.createDialog.start").getAttribute("type")).toBe("datetime-local");
|
|
expect(byUiId("ui.projects.plantafel.createDialog.end").getAttribute("type")).toBe("datetime-local");
|
|
expect(screen.getByRole("combobox", { name: "projects.plantafel.fields.project" })).toBeTruthy();
|
|
expect(screen.getByRole("combobox", { name: "projects.plantafel.fields.assignee" })).toBeTruthy();
|
|
expect(screen.getByRole("dialog", { name: "projects.plantafel.newEntry" })).toBeTruthy();
|
|
});
|
|
|
|
it("changes an appointment status from the status flyout in one pick", async () => {
|
|
const page = renderPage();
|
|
|
|
// The badge itself opens the flyout - no separate save button any more.
|
|
// Radix opens on keyboard/pointerdown, so drive it the way the leads test does.
|
|
fireEvent.keyDown(byUiId("ui.projects.plantafel.status.schedule-1"), { key: "Enter" });
|
|
await waitFor(() => byUiId("ui.projects.plantafel.status.schedule-1.done"));
|
|
fireEvent.click(byUiId("ui.projects.plantafel.status.schedule-1.done"));
|
|
|
|
expect(page.props.actions.onSubmit).toHaveBeenCalledWith("updateStatus", {
|
|
entryId: "schedule-1",
|
|
status: "done",
|
|
});
|
|
});
|
|
|
|
it("does not resubmit when the already active status is picked", async () => {
|
|
const page = renderPage();
|
|
|
|
fireEvent.keyDown(byUiId("ui.projects.plantafel.status.schedule-1"), { key: "Enter" });
|
|
await waitFor(() => byUiId("ui.projects.plantafel.status.schedule-1.confirmed"));
|
|
fireEvent.click(byUiId("ui.projects.plantafel.status.schedule-1.confirmed"));
|
|
|
|
expect(page.props.actions.onSubmit).not.toHaveBeenCalled();
|
|
});
|
|
|
|
it("drops the separate save-status column from the table", () => {
|
|
renderPage();
|
|
|
|
const headers = [...document.querySelectorAll("thead th")].map((cell) => cell.textContent);
|
|
expect(headers).not.toContain("projects.actions.updateStatus");
|
|
expect(document.body.textContent).not.toContain("projects.plantafel.readOnly");
|
|
});
|
|
|
|
it("keeps the existing offline sync bridge available", () => {
|
|
const page = renderPage();
|
|
|
|
fireEvent.click(byUiId("ui.projects.plantafel.offline.submit"));
|
|
|
|
expect(page.props.actions.onSubmit).toHaveBeenCalledWith("offlineSync", {
|
|
clientMutationId: "",
|
|
operation: "schedule_upsert",
|
|
payload: "{}",
|
|
});
|
|
});
|
|
|
|
it("hides schedule write actions for read-only users", () => {
|
|
renderPage({ canWrite: false, projectOptions: [] });
|
|
|
|
expect(document.querySelector('[data-ui-id="ui.projects.plantafel.new"]')).toBeNull();
|
|
expect(document.querySelector('[data-ui-id="ui.projects.plantafel.status.schedule-1"]')).toBeNull();
|
|
expect(document.querySelector('[data-ui-id="ui.projects.plantafel.createDialog"]')).toBeNull();
|
|
expect(document.querySelector('[data-ui-id="ui.projects.plantafel.offline"]')).not.toBeNull();
|
|
});
|
|
|
|
it("hides a status control when a project is visible but not editable", () => {
|
|
renderPage({ editableProjectIds: [] });
|
|
|
|
expect(screen.getByText("Heizungstausch Auenland Gastronomie Frankfurt")).toBeTruthy();
|
|
expect(document.querySelector('[data-ui-id="ui.projects.plantafel.status.schedule-1"]')).toBeNull();
|
|
});
|
|
|
|
it("searches editable projects and makes a truncated result explicit", () => {
|
|
const page = renderPage({ projectOptionsHasMore: true });
|
|
|
|
fireEvent.click(byUiId("ui.projects.plantafel.new"));
|
|
fireEvent.change(byUiId("ui.projects.plantafel.createDialog.projectSearch"), { target: { value: "wärme" } });
|
|
fireEvent.click(byUiId("ui.projects.plantafel.createDialog.projectSearchSubmit"));
|
|
|
|
expect(page.props.actions.onProjectSearch).toHaveBeenCalledWith("wärme");
|
|
expect((byUiId("ui.projects.plantafel.createDialog.projectSearchSubmit") as HTMLButtonElement).disabled).toBe(true);
|
|
page.rerender({ projectPickerLoading: true });
|
|
page.rerender({ projectPickerLoading: false });
|
|
expect(screen.getByText("projects.plantafel.projectPickerLimited")).toBeTruthy();
|
|
});
|
|
|
|
it("deduplicates rapid create clicks and cannot close while the request is pending", () => {
|
|
const page = renderPage();
|
|
fireEvent.click(byUiId("ui.projects.plantafel.new"));
|
|
fireEvent.change(byUiId("ui.projects.plantafel.createDialog.title"), { target: { value: "Wartung" } });
|
|
fireEvent.change(byUiId("ui.projects.plantafel.createDialog.start"), { target: { value: "2026-07-21T09:00" } });
|
|
fireEvent.change(byUiId("ui.projects.plantafel.createDialog.end"), { target: { value: "2026-07-21T11:00" } });
|
|
const confirm = byUiId("ui.projects.plantafel.createDialog.confirm");
|
|
|
|
fireEvent.click(confirm);
|
|
fireEvent.click(confirm);
|
|
fireEvent.click(byUiId("ui.projects.plantafel.createDialog.cancel"));
|
|
|
|
expect(page.props.actions.onSubmit).toHaveBeenCalledTimes(1);
|
|
expect((confirm as HTMLButtonElement).disabled).toBe(true);
|
|
expect((byUiId("ui.projects.plantafel.createDialog.cancel") as HTMLButtonElement).disabled).toBe(true);
|
|
expect(screen.getByRole("dialog", { name: "projects.plantafel.newEntry" })).toBeTruthy();
|
|
});
|
|
|
|
it("keeps the dialog open on a blocking conflict and resubmits with a clear override reason", async () => {
|
|
const page = renderPage();
|
|
fireEvent.click(byUiId("ui.projects.plantafel.new"));
|
|
fireEvent.change(byUiId("ui.projects.plantafel.createDialog.title"), { target: { value: "Wartung" } });
|
|
fireEvent.change(byUiId("ui.projects.plantafel.createDialog.start"), { target: { value: "2026-07-21T09:00" } });
|
|
fireEvent.change(byUiId("ui.projects.plantafel.createDialog.end"), { target: { value: "2026-07-21T11:00" } });
|
|
fireEvent.click(byUiId("ui.projects.plantafel.createDialog.confirm"));
|
|
const firstMutationId = (page.props.actions.onSubmit as ReturnType<typeof vi.fn>).mock.calls[0]?.[1]?.clientMutationId;
|
|
|
|
const conflictResult: PlantafelActionResult = {
|
|
intent: "upsertSchedule",
|
|
error: "projects.error.scheduleConflictOverrideRequired",
|
|
};
|
|
page.rerender({ actionResult: conflictResult });
|
|
|
|
expect(screen.getByRole("dialog", { name: "projects.plantafel.newEntry" })).toBeTruthy();
|
|
expect(screen.getByRole("alert").textContent).toContain("projects.error.scheduleConflictOverrideRequired");
|
|
const overrideReason = byUiId("ui.projects.plantafel.createDialog.conflictOverrideReason");
|
|
fireEvent.change(overrideReason, { target: { value: "Kunde hat den Termin ausdrücklich bestätigt." } });
|
|
fireEvent.click(byUiId("ui.projects.plantafel.createDialog.confirm"));
|
|
|
|
expect(page.props.actions.onSubmit).toHaveBeenLastCalledWith(
|
|
"upsertSchedule",
|
|
expect.objectContaining({
|
|
conflictOverrideReason: "Kunde hat den Termin ausdrücklich bestätigt.",
|
|
clientMutationId: firstMutationId,
|
|
}),
|
|
);
|
|
|
|
page.rerender({ actionResult: { intent: "upsertSchedule", ok: true } });
|
|
await waitFor(() => expect(screen.queryByRole("dialog", { name: "projects.plantafel.newEntry" })).toBeNull());
|
|
});
|
|
|
|
it("reads the loaded monteur filter back off the facet button and clears it again", async () => {
|
|
// Same read/write contract the leads filters follow: what the loader
|
|
// resolved has to be visible on the trigger, otherwise a shared link looks
|
|
// unfiltered.
|
|
const page = renderPage({ filter: { assignedUserId: null, includePast: false, sort: "start_asc" } });
|
|
const trigger = () => byUiId("ui.projects.plantafel.filter.assignee");
|
|
|
|
expect(trigger().textContent).toContain("projects.plantafel.filterAssignee");
|
|
|
|
page.rerender({ filter: { assignedUserId: ASSIGNEE_ID, includePast: false, sort: "start_asc" } });
|
|
await waitFor(() => expect(trigger().textContent).toContain("Anna Schneider"));
|
|
|
|
// Every assignable monteur is offered, and picking the active one again is
|
|
// the way back to "all" - the chip's X does the same.
|
|
fireEvent.keyDown(trigger(), { key: "Enter" });
|
|
const options = await screen.findAllByRole("menuitem");
|
|
expect(options.map((option) => option.textContent)).toEqual([expect.stringContaining("Anna Schneider")]);
|
|
fireEvent.click(byUiId("ui.projects.plantafel.filter.assignee.rheinmain-shk-v1-employee-0049"));
|
|
expect(page.props.actions.onFilterChange).toHaveBeenLastCalledWith({ assignedUserId: null, includePast: false, sort: "start_asc" });
|
|
});
|
|
|
|
it("resets search and the loader filters through the bar's reset pill", () => {
|
|
const page = renderPage({ filter: { assignedUserId: ASSIGNEE_ID, includePast: true, sort: "title_asc" } });
|
|
|
|
fireEvent.change(byUiId("ui.projects.plantafel.filter.search"), { target: { value: "kabelkanal" } });
|
|
fireEvent.click(screen.getByText("projects.plantafel.filterReset"));
|
|
|
|
expect(page.props.actions.onFilterChange).toHaveBeenLastCalledWith({ assignedUserId: null, includePast: false, sort: "start_asc" });
|
|
expect((byUiId("ui.projects.plantafel.filter.search") as HTMLInputElement).value).toBe("");
|
|
});
|
|
|
|
it("bulk-reassigns selected entries with the picked assignee", async () => {
|
|
const page = renderPage({ canBulkReassign: true });
|
|
|
|
fireEvent.click(byUiId("ui.projects.plantafel.select.schedule-1"));
|
|
expect(byUiId("ui.projects.plantafel.bulk")).toBeTruthy();
|
|
|
|
fireEvent.click(byUiId("ui.projects.plantafel.bulk.submit"));
|
|
|
|
expect(page.props.actions.onSubmit).toHaveBeenLastCalledWith(
|
|
"bulkReassign",
|
|
expect.objectContaining({ assignedUserId: ASSIGNEE_ID }),
|
|
);
|
|
const fields = (page.props.actions.onSubmit as ReturnType<typeof vi.fn>).mock.lastCall?.[1] as Record<string, string>;
|
|
expect(JSON.parse(fields.entryIds)).toEqual(["schedule-1"]);
|
|
|
|
page.rerender({ actionResult: { intent: "bulkReassign", ok: true } });
|
|
await waitFor(() => expect(document.querySelector("[data-ui-id='ui.projects.plantafel.bulk']")).toBeNull());
|
|
});
|
|
|
|
it("opens the details read-only on a double-click in the table", () => {
|
|
renderPage();
|
|
|
|
fireEvent.doubleClick(screen.getByRole("table").querySelector("tbody tr")!);
|
|
|
|
// Read-only means: the stored values, no form, and no way to save yet.
|
|
expect(byUiId("ui.projects.plantafel.detailDialog.readOnly").textContent).toContain("Anna Schneider");
|
|
expect(document.querySelector("[data-ui-id='ui.projects.plantafel.detailDialog.save']")).toBeNull();
|
|
expect(byUiId("ui.projects.plantafel.detailDialog.close")).toBeTruthy();
|
|
});
|
|
|
|
it("opens the same popup from a calendar block, for mouse and keyboard alike", () => {
|
|
renderPage({ view: "calendar" });
|
|
|
|
const block = byUiId("ui.projects.plantafel.week.entry.schedule-1");
|
|
fireEvent.keyDown(block, { key: "Enter" });
|
|
expect(byUiId("ui.projects.plantafel.detailDialog")).toBeTruthy();
|
|
|
|
fireEvent.click(byUiId("ui.projects.plantafel.detailDialog.close"));
|
|
fireEvent.doubleClick(block);
|
|
expect(byUiId("ui.projects.plantafel.detailDialog")).toBeTruthy();
|
|
});
|
|
|
|
it("swaps the close button for save only after editing is switched on", () => {
|
|
renderPage();
|
|
|
|
fireEvent.click(byUiId("ui.projects.plantafel.detail.open.schedule-1"));
|
|
fireEvent.click(byUiId("ui.projects.plantafel.detailDialog.edit"));
|
|
|
|
expect(byUiId("ui.projects.plantafel.detailDialog.save")).toBeTruthy();
|
|
expect(document.querySelector("[data-ui-id='ui.projects.plantafel.detailDialog.close']")).toBeNull();
|
|
// The edit button has done its job and gives its place to the form.
|
|
expect(document.querySelector("[data-ui-id='ui.projects.plantafel.detailDialog.edit']")).toBeNull();
|
|
});
|
|
|
|
it("prefills the form from the stored entry and saves it back under its own id", () => {
|
|
const page = renderPage();
|
|
|
|
fireEvent.click(byUiId("ui.projects.plantafel.detail.open.schedule-1"));
|
|
fireEvent.click(byUiId("ui.projects.plantafel.detailDialog.edit"));
|
|
|
|
const title = byUiId("ui.projects.plantafel.detailDialog.title") as HTMLInputElement;
|
|
expect(title.value).toBe("Heizungstausch Auenland Gastronomie Frankfurt");
|
|
// 09:00Z in July is 11:00 in Berlin - the form shows the local wall clock.
|
|
expect((byUiId("ui.projects.plantafel.detailDialog.start") as HTMLInputElement).value).toBe("2026-07-20T11:00");
|
|
|
|
fireEvent.change(title, { target: { value: "Heizungstausch Auenland (verschoben)" } });
|
|
fireEvent.click(byUiId("ui.projects.plantafel.detailDialog.save"));
|
|
|
|
expect(page.props.actions.onSubmit).toHaveBeenLastCalledWith(
|
|
"upsertSchedule",
|
|
expect.objectContaining({
|
|
entryId: "schedule-1",
|
|
title: "Heizungstausch Auenland (verschoben)",
|
|
startAt: "2026-07-20T11:00",
|
|
endAt: "2026-07-20T14:00",
|
|
status: "confirmed",
|
|
}),
|
|
);
|
|
});
|
|
|
|
it("closes the popup once the save came back green", async () => {
|
|
const page = renderPage();
|
|
|
|
fireEvent.click(byUiId("ui.projects.plantafel.detail.open.schedule-1"));
|
|
fireEvent.click(byUiId("ui.projects.plantafel.detailDialog.edit"));
|
|
fireEvent.click(byUiId("ui.projects.plantafel.detailDialog.save"));
|
|
|
|
page.rerender({ actionResult: { intent: "upsertSchedule", ok: true } });
|
|
|
|
await waitFor(() => expect(document.querySelector("[data-ui-id='ui.projects.plantafel.detailDialog']")).toBeNull());
|
|
});
|
|
|
|
it("keeps the popup read-only for an entry the user may not edit", () => {
|
|
renderPage({ editableProjectIds: [] });
|
|
|
|
fireEvent.click(byUiId("ui.projects.plantafel.detail.open.schedule-1"));
|
|
|
|
expect(byUiId("ui.projects.plantafel.detailDialog")).toBeTruthy();
|
|
expect(document.querySelector("[data-ui-id='ui.projects.plantafel.detailDialog.edit']")).toBeNull();
|
|
});
|
|
});
|