feat: Implement resource booking functionality
- Add service timeline builder for appointments to manage available slots. - Create a hook to fetch resource booking services with effective durations. - Develop ResourceBookingSlotController to handle API requests for resource booking slots. - Implement ResourceBookingSlotService to calculate available time slots based on resource occupancy and service durations. - Add tests for resource appointment creation and booking slot functionality to ensure correct behavior and edge cases.
This commit is contained in:
@@ -0,0 +1,83 @@
|
||||
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 ResourceDayPanel from './ResourceDayPanel';
|
||||
import type { Appointment, ClinicResource } from '../../types';
|
||||
|
||||
const get = api.get as ReturnType<typeof vi.fn>;
|
||||
|
||||
const DAY = Math.floor(Date.now() / 1000) + 7 * 86400;
|
||||
|
||||
const resource = {
|
||||
uuid: 'r-2', name: 'لیزر CO2',
|
||||
supervisor: { uuid: 'd1', name: 'مینا یوسفی' },
|
||||
} as unknown as ClinicResource;
|
||||
|
||||
const appointment = {
|
||||
uuid: 'a-1', patient_name: 'رضا رحیمی', patient_mobile: '09120001307',
|
||||
doctor_uuid: 'd1', doctor_name: 'مینا یوسفی',
|
||||
slot_start: DAY + 3600, slot_end: DAY + 3600 + 3000,
|
||||
appointment_date: '', appointment_time: '10:35', end_time: '11:25',
|
||||
status: 'pending', version: 1, created_at: '',
|
||||
service_item: { uuid: 's-2', name: 'RF فرکشنال' },
|
||||
} as unknown as Appointment;
|
||||
|
||||
function render(appointments: Appointment[] = []) {
|
||||
return renderWithProviders(
|
||||
<ResourceDayPanel
|
||||
resource={resource}
|
||||
date="2026-08-04"
|
||||
appointments={appointments}
|
||||
loading={false}
|
||||
canCreate
|
||||
queryKey={['appointments']}
|
||||
onBook={() => {}}
|
||||
onView={() => {}}
|
||||
/>,
|
||||
);
|
||||
}
|
||||
|
||||
beforeEach(() => get.mockReset());
|
||||
|
||||
describe('ResourceDayPanel', () => {
|
||||
it('بازهٔ کاری منبع و ردیفهای خالیِ قابل رزرو را نشان میدهد', async () => {
|
||||
get.mockResolvedValue({ success: true, data: {
|
||||
windows: [{ start: DAY, end: DAY + 6 * 3600, start_time: '08:00', end_time: '14:00' }],
|
||||
empty_reason: null,
|
||||
} });
|
||||
|
||||
render();
|
||||
|
||||
expect(await screen.findByText(/ساعت کاری: 08:00 - 14:00/)).toBeInTheDocument();
|
||||
expect(screen.getByText(/نوبتها بر اساس مدت سرویس چیده میشوند/)).toBeInTheDocument();
|
||||
expect(await screen.findByText('افزودن نوبت سریع')).toBeInTheDocument();
|
||||
});
|
||||
|
||||
it('نوبتِ رزروشده کارت خودش را میگیرد و خالیها دو طرفش میمانند', async () => {
|
||||
get.mockResolvedValue({ success: true, data: {
|
||||
windows: [{ start: DAY, end: DAY + 6 * 3600, start_time: '08:00', end_time: '14:00' }],
|
||||
empty_reason: null,
|
||||
} });
|
||||
|
||||
render([appointment]);
|
||||
|
||||
expect(await screen.findByText('رضا رحیمی')).toBeInTheDocument();
|
||||
expect(screen.getByText('سرویس: RF فرکشنال')).toBeInTheDocument();
|
||||
expect(screen.getAllByText('افزودن نوبت سریع')).toHaveLength(2);
|
||||
});
|
||||
|
||||
it('روزِ بدون شیفت، دلیلش را میگوید نه فهرست خالی', async () => {
|
||||
get.mockResolvedValue({ success: true, data: { windows: [], empty_reason: 'no_shift' } });
|
||||
|
||||
render();
|
||||
|
||||
expect(await screen.findByText('این روز شیفت کاری ندارد')).toBeInTheDocument();
|
||||
});
|
||||
});
|
||||
Reference in New Issue
Block a user