feat: Refactor specialty display logic and enhance specialty filtering
- Introduced SpecialtyChips component to manage the display of doctor's specialties with a primary specialty and a count of additional specialties. - Updated ItemDoctor component to utilize SpecialtyChips for better UI presentation. - Enhanced PosterLight and Poster components to display primary specialties and a text line for sub-specialties. - Implemented nextSpecialtyFilter function to improve specialty selection logic in the Content component. - Updated search functionality to allow searching by both doctor name and specialty. - Added new specialties to specialties.json for better coverage. - Created sync-specialties script to synchronize specialties data with the backend during build. - Added tests for new components and helper functions to ensure functionality and reliability.
This commit is contained in:
@@ -0,0 +1,84 @@
|
||||
import { describe, expect, it, vi } from "vitest";
|
||||
import { render, screen } from "@testing-library/react";
|
||||
import Poster from "@/components/doctor/poster";
|
||||
import PosterLight from "@/components/doctor/poster/PosterLight";
|
||||
|
||||
vi.mock("@/lib/getStateInfoClient", () => ({
|
||||
getStateInfoClient: () => ({ matchedCity: { site_name: "یاسوج نوبت", domain: "yasuj-nobat.ir" } }),
|
||||
}));
|
||||
|
||||
vi.mock("./QrImg", () => ({ default: () => <div data-testid="qr" /> }));
|
||||
vi.mock("@/components/doctor/poster/QrImg", () => ({ default: () => <div data-testid="qr" /> }));
|
||||
|
||||
// همان شش تخصص دکتر محمدباقر جهانتاب، با همان شکلی که API برمیگرداند.
|
||||
const JAHANTAB = {
|
||||
name: "محمدباقر جهانتاب",
|
||||
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" },
|
||||
],
|
||||
expertise: [],
|
||||
address: [],
|
||||
};
|
||||
|
||||
describe.each([
|
||||
["پوستر تیره", Poster],
|
||||
["پوستر روشن", PosterLight],
|
||||
])("%s", (_label, Component) => {
|
||||
it("تخصص والد را بهعنوان تیتر نشان میدهد", () => {
|
||||
render(<Component data={JAHANTAB} />);
|
||||
|
||||
expect(screen.getByText("جراحی عمومی")).toBeInTheDocument();
|
||||
});
|
||||
|
||||
it("زیرتخصصها یک خط متنیاند، نه چیپ جداگانه", () => {
|
||||
render(<Component data={JAHANTAB} />);
|
||||
|
||||
// اگر چیپ بودند، هر نام یک گرهٔ متنی مستقل داشت.
|
||||
expect(screen.queryByText("جراح گوارش")).not.toBeInTheDocument();
|
||||
expect(screen.getByText(/جراح گوارش/)).toBeInTheDocument();
|
||||
});
|
||||
|
||||
it("مازاد را میشمارد و نمیبرد", () => {
|
||||
render(<Component data={JAHANTAB} />);
|
||||
|
||||
expect(screen.getByText(/تخصص دیگر/)).toBeInTheDocument();
|
||||
});
|
||||
|
||||
it("کادر ثابت ۱۰۸۰×۱۳۵۰ و overflow-hidden دستنخورده است", () => {
|
||||
const { container } = render(<Component data={JAHANTAB} />);
|
||||
const frame = container.firstChild;
|
||||
|
||||
expect(frame.className).toContain("w-[1080px]");
|
||||
expect(frame.className).toContain("h-[1350px]");
|
||||
expect(frame.className).toContain("overflow-hidden");
|
||||
});
|
||||
|
||||
it("خط زیرتخصص از بودجهٔ کاراکتر نمیگذرد", () => {
|
||||
// jsdom چیدمان را اندازه نمیگیرد، پس سرریزِ پیکسلی اینجا اثباتشدنی نیست.
|
||||
// چیزی که اثبات میشود همان سازوکاری است که سرریز را میبندد: طول متن کراندار.
|
||||
render(<Component data={JAHANTAB} />);
|
||||
|
||||
const line = screen.getByText(/جراح گوارش/);
|
||||
expect(line.textContent.length).toBeLessThan(120);
|
||||
});
|
||||
|
||||
it("پزشک تکتخصص خط زیرتخصص ندارد", () => {
|
||||
render(
|
||||
<Component
|
||||
data={{ ...JAHANTAB, specialties: [{ id: "13", name: "جراحی عمومی", parent_id: null }] }}
|
||||
/>
|
||||
);
|
||||
|
||||
expect(screen.getByText("جراحی عمومی")).toBeInTheDocument();
|
||||
expect(screen.queryByText(/تخصص دیگر/)).not.toBeInTheDocument();
|
||||
});
|
||||
|
||||
it("پزشک بدون تخصص کرش نمیکند", () => {
|
||||
expect(() => render(<Component data={{ ...JAHANTAB, specialties: [] }} />)).not.toThrow();
|
||||
});
|
||||
});
|
||||
Reference in New Issue
Block a user