Centralize project loading and status-state handling across dashboard surfaces. - add a reusable DataBoundary component for loading, empty, error, and loaded states - extract shared project status config helpers for labels, colors, icons, and initializing detection - update project overview, cards, badges, and selector UI to use the shared helpers - add regression coverage for data-boundary behavior, project overview empty/loading transitions, and status config fallbacks Files changed: packages/dashboard/app/components/DataBoundary.tsx | 64 ++++++++++++++++++++++ packages/dashboard/app/components/ProjectCard.tsx | 48 ++-------------- .../app/components/ProjectHealthBadge.tsx | 45 +-------------- .../dashboard/app/components/ProjectOverview.tsx | 4 +- .../dashboard/app/components/ProjectSelector.tsx | 27 +-------- .../app/components/__tests__/DataBoundary.test.tsx | 62 +++++++++++++++++++++ .../components/__tests__/ProjectOverview.test.tsx | 25 +++++++++ .../__tests__/ProjectThemeTokens.test.tsx | 37 ++++--------- .../utils/__tests__/projectStatusConfig.test.ts | 53 ++++++++++++++++++ .../dashboard/app/utils/projectStatusConfig.ts | 50 +++++++++++++++++ packages/dashboard/vitest.config.ts | 2 + 11 files changed, 282 insertions(+), 135 deletions(-) Fusion-Task-Id: FN-5894 Fusion-Task-Lineage: 3626a4af-b62b-456d-82d7-cf47bbf55c21
63 lines
2.0 KiB
TypeScript
63 lines
2.0 KiB
TypeScript
import { describe, expect, it, vi } from "vitest";
|
|
import { render, screen } from "@testing-library/react";
|
|
import { DataBoundary } from "../DataBoundary";
|
|
|
|
vi.mock("lucide-react", () => ({
|
|
AlertCircle: () => <span data-testid="alert-icon">⚠</span>,
|
|
Bot: () => <span data-testid="bot-icon">🤖</span>,
|
|
Folder: () => <span data-testid="folder-icon">📁</span>,
|
|
Activity: () => <span data-testid="activity-icon">📊</span>,
|
|
CheckCircle: () => <span data-testid="check-icon">✓</span>,
|
|
}));
|
|
|
|
describe("DataBoundary", () => {
|
|
it("renders the loading fallback before the first fetch completes", () => {
|
|
render(
|
|
<DataBoundary
|
|
isEmpty={false}
|
|
hasFetched={false}
|
|
isLoading={false}
|
|
loadingFallback={<div data-testid="loading-fallback">Loading</div>}
|
|
>
|
|
<div>Loaded content</div>
|
|
</DataBoundary>
|
|
);
|
|
|
|
expect(screen.getByTestId("loading-fallback")).toBeDefined();
|
|
expect(screen.queryByText("Loaded content")).toBeNull();
|
|
});
|
|
|
|
it("renders an empty state after fetch completion instead of an infinite skeleton", () => {
|
|
render(
|
|
<DataBoundary isEmpty hasFetched isLoading={false}>
|
|
<div>Loaded content</div>
|
|
</DataBoundary>
|
|
);
|
|
|
|
expect(screen.getByText("No data available")).toBeDefined();
|
|
expect(screen.queryByText("Loaded content")).toBeNull();
|
|
});
|
|
|
|
it("renders an error state when error is set", () => {
|
|
render(
|
|
<DataBoundary isEmpty hasFetched={false} error={new Error("Boom")}>
|
|
<div>Loaded content</div>
|
|
</DataBoundary>
|
|
);
|
|
|
|
expect(screen.getByTestId("data-boundary-error")).toBeDefined();
|
|
expect(screen.getByText("Boom")).toBeDefined();
|
|
});
|
|
|
|
it("renders children when data is present", () => {
|
|
render(
|
|
<DataBoundary isEmpty={false} hasFetched>
|
|
<div>Loaded content</div>
|
|
</DataBoundary>
|
|
);
|
|
|
|
expect(screen.getByText("Loaded content")).toBeDefined();
|
|
expect(screen.queryByText("No data available")).toBeNull();
|
|
});
|
|
});
|