- Updated DoctorPage component to accept bookingResources prop for appointment list. - Added serviceQuery function to serialize service item UUIDs for API requests. - Introduced new API endpoints for fetching booking resources and resource slots. - Enhanced tests for new resource-based booking functionality, including resource selection and service availability. - Created ResourceSelect component for selecting appointment types, including doctor and resource options. - Updated appointment submission logic to include resource_uuid in payload when applicable. - Ensured UI reflects changes in booking flow without disrupting existing doctor-centric experience.
86 lines
3.6 KiB
JavaScript
86 lines
3.6 KiB
JavaScript
import { describe, it, expect, vi, beforeEach } from 'vitest';
|
|
import { render, waitFor } from '@testing-library/react';
|
|
|
|
vi.mock('@/services/response', () => ({
|
|
request: {
|
|
getAppointmentSlots: vi.fn(() => Promise.resolve({ data: { sessions: [] } })),
|
|
getServiceSlots: vi.fn(() => Promise.resolve({ data: { start_times: [] } })),
|
|
getResourceSlots: vi.fn(() => Promise.resolve({ data: { start_times: [] } })),
|
|
getMonthAvailability: vi.fn(() => Promise.resolve({ data: {} })),
|
|
getResourceMonthAvailability: vi.fn(() => Promise.resolve({ data: {} })),
|
|
},
|
|
}));
|
|
|
|
vi.mock('next/navigation', () => ({ useParams: () => ({ doctorId: 'doc-1' }) }));
|
|
vi.mock('@/components/common/InlineJalaliMonth', () => ({ default: () => <div /> }));
|
|
vi.mock('./dateTime/hours', () => ({ default: () => <div /> }));
|
|
vi.mock('./dateTime/SendAppo', () => ({ default: () => <div /> }));
|
|
vi.mock('../Tabs', () => ({ default: () => <div /> }));
|
|
|
|
import { request } from '@/services/response';
|
|
import DateTime from './dateTime';
|
|
import DatePicker from './datePicker';
|
|
|
|
// نیمهشبِ فردا — تا «زمانِ گذشته» جریان را کوتاه نکند.
|
|
const TOMORROW = Math.floor(new Date(new Date().setHours(24, 0, 0, 0)).getTime() / 1000);
|
|
|
|
describe('DateTime — انتخاب اندپوینت اسلات', () => {
|
|
beforeEach(() => vi.clearAllMocks());
|
|
|
|
it('بدون منبع و بدون حالت سرویسی → اسلات پزشک', async () => {
|
|
render(<DateTime date={TOMORROW} doctor={{ uuid: 'doc-1' }} />);
|
|
|
|
await waitFor(() => expect(request.getAppointmentSlots).toHaveBeenCalled());
|
|
expect(request.getResourceSlots).not.toHaveBeenCalled();
|
|
});
|
|
|
|
it('حالت سرویسیِ پزشک → اسلات سرویسیِ پزشک', async () => {
|
|
render(
|
|
<DateTime date={TOMORROW} doctor={{ uuid: 'doc-1' }} serviceMode selectedServiceUuids={['s1']} />
|
|
);
|
|
|
|
await waitFor(() => expect(request.getServiceSlots).toHaveBeenCalled());
|
|
expect(request.getResourceSlots).not.toHaveBeenCalled();
|
|
});
|
|
|
|
it('با منبع → اسلات منبع، حتی وقتی برنامهٔ محل اسلاتی است', async () => {
|
|
render(
|
|
<DateTime
|
|
date={TOMORROW}
|
|
doctor={{ uuid: 'doc-1' }}
|
|
resourceUuid="r1"
|
|
selectedServiceUuids={['s1']}
|
|
/>
|
|
);
|
|
|
|
await waitFor(() => expect(request.getResourceSlots).toHaveBeenCalledWith('r1', expect.any(String), ['s1']));
|
|
expect(request.getAppointmentSlots).not.toHaveBeenCalled();
|
|
expect(request.getServiceSlots).not.toHaveBeenCalled();
|
|
});
|
|
});
|
|
|
|
describe('DatePicker — انتخاب اندپوینت تقویم ماه', () => {
|
|
beforeEach(() => vi.clearAllMocks());
|
|
|
|
it('بدون منبع → تقویم پزشک', async () => {
|
|
render(<DatePicker setDate={vi.fn()} />);
|
|
|
|
await waitFor(() => expect(request.getMonthAvailability).toHaveBeenCalled());
|
|
expect(request.getResourceMonthAvailability).not.toHaveBeenCalled();
|
|
});
|
|
|
|
it('با منبع → تقویم منبع، همراه سرویسهای انتخابشده', async () => {
|
|
render(<DatePicker setDate={vi.fn()} resourceUuid="r1" selectedServiceUuids={['s1']} />);
|
|
|
|
await waitFor(() =>
|
|
expect(request.getResourceMonthAvailability).toHaveBeenCalledWith(
|
|
'r1',
|
|
expect.any(Number),
|
|
expect.any(Number),
|
|
['s1']
|
|
)
|
|
);
|
|
expect(request.getMonthAvailability).not.toHaveBeenCalled();
|
|
});
|
|
});
|