fix(web): keep segmented timeline allocations actionable
This commit is contained in:
@@ -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.");
|
||||
});
|
||||
});
|
||||
Reference in New Issue
Block a user