feat: add unit tests (Rust parser+DB, Vitest frontend) and test workflow

This commit is contained in:
2026-04-25 15:11:25 +02:00
parent b42674b22c
commit 8fd71de1aa
15 changed files with 689 additions and 5 deletions

View File

@ -0,0 +1,54 @@
import { describe, it, expect, vi, beforeEach } from "vitest";
import { render, screen } from "@testing-library/react";
import userEvent from "@testing-library/user-event";
import HomeView from "../components/HomeView";
// État minimal du store pour que HomeView ne plante pas
const baseStoreState = {
guides: [],
profiles: [],
activeProfileId: null,
syncing: false,
openGuide: vi.fn(),
};
vi.mock("../store", () => ({
useStore: vi.fn((selector?: (s: unknown) => unknown) => {
return typeof selector === "function"
? selector(baseStoreState)
: baseStoreState;
}),
}));
describe("HomeView", () => {
beforeEach(() => {
vi.clearAllMocks();
});
it('ne montre pas la bannière "Première utilisation" sans needsSync', () => {
render(<HomeView />);
expect(screen.queryByText("Première utilisation")).not.toBeInTheDocument();
});
it('affiche la bannière "Première utilisation" quand needsSync est true', () => {
render(<HomeView needsSync={true} />);
expect(screen.getByText("Première utilisation")).toBeInTheDocument();
});
it('affiche le bouton "Synchroniser les guides" quand needsSync est true', () => {
render(<HomeView needsSync={true} onSync={vi.fn()} />);
expect(
screen.getByRole("button", { name: /Synchroniser les guides/i })
).toBeInTheDocument();
});
it("appelle onSync au clic sur le bouton de synchronisation", async () => {
const user = userEvent.setup();
const onSync = vi.fn();
render(<HomeView needsSync={true} onSync={onSync} />);
await user.click(screen.getByRole("button", { name: /Synchroniser les guides/i }));
expect(onSync).toHaveBeenCalledOnce();
});
});