Files
alpenwerk-hr/tests/components/Lookup.test.tsx
Raphael Müllner 643fd79f88 Übergabestand 2026-10-29
Alpenwerk HR 0.1.0

Betrieb auf Windows Server
- Die Anwendung läuft im IIS (HttpPlatformHandler) unter dem Konto des Anwendungspools, ohne Administratorrechte und ohne eigenen Windows-Dienst
- Das Zertifikat kommt aus dem Zertifikatsspeicher; die Bindung folgt jeder Erneuerung automatisch
- Neue Versionen mit aktualisieren.ps1 -Paket <zip>, mit Sicherung vorab; Rückstieg mit zuruecksetzen.ps1
- HR-Zugang für ganze Domains mit freischalten.ps1 -Domain; Einzelsperren haben Vorrang
- Anmeldung ausschließlich über Microsoft Entra ID
- Das Windows-Paket hängt an jedem Release

Fachliche Erweiterungen
- Änderungen per Austauschdatei importieren, mit Vorschau, Prüfung und Fehlerdatei
- Einstellung: eigene Maske für externe Personen, Übernahme von Leiharbeitskräften, Planstellen zum Eintrittstag
- Organisationsstruktur: Einheiten und Kostenstellen anlegen, umbenennen und abschließen; Suche nach Planstelle, Einheit und Kostenstelle
- Historie: Austritt, Versetzung und Eintritt berichtigen oder zurücknehmen; Planstelle mit Bezeichnung
- Abwesenheiten ohne Ende, geplante Abwesenheiten mit Art, Checklisten mit Anlass, auch zur Rückkehr
- Berichte mit Mehrfachauswahl in allen Kriterien; Kostenstelle als Filter und Gruppierung
- Stammdaten: mehrere Notfallkontakte, Lehrzeit, Ferialkraft, Altersteilzeit, erweiterte Beschäftigtengruppen und Geschlechtsangaben
2026-10-29 19:21:21 +01:00

131 lines
4.9 KiB
TypeScript

import { render, screen, waitFor } from "@testing-library/react";
import userEvent from "@testing-library/user-event";
import { describe, expect, it, vi } from "vitest";
import { Lookup } from "@/components/ui/Lookup";
type Person = { id: string; name: string };
const PEOPLE: Person[] = [
{ id: "1", name: "Katharina Aigner" },
{ id: "2", name: "Kurt Aigner" },
{ id: "3", name: "Simon Aigner" },
];
function renderLookup(onSelect = vi.fn(), alleAnzeigen = false) {
const onSearch = vi.fn(async (q: string) => PEOPLE.filter((p) => p.name.toLowerCase().includes(q.toLowerCase())));
render(
<Lookup<Person>
onSearch={onSearch}
onSelect={onSelect}
renderResult={(p) => <span>{p.name}</span>}
placeholder="Suchen…"
alleAnzeigen={alleAnzeigen}
/>
);
return { onSelect, onSearch, input: screen.getByRole("combobox") };
}
describe("Lookup mit alleAnzeigen", () => {
it("öffnet über die Lupe die ganze Liste, ohne dass getippt wurde", async () => {
const { onSearch } = renderLookup(vi.fn(), true);
await userEvent.click(screen.getByRole("button", { name: "Alle anzeigen" }));
expect(await screen.findAllByRole("option")).toHaveLength(3);
expect(onSearch).toHaveBeenCalledWith("");
});
it("öffnet mit Pfeil nach unten", async () => {
const { input } = renderLookup(vi.fn(), true);
input.focus();
await userEvent.keyboard("{ArrowDown}");
expect(await screen.findAllByRole("option")).toHaveLength(3);
});
it("grenzt nach dem Öffnen schon ab dem ersten Zeichen ein", async () => {
const { input } = renderLookup(vi.fn(), true);
await userEvent.click(screen.getByRole("button", { name: "Alle anzeigen" }));
await screen.findAllByRole("option");
await userEvent.type(input, "K");
await waitFor(() => expect(screen.getAllByRole("option")).toHaveLength(2));
});
it("ohne die Einstellung ist die Lupe nur ein Zeichen", () => {
renderLookup();
expect(screen.queryByRole("button", { name: "Alle anzeigen" })).not.toBeInTheDocument();
});
});
// A plain text input with a div of clickable buttons under it would be
// typeable, but offer no keyboard path to a result and nothing announcing
// that a list has appeared.
describe("Lookup keyboard operation", () => {
it("exposes combobox semantics", async () => {
const { input } = renderLookup();
expect(input).toHaveAttribute("aria-expanded", "false");
await userEvent.type(input, "Aigner");
expect(await screen.findByRole("listbox")).toBeInTheDocument();
expect(input).toHaveAttribute("aria-expanded", "true");
expect(await screen.findAllByRole("option")).toHaveLength(3);
});
it("moves the selection with the arrow keys", async () => {
const { input } = renderLookup();
await userEvent.type(input, "Aigner");
await screen.findByRole("listbox");
const options = screen.getAllByRole("option");
expect(options[0]).toHaveAttribute("aria-selected", "true");
await userEvent.keyboard("{ArrowDown}");
expect(screen.getAllByRole("option")[1]).toHaveAttribute("aria-selected", "true");
// aria-activedescendant is what tells a screen reader which row is
// current while focus stays in the input.
expect(input).toHaveAttribute("aria-activedescendant", screen.getAllByRole("option")[1].id);
});
it("wraps around at the ends", async () => {
const { input } = renderLookup();
await userEvent.type(input, "Aigner");
await screen.findByRole("listbox");
await userEvent.keyboard("{ArrowUp}");
expect(screen.getAllByRole("option")[2]).toHaveAttribute("aria-selected", "true");
await userEvent.keyboard("{ArrowDown}");
expect(screen.getAllByRole("option")[0]).toHaveAttribute("aria-selected", "true");
});
it("selects the highlighted result with Enter", async () => {
const { input, onSelect } = renderLookup();
await userEvent.type(input, "Aigner");
await screen.findByRole("listbox");
await userEvent.keyboard("{ArrowDown}{Enter}");
expect(onSelect).toHaveBeenCalledWith(PEOPLE[1]);
// Clears itself afterwards, ready for the next search.
expect(input).toHaveValue("");
});
it("closes on Escape without selecting", async () => {
const { input, onSelect } = renderLookup();
await userEvent.type(input, "Aigner");
await screen.findByRole("listbox");
await userEvent.keyboard("{Escape}");
expect(screen.queryByRole("listbox")).not.toBeInTheDocument();
expect(onSelect).not.toHaveBeenCalled();
});
it("does not open below the minimum query length", async () => {
const { input } = renderLookup();
await userEvent.type(input, "A");
expect(screen.queryByRole("listbox")).not.toBeInTheDocument();
});
it("still selects on click", async () => {
const { input, onSelect } = renderLookup();
await userEvent.type(input, "Kurt");
await screen.findByRole("listbox");
await userEvent.click(screen.getByRole("option", { name: "Kurt Aigner" }));
expect(onSelect).toHaveBeenCalledWith(PEOPLE[1]);
});
});