Let the overview say what "upcoming" means

Sixty days and all three kinds was a guess, and it was the only one on
offer. Payroll cares about next month; the person filling a vacancy
cares about entries and nothing else. The card now takes a period and a
set of kinds.

The choice lives in the address rather than in the browser, because it
has to: the page is built on the server, and ninety days pulls in rows
that were never loaded at sixty. Filtering client-side would silently
cap the answer at whatever the first query happened to fetch. It also
means a filtered overview can be sent to someone and opened again the
same way.

Deselecting every kind returns to all of them. An empty card is not an
answer to a question nobody asked, and the way back would otherwise be
one click further than the way in. The default period and the full set
are absent from the URL instead of written into it, so a shared link
carries only what was actually chosen.

Anything the address cannot be trusted to hold is rejected: an unknown
period falls back to sixty rather than reaching the query, which would
otherwise be an invitation to ask for ten years of rows through a link.

Eight rows still, with a count of what did not fit underneath — this is
an overview, and the employee list is where lists belong.

Not verified in a browser: the built-in preview has no company sign-in,
so the page redirects to the login before it renders. Types, lint and
386 tests pass, and the filter's behaviour is covered directly.

Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
This commit is contained in:
2026-08-16 18:56:05 +02:00
parent 16216c5537
commit 6957b95a97
5 changed files with 361 additions and 30 deletions

View File

@@ -0,0 +1,73 @@
import { describe, expect, it } from "vitest";
import {
ANSTEHEND_ARTEN,
STANDARD_ZEITRAUM,
istEingeschraenkt,
parseArten,
parseZeitraum,
} from "@/lib/dashboard-filter";
// Die Auswahl steht in der Adresse, und dort kann alles stehen: eine
// veraltete Verknüpfung, ein Tippfehler, ein abgeschnittener Wert. Sie darf
// die Übersicht weder leeren noch mit einem Zeitraum laden, den niemand
// gewählt hat.
describe("parseZeitraum", () => {
it("nimmt die angebotenen Zeiträume", () => {
expect(parseZeitraum("30")).toBe(30);
expect(parseZeitraum("180")).toBe(180);
});
it("fällt ohne Angabe auf den Standard zurück", () => {
expect(parseZeitraum(undefined)).toBe(STANDARD_ZEITRAUM);
expect(parseZeitraum("")).toBe(STANDARD_ZEITRAUM);
});
it("lässt sich keinen beliebigen Zeitraum unterschieben", () => {
// Sonst liesse sich über die Adresse ein Lesevorgang über Jahre auslösen.
expect(parseZeitraum("3650")).toBe(STANDARD_ZEITRAUM);
expect(parseZeitraum("-5")).toBe(STANDARD_ZEITRAUM);
expect(parseZeitraum("60; drop")).toBe(STANDARD_ZEITRAUM);
});
});
describe("parseArten", () => {
const alle = ANSTEHEND_ARTEN.map((a) => a.value);
it("versteht eine Auswahl", () => {
expect(parseArten("hire,exit")).toEqual(["hire", "exit"]);
});
it("liest ohne Angabe alle — eine leere Karte wäre die falsche Antwort", () => {
expect(parseArten(undefined)).toEqual(alle);
expect(parseArten("")).toEqual(alle);
});
it("verwirft Unbekanntes und behält den Rest", () => {
expect(parseArten("hire,unfug")).toEqual(["hire"]);
});
it("führt eine Auswahl aus lauter Unbekanntem auf alle zurück", () => {
expect(parseArten("unfug,quatsch")).toEqual(alle);
});
it("stört sich nicht an Leerzeichen", () => {
expect(parseArten(" hire , return ")).toEqual(["hire", "return"]);
});
});
describe("istEingeschraenkt", () => {
const alle = ANSTEHEND_ARTEN.map((a) => a.value);
it("erkennt den unveränderten Zustand", () => {
expect(istEingeschraenkt(STANDARD_ZEITRAUM, alle)).toBe(false);
});
it("erkennt einen anderen Zeitraum", () => {
expect(istEingeschraenkt(90, alle)).toBe(true);
});
it("erkennt eine engere Auswahl", () => {
expect(istEingeschraenkt(STANDARD_ZEITRAUM, ["hire"])).toBe(true);
});
});