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:
hamed
2026-07-13 14:26:24 +03:30
co-authored by Claude Opus 4.8
parent 1a8fab1131
commit 3fe007b272
4 changed files with 60 additions and 32 deletions
+12 -5
View File
@@ -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');