Add an optional `roles` filter to the settings menu and hide items that don't apply to the current user's role, so a doctor no longer sees "مدیریت مطب" (clinic-only) and a clinic no longer sees "مدیریت پزشک" / "مدیریت نوبت دهی" (doctor-only) — avoiding menu entries that just redirect. Both the desktop shell (SettingsLayout) and the mobile list (SettingsMenuPage) filter via the shared `menuForRole` helper. Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
29 lines
1.3 KiB
TypeScript
29 lines
1.3 KiB
TypeScript
import { describe, it, expect, beforeEach } from 'vitest';
|
|
import { screen } from '@testing-library/react';
|
|
import { renderWithProviders } from '../test/utils';
|
|
import SettingsMenuPage from './SettingsMenuPage';
|
|
import { menuForRole } from '../components/layout/SettingsLayout';
|
|
import { useAuthStore } from '../stores/authStore';
|
|
|
|
beforeEach(() => {
|
|
useAuthStore.setState({ primaryRole: 'doctor' });
|
|
});
|
|
|
|
describe('SettingsMenuPage', () => {
|
|
it('lists the settings sections available to the current role', () => {
|
|
renderWithProviders(<SettingsMenuPage />);
|
|
for (const item of menuForRole('doctor')) {
|
|
expect(screen.getByText(item.label)).toBeInTheDocument();
|
|
}
|
|
// clinic-only section is not shown to a doctor
|
|
expect(screen.queryByText('مدیریت مطب')).not.toBeInTheDocument();
|
|
});
|
|
|
|
it('links every section to its route', () => {
|
|
renderWithProviders(<SettingsMenuPage />);
|
|
expect(screen.getByText('خرید اشتراک').closest('a')).toHaveAttribute('href', '/admin/subscription');
|
|
expect(screen.getByText('مدیریت نوبت دهی').closest('a')).toHaveAttribute('href', '/admin/appointment-settings');
|
|
expect(screen.getByText('حساب کاربری').closest('a')).toHaveAttribute('href', '/admin/account-settings');
|
|
});
|
|
});
|