The public doctor payload built `active`/`free_turn`/`hours_of_work` from the personal schedule alone, so a doctor bookable only at a clinic was reported as "نوبتدهی غیرفعال". Aggregate over every schedule instead: any schedule with online booking on and an active day makes the doctor bookable, and the disabled label only appears when all of them are off. Three admin-panel fixes for the same class of bug: - AppointmentsPage took the selected doctor from `dbUuid`, which is the clinic's uuid inside a clinic context — the slots request 404'd. Use `doctorUuid`. - TurnsTimeline rendered any error or unknown empty_reason as "این روز شیفت کاری ندارد". Errors now surface as errors and unknown reasons get a neutral message; the day-off wording is reserved for an explicit day_off from the backend. - Admins have no clinic context, so slots fell back to the personal schedule. They now pick a location from `appointment-booking-locations` and that choice drives the slot, service and create-appointment requests. Adds `app:schedule:normalize-format` for legacy rows stored as a bare JSON list covering only Saturday, which read as day-off for the rest of the week. Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
89 lines
4.7 KiB
TypeScript
89 lines
4.7 KiB
TypeScript
import { describe, it, expect, beforeEach, vi } from 'vitest';
|
||
import { screen } from '@testing-library/react';
|
||
import { renderWithProviders } from '../test/utils';
|
||
|
||
vi.mock('../lib/api', () => ({
|
||
api: { get: vi.fn(), post: vi.fn(), patch: vi.fn(), put: vi.fn(), delete: vi.fn() },
|
||
ApiError: class extends Error {},
|
||
}));
|
||
|
||
import { api } from '../lib/api';
|
||
import { useAuthStore } from '../stores/authStore';
|
||
import AppointmentsPage from './AppointmentsPage';
|
||
|
||
const get = api.get as ReturnType<typeof vi.fn>;
|
||
|
||
beforeEach(() => {
|
||
get.mockReset();
|
||
useAuthStore.setState({ primaryRole: 'doctor', dbUuid: 'doc1', doctorUuid: 'doc1' } as any);
|
||
get.mockImplementation((url: string) => {
|
||
if (url.includes('today-stats')) return Promise.resolve({ success: true, data: { total: 7, completed: 3, waiting: 2, cancelled: 1 } });
|
||
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: [] });
|
||
});
|
||
});
|
||
|
||
describe('AppointmentsPage — طرح نوبتها', () => {
|
||
it('renders the title, the stats bar and the افزودن نوبت action', async () => {
|
||
renderWithProviders(<AppointmentsPage />);
|
||
expect(screen.getByText('نوبت ها')).toBeInTheDocument();
|
||
expect(screen.getByText('کل نوبت های امروز')).toBeInTheDocument();
|
||
expect(await screen.findByText('۷')).toBeInTheDocument(); // total from stats
|
||
expect(screen.getByText('افزودن نوبت')).toBeInTheDocument();
|
||
});
|
||
|
||
it('timeline view shows the holiday message when the doctor has no slots', async () => {
|
||
renderWithProviders(<AppointmentsPage />);
|
||
// نمای پیشفرض زمانبندی است و پزشک (نقش doctor) از قبل انتخاب شده
|
||
expect(await screen.findByText('این روز تعطیل است')).toBeInTheDocument();
|
||
});
|
||
|
||
it('honors the ?date= query param (returns to the same day after edit)', async () => {
|
||
renderWithProviders(<AppointmentsPage />, { route: '/admin/appointments?date=2024-06-01' });
|
||
await screen.findByText('این روز تعطیل است');
|
||
const usedDate = get.mock.calls.some((c: any[]) => typeof c[0] === 'string' && c[0].includes('date=2024-06-01'));
|
||
expect(usedDate).toBe(true);
|
||
});
|
||
|
||
it('independent doctor profile does NOT show doctor tabs', async () => {
|
||
renderWithProviders(<AppointmentsPage />);
|
||
await screen.findByText('این روز تعطیل است');
|
||
expect(screen.queryByText('همه')).toBeNull();
|
||
// برچسب فیلتر سرویس دیده میشود (مطابق طرح)
|
||
expect(screen.getByText('سرویس مورد نظر را انتخاب کنید...')).toBeInTheDocument();
|
||
});
|
||
});
|
||
|
||
describe('AppointmentsPage — پروفایل کلینیک چندپزشکه', () => {
|
||
beforeEach(() => {
|
||
get.mockReset();
|
||
useAuthStore.setState({ primaryRole: 'clinic', dbUuid: 'clinic1' } as any);
|
||
get.mockImplementation((url: string) => {
|
||
if (url.includes('today-stats')) return Promise.resolve({ success: true, data: { total: 5, completed: 1, waiting: 3, cancelled: 1 } });
|
||
if (url.includes('/clinic/doctor-list/')) return Promise.resolve({ success: true, data: { data: [
|
||
{ uuid: 'd1', name: 'دکتر محمدی' }, { uuid: 'd2', name: 'دکتر رضایی' },
|
||
] } });
|
||
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: [] });
|
||
});
|
||
});
|
||
|
||
it('shows the doctor tabs (multi-doctor management) without the «همه» tab', async () => {
|
||
renderWithProviders(<AppointmentsPage />);
|
||
expect(await screen.findByText('دکتر محمدی')).toBeInTheDocument();
|
||
expect(screen.getByText('دکتر رضایی')).toBeInTheDocument();
|
||
expect(screen.queryByText('همه')).toBeNull();
|
||
});
|
||
|
||
it('auto-selects the first doctor so the timeline loads its slots', async () => {
|
||
renderWithProviders(<AppointmentsPage />);
|
||
await screen.findByText('دکتر محمدی');
|
||
// اسلاتها برای اولین دکتر (d1) درخواست میشوند
|
||
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);
|
||
});
|
||
});
|