@
All checks were successful
CI / Lint, Typen, Tests, Build (push) Successful in 11m12s
CI / Migrationen auf leerer Datenbank (push) Successful in 10m6s

Name every draft, and put Vertrag before Angehoerige

Two things the dashboard and the hire wizard were getting wrong.

The drafts card named the author only on other people's drafts. With
foreign and own rows side by side that reads as an inconsistency, not as
information: the eye has to work out that a missing name means "mine".
Now every row says it, "von mir" on the own ones -- the same wording the
notes in the bell already use.

In the wizard, Angehoerige stood before Vertrag. What a contract is made
of -- entry date, working days, a fixed term -- is on paper before the
conversation happens; relatives the person brings along, often on the
first day. The optional step came before the one the hire rests on.

Swapping them meant touching the part that would have broken silently:
the per-step validation was a positional list that had to line up with
STEP_LABELS by hand. Reordered labels alone would have left the checks
where they were -- "Weiter" on Vertrag would have validated the
relatives and waved an empty entry date through, until the database
refused it at the end. The checks are keyed by step name now, so they
travel with the step.

Drafts saved before this land on the step number they stored, which now
points at a different page. Nothing is lost -- the payload carries every
field -- but somebody resuming an older draft may open on Vertrag where
they left Angehoerige.

Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
@
This commit is contained in:
2026-09-10 16:35:20 +02:00
parent eeaf210e78
commit 2838919e42
6 changed files with 186 additions and 32 deletions

View File

@@ -27,7 +27,7 @@ function entwurf(teil: Partial<Entwurf> = {}): Entwurf {
payload: { firstName: "Manuel", lastName: "Aigner" },
updated_at: "2026-09-09T08:00:00.000Z",
vonMir: true,
autor: null,
autor: "Max Stubhan",
...teil,
};
}
@@ -62,10 +62,12 @@ describe("DraftsCard", () => {
expect(within(z).getByRole("button", { name: "Entwurf löschen" })).toBeInTheDocument();
});
it("nennt an eigenen Entwürfen keinen Verfasser", () => {
// Der eigene Name stünde an jeder Zeile und sagte nichts.
it("sagt an eigenen Entwürfen: von mir", () => {
// Der eigene Name stünde an jeder Zeile und sagte nichts — man kennt ihn.
zeige([entwurf()]);
expect(within(zeile("Manuel Aigner")).queryByText(/^von /)).not.toBeInTheDocument();
const z = zeile("Manuel Aigner");
expect(within(z).getByText("von mir")).toBeInTheDocument();
expect(within(z).queryByText(/Max Stubhan/)).not.toBeInTheDocument();
});
it("nennt an fremden Entwürfen, von wem sie stammen", () => {

View File

@@ -0,0 +1,135 @@
import { render, screen, within } from "@testing-library/react";
import userEvent from "@testing-library/user-event";
import { describe, expect, it, vi } from "vitest";
import { HireWizard } from "@/components/hire/HireWizard";
import { ToastProvider } from "@/components/ui/Toast";
import { EMPTY_HIRE_DRAFT } from "@/components/hire/types";
import type { OpenPositionResolved } from "@/lib/positions";
vi.mock("@/actions/employees", () => ({
hireEmployee: vi.fn(async () => ({ success: true })),
addEmployeeDependent: vi.fn(async () => ({ success: true })),
}));
vi.mock("@/actions/hireDrafts", () => ({
saveHireDraft: vi.fn(async () => ({ success: true })),
deleteHireDraft: vi.fn(async () => ({ success: true })),
}));
vi.mock("next/navigation", () => ({ useRouter: () => ({ refresh: vi.fn(), push: vi.fn() }) }));
// Die Reihenfolge der Schritte und die Prüfung, die an jedem hängt, standen
// bis September 2026 in zwei Listen, die stumm zusammenpassen mussten. Beim
// Vertauschen von Vertrag und Angehörige wäre die Prüfung stehengeblieben,
// wo sie war — „Weiter" im Vertrag hätte die Angehörigen geprüft und ein
// leeres Eintrittsdatum durchgelassen, bis die Datenbank es am Ende abweist.
// Deshalb steht beides hier: die Abfolge und der Riegel am richtigen Schritt.
const POSITION = {
id: "p1",
title: "Sachbearbeiter:in",
orgUnitName: "Personal",
} as unknown as OpenPositionResolved;
const LOCATIONS = [{ id: "l1", name: "Wien", country: "AT" }];
/** Steigt mitten im Assistenten ein — ein Entwurf ist genau dafür da. */
function zeige(step: number, payload: Partial<typeof EMPTY_HIRE_DRAFT> = {}) {
return render(
<ToastProvider>
<HireWizard
open
onClose={() => {}}
openPositions={[POSITION]}
locations={LOCATIONS}
resumeDraft={{ id: "d1", step, payload: { ...EMPTY_HIRE_DRAFT, ...payload } }}
/>
</ToastProvider>
);
}
const weiter = () => screen.getByRole("button", { name: "Weiter" });
describe("Abfolge der Schritte", () => {
it("führt Vertrag vor Angehörige", () => {
zeige(0);
const trail = screen.getAllByRole("button").filter((b) => /^\d/.test(b.textContent ?? ""));
expect(trail.map((b) => b.textContent?.replace(/^\d/, ""))).toEqual([
"Person",
"Position",
"Vertrag",
"Angehörige",
"Notfallkontakt",
"Zusammenfassung",
]);
});
it("zeigt an Schritt 3 den Vertrag", () => {
zeige(2);
expect(screen.getByLabelText(/Eintrittsdatum/)).toBeInTheDocument();
});
it("zeigt an Schritt 4 die Angehörigen", () => {
zeige(3);
expect(screen.getByRole("button", { name: /Angehörige:n hinzufügen/ })).toBeInTheDocument();
});
it("hält im Vertrag ohne Eintrittsdatum an", () => {
// Der Riegel muss mit dem Schritt gewandert sein. Bleibt er bei den
// Angehörigen, ist „Weiter" hier offen — und das Eintrittsdatum fehlt
// bis zum Anlegen.
zeige(2, { entryDate: "" });
expect(weiter()).toBeDisabled();
});
it("lässt im Vertrag mit Eintrittsdatum weiter", () => {
zeige(2, { entryDate: "2026-10-01" });
expect(weiter()).toBeEnabled();
});
it("lässt die Angehörigen leer durch", async () => {
// Freiwillig — der Schritt darf niemanden aufhalten.
zeige(3);
expect(weiter()).toBeEnabled();
});
it("hält bei einer angefangenen Angehörigen-Zeile an", async () => {
// Sie scheitert sonst erst nach dem Anlegen der Person, und die steht
// dann schon in der Datenbank.
const user = userEvent.setup();
zeige(3);
await user.click(screen.getByRole("button", { name: /Angehörige:n hinzufügen/ }));
expect(weiter()).toBeDisabled();
});
it("blättert vom Vertrag zu den Angehörigen", async () => {
const user = userEvent.setup();
zeige(2, { entryDate: "2026-10-01" });
await user.click(weiter());
expect(screen.getByRole("button", { name: /Angehörige:n hinzufügen/ })).toBeInTheDocument();
expect(screen.queryByLabelText(/Eintrittsdatum/)).not.toBeInTheDocument();
});
it("blättert von den Angehörigen zurück zum Vertrag", async () => {
// Der Weg zurück führt dorthin, wo man herkam — sonst springt der
// Assistent an eine Stelle, die niemand erwartet.
const user = userEvent.setup();
zeige(3);
await user.click(screen.getByRole("button", { name: "Zurück" }));
expect(screen.getByLabelText(/Eintrittsdatum/)).toBeInTheDocument();
});
});
describe("Fortschrittsleiste", () => {
it("markiert den Schritt, auf dem man steht", () => {
zeige(2);
const aktuell = screen.getAllByRole("button").find((b) => b.getAttribute("aria-current") === "step");
expect(aktuell).toHaveTextContent("Vertrag");
});
it("lässt nur zurück, nicht vor", () => {
zeige(2);
const trail = screen.getAllByRole("button").filter((b) => /^\d/.test(b.textContent ?? ""));
const nach = (label: string) => trail.find((b) => within(b).queryByText(label) ?? b.textContent?.includes(label));
expect(nach("Position")).toBeEnabled();
expect(nach("Angehörige")).toBeDisabled();
});
});