Derive the filter test's list from the registry it tests
Adding the follow-up kind turned one of these tests green-for-the-wrong- reason and one red: both had the three kinds written out by hand, so "all of them are selected" no longer meant what the name said. That is the failure mode a hand-copied list has — it does not break loudly, it drifts. The list now comes from ANSTEHEND_ARTEN, and the two cases that depend on completeness build their input from it. I committed the previous change with this test red. That was wrong; it should have blocked the commit. Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
This commit is contained in:
@@ -2,6 +2,7 @@ import { render, screen } from "@testing-library/react";
|
||||
import userEvent from "@testing-library/user-event";
|
||||
import { beforeEach, describe, expect, it, vi } from "vitest";
|
||||
import { AnstehendFilter } from "@/components/dashboard/AnstehendFilter";
|
||||
import { ANSTEHEND_ARTEN, type AnstehendArt } from "@/lib/dashboard-filter";
|
||||
|
||||
// Die Auswahl muss in die Adresse, nicht in den Browser-Zustand: die
|
||||
// Übersicht wird auf dem Server gebaut, und ein längerer Zeitraum bringt
|
||||
@@ -17,7 +18,10 @@ vi.mock("next/navigation", () => ({
|
||||
useSearchParams: () => new URLSearchParams(suchString),
|
||||
}));
|
||||
|
||||
const ALLE = ["hire", "exit", "return"] as const;
|
||||
// Aus dem Verzeichnis abgeleitet, nicht abgeschrieben: eine neue Art hätte
|
||||
// diesen Test sonst stillschweigend am falschen Fall prüfen lassen — genau das
|
||||
// ist beim Hinzufügen der Wiedervorlage passiert.
|
||||
const ALLE: AnstehendArt[] = ANSTEHEND_ARTEN.map((a) => a.value);
|
||||
|
||||
beforeEach(() => {
|
||||
replace.mockClear();
|
||||
@@ -45,7 +49,8 @@ describe("AnstehendFilter", () => {
|
||||
const user = userEvent.setup();
|
||||
render(<AnstehendFilter zeitraum={60} arten={[...ALLE]} />);
|
||||
await user.click(screen.getByRole("button", { name: "Austritt" }));
|
||||
expect(replace).toHaveBeenCalledWith("/?arten=hire%2Creturn", { scroll: false });
|
||||
const erwartet = encodeURIComponent(ALLE.filter((a) => a !== "exit").join(","));
|
||||
expect(replace).toHaveBeenCalledWith(`/?arten=${erwartet}`, { scroll: false });
|
||||
});
|
||||
|
||||
it("nimmt eine wieder hinzugewählte Art auf", async () => {
|
||||
@@ -68,9 +73,14 @@ describe("AnstehendFilter", () => {
|
||||
|
||||
it("lässt vollständige Auswahl gar nicht erst in der Adresse stehen", async () => {
|
||||
const user = userEvent.setup();
|
||||
suchString = "arten=hire,exit";
|
||||
render(<AnstehendFilter zeitraum={60} arten={["hire", "exit"]} />);
|
||||
await user.click(screen.getByRole("button", { name: "Rückkehr" }));
|
||||
// Die letzte fehlende Art wieder dazu: dann ist wieder alles gewählt, und
|
||||
// das gehört nicht in die Adresse. Bewusst über ALLE gebildet statt
|
||||
// abgeschrieben — sonst prüft dieser Test nach der nächsten neuen Art die
|
||||
// falsche Bedingung.
|
||||
const bisAufEine = ALLE.slice(0, -1);
|
||||
suchString = `arten=${bisAufEine.join(",")}`;
|
||||
render(<AnstehendFilter zeitraum={60} arten={[...bisAufEine]} />);
|
||||
await user.click(screen.getByRole("button", { name: "Wiedervorlage" }));
|
||||
expect(replace).toHaveBeenCalledWith("/", { scroll: false });
|
||||
});
|
||||
|
||||
|
||||
Reference in New Issue
Block a user