feat(secretary): enhance functionality for secretary role in appointments management

This commit is contained in:
hamed
2026-07-25 18:45:09 +03:30
parent 8d2b0d908a
commit 3cc4a59459
2 changed files with 69 additions and 12 deletions
@@ -86,3 +86,57 @@ describe('AppointmentsPage — پروفایل کلینیک چندپزشکه', ()
expect(calledSlotsForD1).toBe(true);
});
});
describe('AppointmentsPage — منشی', () => {
/**
* منشی در هر دو ساختار باید تایم‌لاین ببیند. لیست پزشکانِ مجاز از اندپوینت
* احرازشدهٔ /my/clinic-doctors می‌آید (نه لیست عمومی کلینیک).
*/
function mockSecretary(doctors: { uuid: string; name: string }[], scope: string | null) {
useAuthStore.setState({
primaryRole: 'secretary',
dbUuid: scope === 'clinic' ? 'clinic1' : 'doc1',
context: scope ? { type: scope, scope } : null,
} as any);
get.mockImplementation((url?: string) => {
if (typeof url !== 'string') return Promise.resolve({ success: true, data: [] });
if (url.includes('today-stats')) return Promise.resolve({ success: true, data: { total: 11, completed: 2, waiting: 7, cancelled: 2 } });
if (url.includes('/my/clinic-doctors')) return Promise.resolve({ success: true, data: { data: doctors } });
if (url.includes('appointment-slots')) return Promise.resolve({ success: true, data: { sessions: [], empty_reason: 'holiday' } });
if (url.includes('/my/appointments')) return Promise.resolve({ success: true, data: [], meta: { totalRecords: 0, totalPages: 0, currentPage: 1 } });
return Promise.resolve({ success: true, data: [] });
});
}
beforeEach(() => get.mockReset());
it('منشیِ پزشک مستقل: همان پزشک خودکار انتخاب و تایم‌لاین بارگذاری می‌شود', async () => {
mockSecretary([{ uuid: 'doc1', name: 'دکتر موسوی' }], null);
renderWithProviders(<AppointmentsPage />);
expect(await screen.findByText('این روز تعطیل است')).toBeInTheDocument();
expect(screen.queryByText('برای نمایش زمانبندی، ابتدا یک پزشک انتخاب کنید')).toBeNull();
const calledSlots = get.mock.calls.some((c: any[]) => typeof c[0] === 'string' && c[0].includes('appointment-slots') && c[0].includes('doctor_uuid=doc1'));
expect(calledSlots).toBe(true);
});
it('منشیِ کلینیک: تب پزشکانِ تخصیص‌یافته و انتخاب خودکار اولی', async () => {
mockSecretary([{ uuid: 'd1', name: 'دکتر محمدی' }, { uuid: 'd2', name: 'دکتر رضایی' }], 'clinic');
renderWithProviders(<AppointmentsPage />);
expect(await screen.findByText('دکتر محمدی')).toBeInTheDocument();
expect(screen.getByText('دکتر رضایی')).toBeInTheDocument();
await screen.findByText('این روز تعطیل است');
const calledSlotsForD1 = get.mock.calls.some((c: any[]) => typeof c[0] === 'string' && c[0].includes('appointment-slots') && c[0].includes('doctor_uuid=d1'));
expect(calledSlotsForD1).toBe(true);
});
it('منشی هرگز از لیست عمومی کلینیک نمی‌خواند', async () => {
mockSecretary([{ uuid: 'doc1', name: 'دکتر موسوی' }], null);
renderWithProviders(<AppointmentsPage />);
await screen.findByText('این روز تعطیل است');
const usedPublicList = get.mock.calls.some((c: any[]) => typeof c[0] === 'string' && c[0].includes('/clinic/doctor-list/'));
expect(usedPublicList).toBe(false);
});
});