6f35eb77ae
- Add HomePage with open sessions grid, projects overview, and session composer - Add SettingsPage with tabs for General, SSH Keys, Tool Types, Tool Configs - Update navigation to Home, Projects, Settings - Redirect legacy routes (/sessions, /ssh-keys, /tool-types, /tool-configs) - Apply Inter font and warm editorial styling - Update tests for new dashboard and projects pages Quality gates: typecheck pass, lint pass, 15/15 tests pass Refs: openspec/changes/ui-redesign-home-settings
82 lines
2.3 KiB
TypeScript
82 lines
2.3 KiB
TypeScript
import { fireEvent, render, screen, waitFor } from "@testing-library/react";
|
|
import { MemoryRouter } from "react-router-dom";
|
|
import { beforeEach, describe, expect, it, vi } from "vitest";
|
|
|
|
import { HomePage } from "./dashboard";
|
|
|
|
const mockDashboard = vi.fn();
|
|
const mockSessions = vi.fn();
|
|
const mockProjects = vi.fn();
|
|
const mockRepos = vi.fn();
|
|
|
|
vi.mock("../api/dashboard", () => ({
|
|
getDashboardSummary: (...args: unknown[]) => mockDashboard(...args)
|
|
}));
|
|
|
|
vi.mock("../api/sessions", () => ({
|
|
getUserSessions: (...args: unknown[]) => mockSessions(...args),
|
|
createInstance: vi.fn(),
|
|
startInstance: vi.fn(),
|
|
stopInstance: vi.fn(),
|
|
deleteInstance: vi.fn(),
|
|
recreateInstanceTunnel: vi.fn()
|
|
}));
|
|
|
|
vi.mock("../api/projects", () => ({
|
|
listProjects: (...args: unknown[]) => mockProjects(...args)
|
|
}));
|
|
|
|
vi.mock("../api/git_repositories", () => ({
|
|
listRepositories: (...args: unknown[]) => mockRepos(...args)
|
|
}));
|
|
|
|
vi.mock("../api/tool_types", () => ({
|
|
listToolTypes: vi.fn().mockResolvedValue([])
|
|
}));
|
|
|
|
describe("HomePage", () => {
|
|
beforeEach(() => {
|
|
mockDashboard.mockReset();
|
|
mockSessions.mockReset();
|
|
mockProjects.mockReset();
|
|
mockRepos.mockReset();
|
|
});
|
|
|
|
it("shows overview sections", async () => {
|
|
mockDashboard.mockResolvedValue({ projects: 1, repositories: 2, sshKeys: 3, recentActivity: [] });
|
|
mockSessions.mockResolvedValue([]);
|
|
mockProjects.mockResolvedValue([]);
|
|
mockRepos.mockResolvedValue([]);
|
|
|
|
render(
|
|
<MemoryRouter>
|
|
<HomePage />
|
|
</MemoryRouter>
|
|
);
|
|
|
|
expect(screen.getByText("Loading overview...")).toBeInTheDocument();
|
|
await waitFor(() => {
|
|
expect(screen.getAllByText("Open sessions").length).toBeGreaterThan(0);
|
|
expect(screen.getByText("Available projects")).toBeInTheDocument();
|
|
});
|
|
});
|
|
|
|
it("shows retry action when home load fails", async () => {
|
|
mockDashboard.mockRejectedValueOnce(new Error("failed"));
|
|
mockSessions.mockRejectedValueOnce(new Error("failed"));
|
|
mockProjects.mockRejectedValueOnce(new Error("failed"));
|
|
|
|
render(
|
|
<MemoryRouter>
|
|
<HomePage />
|
|
</MemoryRouter>
|
|
);
|
|
|
|
await waitFor(() => {
|
|
expect(screen.getByText("Unable to load your workspace overview.")).toBeInTheDocument();
|
|
});
|
|
|
|
fireEvent.click(screen.getAllByRole("button", { name: "Retry" })[0]);
|
|
});
|
|
});
|