feat: enhance NewAppointmentsTable with dynamic patient record navigation and update DashboardPage tests
This commit is contained in:
@@ -1,5 +1,5 @@
|
||||
import { describe, it, expect, beforeEach, vi } from 'vitest';
|
||||
import { screen } from '@testing-library/react';
|
||||
import { screen, fireEvent, waitFor } from '@testing-library/react';
|
||||
import { renderWithProviders } from '../test/utils';
|
||||
|
||||
vi.mock('../lib/api', () => ({
|
||||
@@ -7,6 +7,12 @@ vi.mock('../lib/api', () => ({
|
||||
ApiError: class extends Error {},
|
||||
}));
|
||||
|
||||
const navigate = vi.fn();
|
||||
vi.mock('react-router-dom', async () => ({
|
||||
...(await vi.importActual<typeof import('react-router-dom')>('react-router-dom')),
|
||||
useNavigate: () => navigate,
|
||||
}));
|
||||
|
||||
import { api } from '../lib/api';
|
||||
import { useAuthStore } from '../stores/authStore';
|
||||
import DashboardPage from './DashboardPage';
|
||||
@@ -103,7 +109,32 @@ describe('DashboardPage (ported clinic dashboard)', () => {
|
||||
expect(screen.queryByText('پزشکان کلینیک')).not.toBeInTheDocument();
|
||||
});
|
||||
|
||||
it('«مشاهده» به همان روزِ نوبت در لیست نوبتها لینک میدهد', async () => {
|
||||
it('«مشاهده» نوبتِ قطعیشده، پروندهٔ بیمار را باز میکند', async () => {
|
||||
// fixture وضعیت `completed` دارد — یعنی از قطعیشدن رد شده و پرونده دارد.
|
||||
get.mockImplementation((url: string) => {
|
||||
if (url.startsWith('/api/v1/patients?search='))
|
||||
return Promise.resolve({ success: true, data: [{ uuid: 'rec-42' }] });
|
||||
return Promise.resolve(clinicPayload);
|
||||
});
|
||||
|
||||
renderWithProviders(<DashboardPage />, { route: '/admin/dashboard' });
|
||||
await screen.findByText('دنیا خلیلی');
|
||||
|
||||
fireEvent.click(screen.getByText('مشاهده'));
|
||||
|
||||
await waitFor(() => expect(get).toHaveBeenCalledWith(expect.stringContaining('/api/v1/patients?search=09136549874')));
|
||||
await waitFor(() => expect(navigate).toHaveBeenCalledWith('/admin/patients/rec-42'));
|
||||
});
|
||||
|
||||
it('«مشاهده» نوبتِ ثبتشده (قطعینشده) به لیست نوبتهای همان روز میرود', async () => {
|
||||
get.mockResolvedValue({
|
||||
...clinicPayload,
|
||||
data: {
|
||||
...clinicPayload.data,
|
||||
today_appointments: [{ ...clinicPayload.data.today_appointments[0], status: 'pending' }],
|
||||
},
|
||||
});
|
||||
|
||||
renderWithProviders(<DashboardPage />, { route: '/admin/dashboard' });
|
||||
await screen.findByText('دنیا خلیلی');
|
||||
|
||||
|
||||
Reference in New Issue
Block a user