Spaces:
Sleeping
Sleeping
File size: 4,814 Bytes
1955a0f | 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 | import { describe, it, expect, vi, beforeEach } from "vitest";
import { render, screen, waitFor } from "@testing-library/react";
import userEvent from "@testing-library/user-event";
import { MemoryRouter, Routes, Route } from "react-router-dom";
import { QueryClient, QueryClientProvider } from "@tanstack/react-query";
import ModuleHub from "./ModuleHub";
import ModuleShell from "./ModuleShell";
import { LaunchProvider } from "./LaunchContext";
import { ThemeProvider } from "../context/ThemeContext";
import { ApiKeyProvider } from "../context/ApiKeyContext";
import { EDashboard, SCampaigns } from "./lazyPages";
import { apiClient } from "../lib/apiClient";
vi.mock("recharts", () => ({
ResponsiveContainer: ({ children }: any) => <div>{children}</div>,
AreaChart: () => <div>AreaChart</div>,
Area: () => <div />,
XAxis: () => <div />,
YAxis: () => <div />,
Tooltip: () => <div />,
LineChart: () => <div>LineChart</div>,
BarChart: () => <div>BarChart</div>,
Line: () => <div />,
Bar: () => <div />,
CartesianGrid: () => <div />,
Legend: () => <div />,
PieChart: () => <div>PieChart</div>,
Pie: () => <div />,
Cell: () => <div />,
}));
vi.mock("../lib/apiClient", () => ({
apiClient: { get: vi.fn().mockResolvedValue({ data: [] }) },
}));
vi.mock("../lib/supabaseClient", () => ({
supabase: null,
isSupabaseConfigured: false,
}));
function makeWrapper(initialEntries: string[]) {
const queryClient = new QueryClient({
defaultOptions: { queries: { retry: false, gcTime: 0 } },
});
return (
<QueryClientProvider client={queryClient}>
<ThemeProvider>
<ApiKeyProvider>
<MemoryRouter initialEntries={initialEntries}>
<LaunchProvider>
<Routes>
<Route path="/" element={<ModuleHub />} />
<Route path="/modules/e" element={<ModuleShell module="e" />}>
<Route index element={<EDashboard />} />
</Route>
<Route path="/modules/s" element={<ModuleShell module="s" />}>
<Route path="campaigns" element={<SCampaigns />} />
</Route>
</Routes>
</LaunchProvider>
</MemoryRouter>
</ApiKeyProvider>
</ThemeProvider>
</QueryClientProvider>
);
}
describe("BRIDGE platform routing", () => {
beforeEach(() => {
vi.clearAllMocks();
(apiClient.get as any).mockResolvedValue({ data: [] });
});
it("hub renders both module launcher cards with direct-launch buttons", () => {
render(makeWrapper(["/"]));
expect(screen.getAllByText(/BRIDGE/).length).toBeGreaterThan(0);
expect(screen.getByRole("button", { name: /Launch Module E/i })).toBeTruthy();
expect(screen.getByRole("button", { name: /Launch Module S/i })).toBeTruthy();
expect(screen.getByText(/Direct URLs/i)).toBeTruthy();
});
it("direct URL load of /modules/e mounts the E shell with its launch guard", async () => {
render(makeWrapper(["/modules/e"]));
expect(screen.getByTestId("module-shell-e")).toBeTruthy();
expect(screen.getByTestId("module-launch-animation")).toBeTruthy();
// Real dashboard primitives assemble — StatCards carry real titles
await waitFor(() => {
expect(screen.getAllByText(/Total Leads/i).length).toBeGreaterThan(0);
});
});
it("direct URL load of /modules/s mounts the S shell with the S campaign page", async () => {
render(makeWrapper(["/modules/s/campaigns"]));
expect(screen.getByTestId("module-shell-s")).toBeTruthy();
expect(screen.getByTestId("module-launch-animation")).toBeTruthy();
await waitFor(() => {
expect(document.querySelector('[data-module="s"]')).toBeTruthy();
});
});
it("launch animation reveals the workspace when completed", async () => {
vi.useFakeTimers({ shouldAdvanceTime: true });
try {
render(makeWrapper(["/modules/e"]));
expect(screen.getByTestId("module-launch-animation")).toBeTruthy();
// Watchdog completes the assembly (slow-motion budget ≈ 3.3s)
await vi.advanceTimersByTimeAsync(4000);
await waitFor(() => {
expect(screen.queryByTestId("module-launch-animation")).toBeNull();
});
} finally {
vi.useRealTimers();
}
});
it("launching Module S from the hub routes to /modules/s", async () => {
const user = userEvent.setup({ advanceTimers: vi.advanceTimersByTime });
vi.useFakeTimers({ shouldAdvanceTime: true });
try {
render(makeWrapper(["/"]));
await user.click(screen.getByRole("button", { name: /Launch Module S/i }));
await vi.advanceTimersByTimeAsync(4000);
await waitFor(() => {
expect(screen.getByTestId("module-shell-s")).toBeTruthy();
});
} finally {
vi.useRealTimers();
}
});
});
|