AppointmentDetailPage now derives the appointment's local day from slot_start and points both the «بازگشت» button and the «نوبتها» breadcrumb to /admin/appointments?date=<that day>, so viewing/acting on an appointment from any day returns to that day instead of today. Test: the «نوبتها» breadcrumb links back to the appointment's date. Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
44 lines
1.6 KiB
TypeScript
44 lines
1.6 KiB
TypeScript
import { describe, it, expect, beforeEach, vi } from 'vitest';
|
|
import { screen, waitFor } from '@testing-library/react';
|
|
import { Routes, Route } from 'react-router-dom';
|
|
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 AppointmentDetailPage from './AppointmentDetailPage';
|
|
|
|
const get = api.get as ReturnType<typeof vi.fn>;
|
|
// 2024-06-01 12:00 محلی
|
|
const slotStart = Math.floor(new Date('2024-06-01T12:00:00').getTime() / 1000);
|
|
|
|
beforeEach(() => {
|
|
get.mockReset();
|
|
get.mockResolvedValue({
|
|
success: true,
|
|
data: {
|
|
uuid: 'ap1', patient_name: 'ساغر', patient_mobile: '09120000000',
|
|
slot_start: slotStart, slot_end: slotStart + 1800, status: 'confirmed', version: 1, created_at: slotStart,
|
|
},
|
|
});
|
|
});
|
|
|
|
describe('AppointmentDetailPage — بازگشت به همان روز', () => {
|
|
it('the «نوبتها» breadcrumb points back to the appointment day', async () => {
|
|
renderWithProviders(
|
|
<Routes>
|
|
<Route path="/admin/appointments/:uuid" element={<AppointmentDetailPage />} />
|
|
</Routes>,
|
|
{ route: '/admin/appointments/ap1' },
|
|
);
|
|
// پس از بارگذاری نوبت، لینک «نوبتها» باید به روزِ نوبت اشاره کند
|
|
await waitFor(() => {
|
|
const link = screen.getByText('نوبتها').closest('a');
|
|
expect(link?.getAttribute('href')).toContain('date=2024-06-01');
|
|
});
|
|
});
|
|
});
|