The deactivation warning was blocked on task 07: there was no way to count "the
appointments on this resource" until occupancy rows linked the two. They do
now, so GET /resource/{uuid} returns upcoming_appointments. It stays off the
list endpoint, where it would be one count query per row.
It is a warning, not a block, and the wording says so: switching a resource off
does not cancel anything, it only removes the resource from future searches.
The panel shows it the moment the "active" box is unticked.
The calendar's exception range still used <input type="date">, which is
Gregorian. Operators say dates in Jalali, and the mental conversion is exactly
where an exception gets recorded a day off. PersianDateInput takes the same
YYYY-MM-DD string, so this is a drop-in swap.
Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
68 lines
2.3 KiB
TypeScript
68 lines
2.3 KiB
TypeScript
import { describe, it, expect, vi, beforeEach } from 'vitest';
|
||
import { screen, waitFor } from '@testing-library/react';
|
||
import userEvent from '@testing-library/user-event';
|
||
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 {},
|
||
}));
|
||
|
||
vi.mock('sonner', () => ({ toast: { success: vi.fn(), error: vi.fn() } }));
|
||
|
||
import { api } from '../../lib/api';
|
||
import ResourceFormModal from './ResourceFormModal';
|
||
|
||
const get = api.get as ReturnType<typeof vi.fn>;
|
||
|
||
const resource = {
|
||
uuid: 'r-1',
|
||
name: 'لیزر ۱',
|
||
address_uuid: 'b-1',
|
||
type_uuid: 't-1',
|
||
capacity: 1,
|
||
is_active: true,
|
||
attributes: {},
|
||
};
|
||
|
||
const props = {
|
||
open: true,
|
||
resource: resource as never,
|
||
branches: [{ uuid: 'b-1', name: 'شعبه' }] as never,
|
||
types: [{ uuid: 't-1', name: 'دستگاه', code: 'device' }] as never,
|
||
saving: false,
|
||
onClose: () => {},
|
||
onSave: () => {},
|
||
};
|
||
|
||
describe('ResourceFormModal — هشدار غیرفعالسازی', () => {
|
||
beforeEach(() => vi.clearAllMocks());
|
||
|
||
/** ⭐ غیرفعالکردن نوبتها را لغو نمیکند؛ اپراتور باید بداند چند بیمار درگیرند. */
|
||
it('warns with the upcoming count only once the resource is switched off', async () => {
|
||
get.mockResolvedValue({ data: { ...resource, upcoming_appointments: 4 } });
|
||
const user = userEvent.setup();
|
||
|
||
renderWithProviders(<ResourceFormModal {...props} />);
|
||
|
||
await waitFor(() => expect(get).toHaveBeenCalledWith('/api/v1/resource/r-1'));
|
||
expect(screen.queryByText(/نوبت آیندهٔ فعال دارد/)).toBeNull();
|
||
|
||
await user.click(screen.getByLabelText('منبع فعال است'));
|
||
|
||
expect(await screen.findByText(/۴ نوبت آیندهٔ فعال دارد/)).toBeInTheDocument();
|
||
});
|
||
|
||
it('stays quiet when nothing is booked on the resource', async () => {
|
||
get.mockResolvedValue({ data: { ...resource, upcoming_appointments: 0 } });
|
||
const user = userEvent.setup();
|
||
|
||
renderWithProviders(<ResourceFormModal {...props} />);
|
||
|
||
await waitFor(() => expect(get).toHaveBeenCalled());
|
||
await user.click(screen.getByLabelText('منبع فعال است'));
|
||
|
||
expect(screen.queryByText(/نوبت آیندهٔ فعال دارد/)).toBeNull();
|
||
});
|
||
});
|