import { describe, expect, it } from "vitest"; import { render, screen } from "@testing-library/react"; import specialtiesData from "@/data/specialties.json"; import SpecialtyDetailPage from "@/components/specialties/detail"; const byName = (name) => specialtiesData.find((s) => s.name === name); const GENERAL_SURGERY = byName("جراحی عمومی"); const GI = byName("جراح گوارش"); const renderPage = (specialty) => render( ); /** حلقه‌های breadcrumd به‌ترتیب. */ const crumbs = () => Array.from( screen.getByRole("navigation", { name: "breadcrumb" }).querySelectorAll("li") ).map((li) => li.textContent.replace(/>/g, "").trim()); describe("breadcrumb صفحهٔ تخصص", () => { it("صفحهٔ زیرتخصص حلقهٔ والد را دارد", () => { renderPage(GI); expect(crumbs()).toEqual(["خانه", "تخصص‌ها", GENERAL_SURGERY.name, GI.name]); }); it("حلقهٔ والد به صفحهٔ گروه لینک می‌دهد", () => { renderPage(GI); expect( screen.getByRole("link", { name: GENERAL_SURGERY.name }) ).toHaveAttribute("href", `/specialties/${GENERAL_SURGERY.slug}`); }); it("صفحهٔ ریشه حلقهٔ والد اضافه نمی‌گیرد", () => { renderPage(GENERAL_SURGERY); expect(crumbs()).toEqual(["خانه", "تخصص‌ها", GENERAL_SURGERY.name]); }); it("JSON-LD همان حلقه‌ها را دارد — نما و schema واگرا نمی‌شوند", () => { const { container } = renderPage(GI); const script = container.querySelector('script[type="application/ld+json"]'); const jsonLd = JSON.parse(script.innerHTML); expect(jsonLd["@type"]).toBe("BreadcrumbList"); expect(jsonLd.itemListElement.map((i) => i.name)).toEqual([ "خانه", "تخصص‌ها", GENERAL_SURGERY.name, GI.name, ]); }); });