61 lines
2.6 KiB
TypeScript
61 lines
2.6 KiB
TypeScript
import { describe, it, expect, beforeEach, vi } from 'vitest';
|
|
import { screen } from '@testing-library/react';
|
|
import { renderWithProviders } from '../test/utils';
|
|
import PracticeDomainSettingsPage from './PracticeDomainSettingsPage';
|
|
import { useAuthStore } from '../stores/authStore';
|
|
import { api } from '../lib/api';
|
|
|
|
const DOMAINS = [
|
|
{ uuid: 'd-1', name: 'دندانپزشکی', has_workflow: true },
|
|
{ uuid: 'd-2', name: 'کلینیک زیبایی', has_workflow: false },
|
|
];
|
|
|
|
beforeEach(() => {
|
|
useAuthStore.setState({
|
|
primaryRole: 'clinic',
|
|
context: { scope: 'clinic', db_uuid: 'clinic-1' } as never,
|
|
});
|
|
|
|
vi.spyOn(api, 'get').mockImplementation(async (path: string) => {
|
|
if (path.startsWith('/api/v1/practice-domains')) return { data: DOMAINS } as never;
|
|
return { data: { data: { practice_domain: DOMAINS[1] } } } as never;
|
|
});
|
|
});
|
|
|
|
describe('PracticeDomainSettingsPage', () => {
|
|
/**
|
|
* این صفحه تنها عضو منوی تنظیمات بود که پوستهٔ تنظیمات را نداشت: کاربر برای رفتن
|
|
* به بخش بعدی مجبور بود «بازگشت» بزند.
|
|
*/
|
|
it('داخل پوستهٔ تنظیمات رندر میشود و منوی تنظیمات را نشان میدهد', async () => {
|
|
renderWithProviders(<PracticeDomainSettingsPage />);
|
|
|
|
expect(await screen.findByLabelText('منوی تنظیمات')).toBeInTheDocument();
|
|
});
|
|
|
|
it('همین آیتم در منو فعال است', async () => {
|
|
renderWithProviders(<PracticeDomainSettingsPage />);
|
|
|
|
// عنوان صفحه هم همین متن را دارد، پس آیتم منو با نقش link گرفته میشود.
|
|
const active = await screen.findByRole('link', { name: 'حوزهٔ فعالیت' });
|
|
|
|
expect(active).toHaveAttribute('aria-current', 'page');
|
|
expect(active).toHaveAttribute('href', '/admin/settings/practice-domain');
|
|
});
|
|
|
|
it('عنوان صفحه یک بار میآید، نه هم در هدر هم در کارت', async () => {
|
|
renderWithProviders(<PracticeDomainSettingsPage />);
|
|
|
|
expect(await screen.findByRole('heading', { name: 'حوزهٔ فعالیت' })).toBeInTheDocument();
|
|
expect(screen.getAllByRole('heading', { name: 'حوزهٔ فعالیت' })).toHaveLength(1);
|
|
});
|
|
|
|
it('حوزهٔ بدون فرآیند، هشدارش را نشان میدهد', async () => {
|
|
renderWithProviders(<PracticeDomainSettingsPage />);
|
|
|
|
expect(
|
|
await screen.findByText(/برای این حوزه هنوز فرآیند اختصاصی تعریف نشده است/),
|
|
).toBeInTheDocument();
|
|
});
|
|
});
|