fix(allocations): recover from fully filtered empty state

This commit is contained in:
2026-04-01 15:16:57 +02:00
parent 7df751d5eb
commit fd75628e9d
3 changed files with 185 additions and 2 deletions
@@ -0,0 +1,68 @@
import { describe, expect, it } from "vitest";
import { getAllocationEmptyState, shouldAutoRelaxAllocationFilters } from "./allocationVisibilityState.js";
describe("allocationVisibilityState", () => {
it("auto-relaxes default project filters when they hide every available row", () => {
expect(
shouldAutoRelaxAllocationFilters({
totalAssignments: 8,
totalDemands: 2,
visibleAssignments: 0,
visibleDemands: 0,
hidePastProjects: true,
hideCompletedProjects: true,
hideDraftProjects: false,
}),
).toBe(true);
});
it("does not auto-relax when there is no underlying allocation data", () => {
expect(
shouldAutoRelaxAllocationFilters({
totalAssignments: 0,
totalDemands: 0,
visibleAssignments: 0,
visibleDemands: 0,
hidePastProjects: true,
hideCompletedProjects: true,
hideDraftProjects: false,
}),
).toBe(false);
});
it("builds a filter-aware empty state when rows are hidden", () => {
expect(
getAllocationEmptyState({
totalAssignments: 5,
totalDemands: 1,
visibleAssignments: 0,
visibleDemands: 0,
hidePastProjects: true,
hideCompletedProjects: true,
hideDraftProjects: false,
}),
).toEqual({
title: "No assignments match the active filters.",
detail: "5 assignments and 1 demand are hidden by the active project filters.",
showResetAction: true,
});
});
it("keeps the plain empty state when there is genuinely no data", () => {
expect(
getAllocationEmptyState({
totalAssignments: 0,
totalDemands: 0,
visibleAssignments: 0,
visibleDemands: 0,
hidePastProjects: false,
hideCompletedProjects: false,
hideDraftProjects: false,
}),
).toEqual({
title: "No assignments found.",
detail: "Create a planning entry or relax the current project filters once data is available.",
showResetAction: false,
});
});
});