Works council members, expectant mothers, parents on leave, registered disabled employees, apprentices — each has its own rules that come before a dismissal. The tool does not judge whether one is lawful, but it must not stay quiet about it either, and looking it up on the contract tab is exactly the step that gets skipped under time pressure. So: a checkbox, an optional end date, and a red warning at the top of the termination panel naming the date — or saying plainly that no end was recorded. It shows for a no-show too; the protection runs from the start of the contract, not the first day worked. The date is optional on purpose. A works council mandate has a known end, a pregnancy does not, and a mandatory field would force an invented number. A constraint says only what cannot be: an end date without the flag, which would be a leftover nobody could interpret. The field goes the whole way through — hire, data change, contract sheet, export, report criteria (as a yes/no and as a date range), and the import. A field that exists in one screen and not the next is how people stop trusting the numbers. Terminating is now offered for planned entries as well, labelled "Nicht angetreten", with No Show preselected. Without it a person who never turned up stayed a planned entry forever, since nothing else can end one. One finding worth recording: tsc has been reporting success on a broken program. A generated file under .next got corrupted when a build ran against a live dev server, and its syntax errors suppressed semantic checking everywhere else — two genuine type errors in this change went unreported until I typechecked with .next excluded. The file is removed and the ordinary typecheck is meaningful again. Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
178 lines
6.6 KiB
TypeScript
178 lines
6.6 KiB
TypeScript
import { render, screen } from "@testing-library/react";
|
|
import userEvent from "@testing-library/user-event";
|
|
import { describe, expect, it, vi } from "vitest";
|
|
import { TerminatePanel } from "@/components/employees/panels/TerminatePanel";
|
|
import { ToastProvider } from "@/components/ui/Toast";
|
|
import type { Database } from "@/lib/supabase/types";
|
|
|
|
type EmployeeRow = Database["public"]["Tables"]["employees"]["Row"];
|
|
|
|
vi.mock("@/actions/employees", () => ({
|
|
terminateEmployee: vi.fn(async () => ({ success: true })),
|
|
}));
|
|
vi.mock("next/navigation", () => ({ useRouter: () => ({ refresh: vi.fn(), push: vi.fn() }) }));
|
|
|
|
// Wer nie angetreten ist, scheidet am Tag seines Eintritts aus. Nur so gibt es
|
|
// keinen Stichtag, an dem die Person als beschäftigt zählt — „nie aktiv"
|
|
// folgt aus dem Datum, nicht aus einer Sonderregel im Auswerten.
|
|
|
|
const EINTRITT = "2026-09-10";
|
|
|
|
function mitarbeiter(teil: Partial<EmployeeRow> = {}): EmployeeRow {
|
|
return {
|
|
id: "e1",
|
|
personnel_number: 3038,
|
|
first_name: "Hannah",
|
|
last_name: "Winkler",
|
|
gender: "w",
|
|
birth_date: "1990-04-01",
|
|
sv_nummer: null,
|
|
nationality: "Österreich",
|
|
address: null,
|
|
address_country: null,
|
|
postal_code: null,
|
|
city: null,
|
|
email: null,
|
|
phone: null,
|
|
job_title: "IT-Security-Spezialist:in",
|
|
location_id: "l1",
|
|
employment_type: "Vollzeit",
|
|
weekly_hours: 38.5,
|
|
monthly_salary_gross: null,
|
|
contract_type: "unbefristet",
|
|
contract_end_date: null,
|
|
paygrade: "C",
|
|
source: "Extern",
|
|
status: "Geplant",
|
|
entry_date: EINTRITT,
|
|
exit_date: null,
|
|
exit_reason: null,
|
|
karenz_start_date: null,
|
|
karenz_return_date: null,
|
|
absence_type: null,
|
|
avatar_color: null,
|
|
worker_type: "Angestellte:r",
|
|
collective_agreement: "Handel",
|
|
work_days: ["Mo", "Di", "Mi", "Do", "Fr"],
|
|
is_betriebsrat: false,
|
|
has_dienstwagen: false,
|
|
dienstwagen_art: null,
|
|
has_kuendigungsschutz: false,
|
|
kuendigungsschutz_bis: null,
|
|
is_laterale_fuehrung: false,
|
|
is_c_level: false,
|
|
title_prefix: [],
|
|
title_suffix: [],
|
|
emergency_contact_name: null,
|
|
emergency_contact_phone: null,
|
|
emergency_contact_relation: null,
|
|
created_at: "2026-08-01T00:00:00.000Z",
|
|
updated_at: "2026-08-01T00:00:00.000Z",
|
|
...teil,
|
|
} as EmployeeRow;
|
|
}
|
|
|
|
function zeige(teil: Partial<EmployeeRow> = {}) {
|
|
return render(
|
|
<ToastProvider>
|
|
<TerminatePanel open onClose={() => {}} employee={mitarbeiter(teil)} directReportCount={0} />
|
|
</ToastProvider>
|
|
);
|
|
}
|
|
|
|
describe("TerminatePanel — Nichtantritt", () => {
|
|
it("bietet No Show als Beendigungsart an", () => {
|
|
zeige();
|
|
expect(screen.getByRole("option", { name: "No Show (nicht angetreten)" })).toBeInTheDocument();
|
|
});
|
|
|
|
it("lässt das Datum bei einem gewöhnlichen Austritt frei", () => {
|
|
zeige({ status: "Aktiv" });
|
|
const feld = screen.getByLabelText(/Austrittsdatum/);
|
|
expect(feld).toBeEnabled();
|
|
expect(feld).toHaveValue("");
|
|
});
|
|
|
|
it("setzt das Datum bei No Show auf den Eintrittstag und sperrt es", async () => {
|
|
const user = userEvent.setup();
|
|
zeige();
|
|
await user.selectOptions(screen.getByLabelText("Beendigungsart"), "No Show");
|
|
|
|
const feld = screen.getByLabelText(/Wirksam am/);
|
|
expect(feld).toHaveValue(EINTRITT);
|
|
expect(feld).toBeDisabled();
|
|
});
|
|
|
|
it("schickt den Eintrittstag, auch wenn vorher ein anderes Datum dastand", async () => {
|
|
const user = userEvent.setup();
|
|
const { terminateEmployee } = await import("@/actions/employees");
|
|
zeige({ status: "Aktiv" });
|
|
|
|
// Erst ein Datum eintippen, dann auf No Show wechseln.
|
|
await user.type(screen.getByLabelText(/Austrittsdatum/), "2026-12-31");
|
|
await user.selectOptions(screen.getByLabelText("Beendigungsart"), "No Show");
|
|
await user.click(screen.getByRole("button", { name: "Austritt bestätigen" }));
|
|
|
|
expect(terminateEmployee).toHaveBeenCalledWith(
|
|
expect.objectContaining({ exit_date: EINTRITT, exit_reason: "No Show" })
|
|
);
|
|
});
|
|
|
|
it("blendet die Offboarding-Checkliste aus — ausgegeben wurde nie etwas", async () => {
|
|
const user = userEvent.setup();
|
|
zeige({ status: "Aktiv" });
|
|
expect(screen.getByText("Offboarding-Checkliste")).toBeVisible();
|
|
await user.selectOptions(screen.getByLabelText("Beendigungsart"), "No Show");
|
|
expect(screen.getByText("Offboarding-Checkliste")).not.toBeVisible();
|
|
});
|
|
|
|
it("sagt, was mit der Planstelle passiert", async () => {
|
|
const user = userEvent.setup();
|
|
zeige();
|
|
await user.selectOptions(screen.getByLabelText("Beendigungsart"), "No Show");
|
|
expect(screen.getByText(/Planstelle wird wieder frei/)).toBeInTheDocument();
|
|
});
|
|
});
|
|
|
|
// Besonderer Kündigungsschutz: Betriebsrat, Mutterschutz, Karenz, begünstigte
|
|
// Behinderung, Lehre. Die Anwendung entscheidet nicht, ob eine Beendigung
|
|
// zulässig ist — sie darf es aber auch nicht verschweigen. Im Vertragsblatt
|
|
// nachzusehen ist genau der Schritt, den man unter Zeitdruck auslässt.
|
|
describe("TerminatePanel — Kündigungsschutz", () => {
|
|
it("warnt mit dem Enddatum, wenn eines erfasst ist", () => {
|
|
zeige({ has_kuendigungsschutz: true, kuendigungsschutz_bis: "2027-06-30" });
|
|
expect(screen.getByText(/Achtung: besonderer Kündigungsschutz bis 30\.06\.2027/)).toBeInTheDocument();
|
|
});
|
|
|
|
it("warnt auch ohne Enddatum, und sagt dass keines erfasst ist", () => {
|
|
zeige({ has_kuendigungsschutz: true, kuendigungsschutz_bis: null });
|
|
expect(screen.getByText(/Ende nicht erfasst/)).toBeInTheDocument();
|
|
});
|
|
|
|
it("schweigt, wo kein Schutz besteht", () => {
|
|
zeige();
|
|
expect(screen.queryByText(/besonderer Kündigungsschutz/i)).not.toBeInTheDocument();
|
|
});
|
|
|
|
it("warnt auch bei einem Nichtantritt — der Schutz gilt ab Vertragsbeginn", async () => {
|
|
const user = userEvent.setup();
|
|
zeige({ has_kuendigungsschutz: true, kuendigungsschutz_bis: "2027-06-30" });
|
|
await user.selectOptions(screen.getByLabelText("Beendigungsart"), "No Show");
|
|
expect(screen.getByText(/Achtung: besonderer Kündigungsschutz/)).toBeInTheDocument();
|
|
});
|
|
});
|
|
|
|
describe("TerminatePanel — geplanter Eintritt", () => {
|
|
it("schlägt bei einem geplanten Eintritt No Show vor", () => {
|
|
zeige({ status: "Geplant" });
|
|
expect(screen.getByLabelText("Beendigungsart")).toHaveValue("No Show");
|
|
expect(screen.getByRole("heading", { name: "Nicht angetreten" })).toBeInTheDocument();
|
|
});
|
|
|
|
it("bleibt bei einer aktiven Person beim gewöhnlichen Austritt", () => {
|
|
zeige({ status: "Aktiv" });
|
|
expect(screen.getByLabelText("Beendigungsart")).toHaveValue("Einvernehmliche Auflösung");
|
|
expect(screen.getByRole("heading", { name: "Austritt" })).toBeInTheDocument();
|
|
});
|
|
});
|