e434c439c9
- Rename all component files to PascalCase matching exported names - Move components into feature directories (git/, session/, project/, terminal/, workspace/, ui/, layout/) - Rename all page files to PascalCase with Page suffix - Rename all API files to kebab-case - Update all imports across codebase with corrected relative depths - Preserve git history via git mv Quality gates: tsc (pass), eslint (pass), 66/74 tests pass (8 pre-existing failures) Refs: repo-restructure Task 4.4
50 lines
1.3 KiB
TypeScript
50 lines
1.3 KiB
TypeScript
import { render, screen } from "@testing-library/react";
|
|
import { MemoryRouter, Route, Routes } from "react-router-dom";
|
|
import { describe, expect, it, vi } from "vitest";
|
|
|
|
import { ProtectedRoute } from "./ProtectedRoute";
|
|
|
|
const mockUseAuth = vi.fn();
|
|
|
|
vi.mock("../state/auth", () => ({
|
|
useAuth: () => mockUseAuth()
|
|
}));
|
|
|
|
describe("ProtectedRoute", () => {
|
|
it("shows loading while session is resolving", () => {
|
|
mockUseAuth.mockReturnValue({ state: "loading" });
|
|
|
|
render(
|
|
<MemoryRouter initialEntries={["/"]}>
|
|
<ProtectedRoute>
|
|
<div>private content</div>
|
|
</ProtectedRoute>
|
|
</MemoryRouter>
|
|
);
|
|
|
|
expect(screen.getByText("Checking session...")).toBeInTheDocument();
|
|
});
|
|
|
|
it("redirects unauthenticated users to login", () => {
|
|
mockUseAuth.mockReturnValue({ state: "unauthenticated" });
|
|
|
|
render(
|
|
<MemoryRouter initialEntries={["/settings"]}>
|
|
<Routes>
|
|
<Route
|
|
path="/settings"
|
|
element={
|
|
<ProtectedRoute>
|
|
<div>private content</div>
|
|
</ProtectedRoute>
|
|
}
|
|
/>
|
|
<Route path="/login" element={<div>login page</div>} />
|
|
</Routes>
|
|
</MemoryRouter>
|
|
);
|
|
|
|
expect(screen.getByText("login page")).toBeInTheDocument();
|
|
});
|
|
});
|