import { render, screen } from "@testing-library/react";
import type { Testimonial } from "@/lib/proof";
import Testimonials from "./Testimonials";
/**
* Testes de caminhos-base de Testimonials e de initials() (complemento de Testimonials.test.tsx):
* foto presente, iniciais com 1, 2 e 3 palavras, espaços extras, e vários depoimentos.
*/
const base: Testimonial = {
quote: "Entregou no prazo combinado.",
name: "Maria Souza",
role: "Sócia",
company: "Empresa de Teste",
};
describe("Testimonials", () => {
it("path: with a photo -> shows the decorative image and no initials", () => {
const { container } = render(
,
);
const image = container.querySelector("img");
expect(image).not.toBeNull();
expect(image).toHaveAttribute("alt", "");
expect(image?.getAttribute("src")).toContain("maria");
expect(screen.queryByText("MS")).toBeNull();
});
it.each([
["Maria", "M"],
["Maria Souza", "MS"],
["maria da silva souza", "MD"],
[" Maria Souza ", "MS"],
])("path: name %j without a photo -> initials %j", (name, initials) => {
const { container } = render();
expect(container.querySelector("img")).toBeNull();
expect(
container.querySelector("span[aria-hidden='true']"),
).toHaveTextContent(new RegExp(`^${initials}$`));
});
it("path: several testimonials -> one card each, keyed by company and name", () => {
render(
,
);
expect(screen.getAllByRole("listitem")).toHaveLength(3);
expect(screen.getAllByText(/Entregou no prazo/)).toHaveLength(3);
expect(screen.getAllByText("Sócia, Outra Empresa")).toHaveLength(2);
});
it("path: a testimonial with a project -> the case link points to that project", () => {
render();
expect(screen.getByRole("link", { name: "Ver case" })).toHaveAttribute(
"href",
"/cases/sc-plus",
);
});
});