Files

76 lines
3.0 KiB
JavaScript

import { describe, expect, it, vi } from "vitest";
import { render, screen } from "@testing-library/react";
import Title from "@/components/doctor/detailDoctor/Title";
import ItemAppointment from "@/components/doctor/appointmentList/ItemAppointment";
vi.mock("@/components/doctor/detailDoctor/Share", () => ({ default: () => null }));
// همان شش تخصص دکتر محمدباقر جهانتاب.
const SPECIALTIES = [
{ id: "13", name: "جراحی عمومی", parent_id: null },
{ id: "14", name: "جراحی پلاستیک و زیبایی", parent_id: "13" },
{ id: "167", name: "جراحی لاپاراسکوپی", parent_id: "13" },
{ id: "168", name: "جراح تیروئید", parent_id: "13" },
{ id: "169", name: "جراح گوارش", parent_id: "13" },
{ id: "170", name: "جراحی سرطانها", parent_id: "13" },
];
const DOCTOR = { name: "محمدباقر جهانتاب", specialties: SPECIALTIES, experience: 5 };
describe("بدنهٔ پروفایل — فهرست کامل تخصص‌ها", () => {
it("هر شش تخصص را جدا نشان می‌دهد، نه یک رشتهٔ درهم", () => {
render(<Title doctor={DOCTOR} />);
for (const s of SPECIALTIES) {
expect(screen.getByText(s.name)).toBeInTheDocument();
}
});
it("بعد از «تخصص:» نام نمی‌چسبد", () => {
// باگ قبلی: خروجی «تخصص:جراحی عمومی» بود.
render(<Title doctor={DOCTOR} />);
expect(screen.getByText("تخصص:")).toBeInTheDocument();
expect(screen.queryByText(/تخصص:جراحی/)).not.toBeInTheDocument();
});
it("جداکنندهٔ آویزان در انتها ندارد", () => {
const { container } = render(<Title doctor={DOCTOR} />);
expect(container.textContent).not.toMatch(/\|\s*$/);
expect(container.textContent).not.toContain("|");
});
it("پزشک بدون تخصص فقط برچسب را نشان می‌دهد و کرش نمی‌کند", () => {
expect(() =>
render(<Title doctor={{ ...DOCTOR, specialties: [] }} />)
).not.toThrow();
});
});
describe("ستون نوبت‌دهی — تخصص اصلی و شمارنده", () => {
const turn = { ...DOCTOR, uuid: "u-1", specialties: SPECIALTIES };
it("فقط تخصص اصلی و شمارندهٔ بقیه را نشان می‌دهد", () => {
render(<ItemAppointment turn={turn} doctorSlug="u-1" />);
expect(screen.getByText(/جراحی عمومی/)).toBeInTheDocument();
expect(
screen.getByRole("button", { name: "نمایش 5 تخصص دیگر" })
).toBeInTheDocument();
expect(screen.queryByText("جراح گوارش")).not.toBeInTheDocument();
});
it("جداکنندهٔ آویزان ندارد", () => {
const { container } = render(<ItemAppointment turn={turn} doctorSlug="u-1" />);
expect(container.textContent).not.toContain("|");
});
it("پزشک بدون تخصص کرش نمی‌کند", () => {
expect(() =>
render(<ItemAppointment turn={{ ...turn, specialties: [] }} doctorSlug="u-1" />)
).not.toThrow();
});
});