feat(secretary): implement grouping of secretaries by doctor and sync profile data across links
This commit is contained in:
@@ -1,5 +1,5 @@
|
||||
import { describe, it, expect, beforeEach, vi } from "vitest";
|
||||
import { screen, fireEvent } from "@testing-library/react";
|
||||
import { screen, fireEvent, waitFor, within } from "@testing-library/react";
|
||||
import { renderWithProviders } from "../test/utils";
|
||||
|
||||
vi.mock("sonner", () => ({ toast: { success: vi.fn(), error: vi.fn(), warning: vi.fn() } }));
|
||||
@@ -18,9 +18,45 @@ import { api } from "../lib/api";
|
||||
import MySecretariesPage from "./MySecretariesPage";
|
||||
|
||||
const get = api.get as ReturnType<typeof vi.fn>;
|
||||
const patch = api.patch as ReturnType<typeof vi.fn>;
|
||||
const put = api.put as ReturnType<typeof vi.fn>;
|
||||
|
||||
/** یک منشیِ مشترک بین دو پزشک = دو ردیف لینک با secretary_uuid یکسان */
|
||||
const sharedSecretaryRows = [
|
||||
{
|
||||
uuid: "link-a",
|
||||
secretary_uuid: "sec-1",
|
||||
user_name: "ساسان عطایی",
|
||||
mobile_number: "09120671732",
|
||||
doctor_name: "دکتر الف",
|
||||
doctor_uuid: "doc-a",
|
||||
is_active: true,
|
||||
national_code: "1212121212",
|
||||
address: null,
|
||||
permissions: {},
|
||||
created_at: "1750000000",
|
||||
},
|
||||
{
|
||||
uuid: "link-b",
|
||||
secretary_uuid: "sec-1",
|
||||
user_name: "ساسان عطایی",
|
||||
mobile_number: "09120671732",
|
||||
doctor_name: "دکتر ب",
|
||||
doctor_uuid: "doc-b",
|
||||
is_active: true,
|
||||
national_code: "1212121212",
|
||||
address: null,
|
||||
permissions: {},
|
||||
created_at: "1750000000",
|
||||
},
|
||||
];
|
||||
|
||||
beforeEach(() => {
|
||||
get.mockReset();
|
||||
patch.mockReset();
|
||||
put.mockReset();
|
||||
patch.mockResolvedValue({ success: true, data: {} });
|
||||
put.mockResolvedValue({ success: true, data: {} });
|
||||
get.mockImplementation((url: string) => {
|
||||
if (url.includes("/clinic/doctor-list/"))
|
||||
return Promise.resolve({ success: true, data: { data: [
|
||||
@@ -56,3 +92,61 @@ describe("MySecretariesPage — clinic multi-doctor", () => {
|
||||
expect(screen.getByText("لغو همه")).toBeInTheDocument();
|
||||
});
|
||||
});
|
||||
|
||||
describe("MySecretariesPage — one row per secretary", () => {
|
||||
beforeEach(() => {
|
||||
get.mockImplementation((url: string) => {
|
||||
if (url.includes("/clinic/doctor-list/"))
|
||||
return Promise.resolve({ success: true, data: { data: [
|
||||
{ uuid: "doc-a", name: "دکتر الف" },
|
||||
{ uuid: "doc-b", name: "دکتر ب" },
|
||||
] } });
|
||||
if (url.includes("/secretaries/clinic/"))
|
||||
return Promise.resolve({ success: true, data: sharedSecretaryRows });
|
||||
return Promise.resolve({ success: true, data: [] });
|
||||
});
|
||||
});
|
||||
|
||||
it("renders a secretary shared by two doctors as a single row", async () => {
|
||||
renderWithProviders(<MySecretariesPage />, { route: "/admin/my-secretaries" });
|
||||
|
||||
const table = within(await screen.findByRole("table"));
|
||||
expect(table.getAllByText("ساسان عطایی")).toHaveLength(1);
|
||||
expect(table.getByText("دکتر الف، دکتر ب")).toBeInTheDocument();
|
||||
});
|
||||
|
||||
it("cancelling collaboration deactivates every link row", async () => {
|
||||
renderWithProviders(<MySecretariesPage />, { route: "/admin/my-secretaries" });
|
||||
const table = within(await screen.findByRole("table"));
|
||||
// اولین «لغو همکاری» عنوان ستون است؛ دکمهی ردیف مورد نظر است
|
||||
fireEvent.click(table.getByRole("button", { name: "لغو همکاری" }));
|
||||
|
||||
// متن تأیید باید تعداد پزشکان را نشان دهد
|
||||
expect(await screen.findByText(/برای همهی .* پزشک/)).toBeInTheDocument();
|
||||
fireEvent.click(screen.getAllByText("لغو همکاری").pop()!);
|
||||
|
||||
await waitFor(() => expect(patch).toHaveBeenCalledTimes(2));
|
||||
expect(patch).toHaveBeenCalledWith("/api/v1/secretary/link-a", { active: false });
|
||||
expect(patch).toHaveBeenCalledWith("/api/v1/secretary/link-b", { active: false });
|
||||
});
|
||||
|
||||
it("editing patches every link row and syncs the doctor set", async () => {
|
||||
renderWithProviders(<MySecretariesPage />, { route: "/admin/my-secretaries" });
|
||||
fireEvent.click((await screen.findAllByTitle("ویرایش"))[0]);
|
||||
|
||||
// مجموعهی پزشکانِ فعلی باید از قبل انتخاب شده باشد
|
||||
expect(await screen.findByText("پزشکانِ این منشی")).toBeInTheDocument();
|
||||
expect(screen.getByText(/[۲2] انتخابشده/)).toBeInTheDocument();
|
||||
|
||||
// حذف یکی از پزشکان (آخرین مورد = ردیف لیست، نه چیپ انتخابشده)
|
||||
fireEvent.click(screen.getAllByText("دکتر ب").pop()!);
|
||||
fireEvent.click(screen.getByText("ذخیره"));
|
||||
|
||||
await waitFor(() => expect(put).toHaveBeenCalledTimes(1));
|
||||
expect(patch).toHaveBeenCalledTimes(2);
|
||||
expect(put).toHaveBeenCalledWith("/api/v1/secretaries/clinic/clinic-1/doctors", {
|
||||
secretary_uuid: "sec-1",
|
||||
doctor_uuids: ["doc-a"],
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user