Files
alpenwerk-hr/tests/components/RoleEmploymentFields.test.tsx
Maximilian Stubhan f17d299045
Some checks failed
CI / Lint, Typen, Tests, Build (push) Successful in 10m51s
CI / Migrationen auf leerer Datenbank (push) Has been cancelled
Lehrling, and a field that stops being named after its values
worker_type had two values because the field was named after them:
"Angestellte:r / Arbeiter:in". Lehrlinge are the third social-insurance
category in Austria; until now they were filed as one of the other two,
which they are not -- and which skewed every report grouped by this
column by exactly those people.

Adding the value is one line. The label was the work: the field was
called after its two values in six places, and each of them becomes
wrong with a third. They now read "Beschaeftigtengruppe", the name the
import has used all along.

One label deliberately keeps the old wording: app_feld_karte() in the
database. That string is not a caption there but a key -- stored rows in
employee_history and pending_changes carry it, and the map is how
reverting or correcting a history entry finds the field again. Renaming
it without rewriting those rows would make every older entry for this
field unrevertable, and nobody would notice until they tried.

The migration's assertion reads pg_enum rather than comparing against
'Lehrling'::worker_type: migrations run inside a transaction, and
Postgres refuses to use a freshly added enum value in the transaction
that added it. This has not been run against a live database here -- the
CI migration job is the first real execution.

Three hand-kept lists of the same enum (reports, import, the form) now
have a test holding them to one another, each mutation-checked.

Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
2026-09-10 17:28:49 +02:00

48 lines
1.7 KiB
TypeScript

import { render, screen, within } from "@testing-library/react";
import { describe, expect, it } from "vitest";
import { RoleEmploymentFields, type RoleEmploymentValue } from "@/components/employees/RoleEmploymentFields";
// Das Auswahlfeld ist die vierte Liste der Beschäftigtengruppen (neben dem
// Enum, den Auswertungen und dem Import — tests/unit/beschaeftigtengruppe).
// Fehlt ein Wert hier, ist er schlicht nicht einzugeben, und niemand merkt
// es: das Feld sieht vollständig aus.
const WERT: RoleEmploymentValue = {
workerType: "Angestellte:r",
collectiveAgreement: "Handel",
workDays: ["Mo", "Di", "Mi", "Do", "Fr"],
isBetriebsrat: false,
hasDienstwagen: false,
dienstwagenArt: "Verbrenner",
isLateraleFuehrung: false,
isCLevel: false,
hasKuendigungsschutz: false,
kuendigungsschutzBis: "",
};
function feld(teil: Partial<RoleEmploymentValue> = {}) {
render(<RoleEmploymentFields value={{ ...WERT, ...teil }} onChange={() => {}} />);
return screen.getByLabelText("Beschäftigtengruppe");
}
describe("Beschäftigtengruppe im Formular", () => {
it("bietet alle drei Gruppen an", () => {
expect(within(feld()).getAllByRole("option").map((o) => o.textContent)).toEqual([
"Angestellte:r",
"Arbeiter:in",
"Lehrling",
]);
});
it("heisst Beschäftigtengruppe, nicht mehr nach zwei ihrer Werte", () => {
// „Angestellte:r / Arbeiter:in" war der Name bis September 2026 — er
// wurde falsch, sobald ein dritter Wert dazukam.
feld();
expect(screen.queryByLabelText(/Arbeiter:in/)).not.toBeInTheDocument();
});
it("zeigt die gespeicherte Gruppe als gewählt", () => {
expect(feld({ workerType: "Lehrling" })).toHaveValue("Lehrling");
});
});