Files
clinicpro/assets/admin/components/layout/SettingsLayout.test.tsx
T
hamed 773f9d4d16 feat: update session payment logic to ensure accurate payable amounts and reflect consumables in cost breakdown
- Adjusted the calculation of payable amounts in PaymentStep to align with server logic, ensuring overpayments are handled correctly.
- Enhanced DetailsStep to include consumables in the itemized cost breakdown, ensuring consistency with patient share calculations.
- Updated tests for SessionPaymentPage to validate new behavior regarding overpayments and consumable listings.
- Modified PatientController to register SessionPayment correctly when settling sessions via wallet, preventing double charges.
- Refactored WalletService to remove outdated methods and ensure wallet transactions reflect the correct amounts after discounts.
- Improved accessibility in SearchableSelect component by adding aria labels and ensuring proper role attributes for screen readers.
- Updated styles to ensure minimum touch targets meet WCAG guidelines for mobile usability.
2026-07-19 13:29:46 +03:30

68 lines
3.5 KiB
TypeScript

import { describe, it, expect, beforeEach } from 'vitest';
import { screen, fireEvent } from '@testing-library/react';
import { renderWithProviders } from '../../test/utils';
import SettingsLayout, { menuForRole } from './SettingsLayout';
import { useAuthStore } from '../../stores/authStore';
beforeEach(() => {
useAuthStore.setState({ primaryRole: 'doctor' });
});
describe('SettingsLayout', () => {
it('renders the shared settings sidebar and the content', () => {
renderWithProviders(
<SettingsLayout active="subscription">
<div>محتوای اشتراک</div>
</SettingsLayout>,
);
expect(screen.getByText('خرید اشتراک')).toBeInTheDocument();
expect(screen.getByText('محتوای اشتراک')).toBeInTheDocument();
});
it('marks the active item with aria-current=page', () => {
renderWithProviders(<SettingsLayout active="subscription"><div /></SettingsLayout>);
const active = screen.getByText('خرید اشتراک').closest('a');
expect(active).toHaveAttribute('aria-current', 'page');
expect(active).toHaveAttribute('href', '/admin/subscription');
});
it('renders the tauri-sourced items as navigable links', () => {
renderWithProviders(<SettingsLayout active="subscription"><div /></SettingsLayout>);
expect(screen.getByText('مدیریت نوبت دهی').closest('a')).toHaveAttribute('href', '/admin/appointment-settings');
expect(screen.getByText('تگ ها').closest('a')).toHaveAttribute('href', '/admin/tags-settings');
// 'مدیریت پزشک' lives in the main nav, not the settings menu
expect(screen.queryByText('مدیریت پزشک')).not.toBeInTheDocument();
});
it('role-gates the desktop sidebar: a doctor does not see the clinic-doctors tab', () => {
renderWithProviders(<SettingsLayout active="subscription"><div /></SettingsLayout>);
expect(screen.queryByText('پزشکان کلینیک')).not.toBeInTheDocument();
// the removed 'مدیریت مطب' tab must be gone for everyone
expect(screen.queryByText('مدیریت مطب')).not.toBeInTheDocument();
});
it('shows the clinic-doctors tab to a clinic owner', () => {
useAuthStore.setState({ primaryRole: 'clinic' });
renderWithProviders(<SettingsLayout active="clinic-doctors"><div /></SettingsLayout>);
expect(screen.getByText('پزشکان کلینیک').closest('a')).toHaveAttribute('href', '/admin/settings/clinic-doctors');
});
it('filters the menu by the search query', () => {
renderWithProviders(<SettingsLayout active="subscription"><div /></SettingsLayout>);
fireEvent.change(screen.getByLabelText('جستجو در تنظیمات'), { target: { value: 'اشتراک' } });
expect(screen.getByText('خرید اشتراک')).toBeInTheDocument();
expect(screen.queryByText('خدمات')).not.toBeInTheDocument();
});
it('menuForRole still role-gates the mobile settings list', () => {
// SettingsMenuPage (mobile) keeps using menuForRole / SETTINGS_MENU
expect(menuForRole('clinic').map((i) => i.key)).toContain('clinic-doctors');
expect(menuForRole('clinic').map((i) => i.key)).not.toContain('doctor');
// کلینیک ورودی تنظیمات نوبت‌دهیِ مخصوص خودش را دارد
expect(menuForRole('clinic').find((i) => i.key === 'appointment')?.to)
.toBe('/admin/settings/appointment-settings');
// a plain doctor must not get the clinic-doctors management tab
expect(menuForRole('doctor').map((i) => i.key)).not.toContain('clinic-doctors');
});
});