import { screen } from "@testing-library/react"; import { describe, expect, it, vi } from "vitest"; import { renderWithProviders } from "../../test/utils"; vi.mock("../../hooks/useSubscription", () => ({ useSubscription: () => ({ hasFeature: () => true }), })); import { useAuthStore } from "../../stores/authStore"; import Sidebar from "./Sidebar"; /** * پرسنل فقط داشبورد و سرویس‌های خودش را دارد؛ هیچ آیتم مدیریتی نباید در منویش * ظاهر شود — قرینهٔ enforcement سمت API (StaffRouteGuardSubscriber). */ describe("Sidebar — نقش پرسنل", () => { const asStaff = () => useAuthStore.setState({ primaryRole: "staff", dbUuid: "d1", userName: "زهرا احمدی", availableContexts: [], context: { type: "doctor", db_uuid: "d1", name: "مطب تست", role: "staff", scope: "doctor", permissions: { version: 1, resources: { services: { view: true }, appointments: { view: true } } }, }, } as any); it("shows only داشبورد and سرویس‌های من", () => { asStaff(); renderWithProviders(, { route: "/admin/dashboard" }); expect(screen.getByText("داشبورد").closest("a")).toHaveAttribute("href", "/admin/dashboard"); expect(screen.getByText("سرویس‌های من").closest("a")).toHaveAttribute("href", "/admin/my-services"); expect(screen.getByText("پرسنل")).toBeInTheDocument(); // برچسب نقش در فوتر }); it("hides management entries", () => { asStaff(); renderWithProviders(, { route: "/admin/dashboard" }); for (const label of ["پرونده بیماران", "تنظیمات", "نوبت‌ها", "پرداخت‌ها"]) { expect(screen.queryByText(label)).not.toBeInTheDocument(); } }); });