fix(web): keep segmented timeline allocations actionable

This commit is contained in:
2026-04-01 08:54:15 +02:00
parent 6249f61ce1
commit 4edf3a32ac
5 changed files with 334 additions and 48 deletions
@@ -0,0 +1,96 @@
import React from "react";
import { renderToStaticMarkup } from "react-dom/server";
import { beforeEach, describe, expect, it, vi } from "vitest";
import { AllocationPopover } from "./AllocationPopover.js";
const mockUseQuery = vi.fn();
const mockUseMutation = vi.fn(() => ({ mutate: vi.fn() }));
const mockUseUtils = vi.fn(() => ({
allocation: {
getAssignmentById: { invalidate: vi.fn() },
listView: { invalidate: vi.fn() },
},
}));
vi.mock("~/lib/trpc/client.js", () => ({
trpc: {
useUtils: () => mockUseUtils(),
allocation: {
getAssignmentById: {
useQuery: (...args: unknown[]) => mockUseQuery(...args),
},
},
timeline: {
updateAllocationInline: {
useMutation: () => mockUseMutation(),
},
carveAllocationRange: {
useMutation: () => mockUseMutation(),
},
},
},
}));
vi.mock("~/hooks/useInvalidatePlanningViews.js", () => ({
useInvalidateTimeline: () => vi.fn(),
}));
vi.mock("~/hooks/useViewportPopover.js", () => ({
useViewportPopover: () => ({
ref: { current: null },
style: {},
}),
}));
describe("AllocationPopover", () => {
beforeEach(() => {
mockUseQuery.mockReset();
mockUseMutation.mockClear();
mockUseUtils.mockClear();
});
it("renders an error state when the allocation lookup fails", () => {
mockUseQuery.mockReturnValue({
data: undefined,
isLoading: false,
error: new Error("Assignment not found"),
});
const html = renderToStaticMarkup(
<AllocationPopover
allocationId="assignment_missing"
projectId="project_1"
anchorX={120}
anchorY={40}
onClose={() => {}}
onOpenPanel={() => {}}
/>,
);
expect(html).toContain("data-testid=\"timeline-allocation-popover-error\"");
expect(html).toContain("The selected booking could not be loaded right now.");
expect(html).toContain("Assignment not found");
});
it("renders an unavailable state when the lookup returns no allocation", () => {
mockUseQuery.mockReturnValue({
data: undefined,
isLoading: false,
error: null,
});
const html = renderToStaticMarkup(
<AllocationPopover
allocationId="assignment_missing"
projectId="project_1"
anchorX={120}
anchorY={40}
onClose={() => {}}
onOpenPanel={() => {}}
/>,
);
expect(html).toContain("data-testid=\"timeline-allocation-popover-unavailable\"");
expect(html).toContain("The selected booking could not be resolved from the current timeline data.");
});
});