feat(settings): role-aware settings menu
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>
This commit is contained in:
@@ -1,18 +1,25 @@
|
||||
import { describe, it, expect } from 'vitest';
|
||||
import { describe, it, expect, beforeEach } from 'vitest';
|
||||
import { screen } from '@testing-library/react';
|
||||
import { renderWithProviders } from '../test/utils';
|
||||
import SettingsMenuPage from './SettingsMenuPage';
|
||||
import { SETTINGS_MENU } from '../components/layout/SettingsLayout';
|
||||
import { menuForRole } from '../components/layout/SettingsLayout';
|
||||
import { useAuthStore } from '../stores/authStore';
|
||||
|
||||
beforeEach(() => {
|
||||
useAuthStore.setState({ primaryRole: 'doctor' });
|
||||
});
|
||||
|
||||
describe('SettingsMenuPage', () => {
|
||||
it('lists every settings section', () => {
|
||||
it('lists the settings sections available to the current role', () => {
|
||||
renderWithProviders(<SettingsMenuPage />);
|
||||
for (const item of SETTINGS_MENU) {
|
||||
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 implemented section', () => {
|
||||
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');
|
||||
|
||||
Reference in New Issue
Block a user