spb/phi-conseil
Public
1import { describe, expect, it } from "vitest";2import { render, screen } from "@testing-library/react";3import { Button } from "@/components/ui/Button";4import { TestimonialSlider } from "@/components/sections/TestimonialSlider";5import { buildSpiral } from "@/lib/spiral";67describe("Button", () => {8 it("rend un lien quand href est fourni", () => {9 render(<Button href="/services">Voir</Button>);10 expect(screen.getByRole("link", { name: /voir/i })).toHaveAttribute("href", "/services");11 });12 it("rend un bouton sinon", () => {13 render(<Button arrow={false}>OK</Button>);14 expect(screen.getByRole("button", { name: "OK" })).toHaveAttribute("type", "button");15 });16});1718describe("TestimonialSlider", () => {19 const items = [20 { quote: "Un", author: "A", role: "r1" },21 { quote: "Deux", author: "B", role: "r2" },22 ];23 it("affiche le premier témoignage et la pagination accessible", () => {24 render(<TestimonialSlider items={items} />);25 expect(screen.getByText("Un")).toBeInTheDocument();26 expect(screen.getByRole("button", { name: "Témoignage 2 sur 2" })).toBeInTheDocument();27 expect(screen.getByRole("button", { name: /pause/i })).toBeInTheDocument();28 });29 it("n'affiche pas de pagination avec un seul avis", () => {30 render(<TestimonialSlider items={[items[0]]} />);31 expect(screen.queryByRole("group")).toBeNull();32 });33});3435describe("spirale de Fibonacci", () => {36 it("produit des carrés de côtés de Fibonacci et un rectangle 34×21 à 8 niveaux", () => {37 const { squares, bbox, path } = buildSpiral(8);38 expect(squares.map((s) => s.s)).toEqual([1, 1, 2, 3, 5, 8, 13, 21]);39 expect([bbox.w, bbox.h].sort((a, b) => a - b)).toEqual([21, 34]);40 expect(path.startsWith("M ")).toBe(true);41 expect((path.match(/A /g) ?? []).length).toBe(8);42 });43});44