refactor(settings): unify settings sidebar across all pages

SettingsLayout rendered its own role-gated aside while the subscription page
rendered PurchaseSubscriptionSidebar, so /admin/subscription and other settings
pages (sms-wallet, ...) showed two different settings menus. Make SettingsLayout
render the shared PurchaseSubscriptionSidebar and have SubscriptionPage use
SettingsLayout too, so every settings page shows one identical menu. menuForRole
/ SETTINGS_MENU are kept for the mobile settings list (SettingsMenuPage).

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
This commit is contained in:
hamed
2026-07-14 15:25:10 +03:30
co-authored by Claude Opus 4.8
parent 2f4d82b703
commit f33c61365d
3 changed files with 35 additions and 127 deletions
@@ -9,15 +9,13 @@ beforeEach(() => {
});
describe('SettingsLayout', () => {
it('renders every menu item available to the role, plus the content', () => {
it('renders the shared settings sidebar and the content', () => {
renderWithProviders(
<SettingsLayout active="subscription">
<div>محتوای اشتراک</div>
</SettingsLayout>,
);
for (const item of menuForRole('doctor')) {
expect(screen.getByText(item.label)).toBeInTheDocument();
}
expect(screen.getByText('خرید اشتراک')).toBeInTheDocument();
expect(screen.getByText('محتوای اشتراک')).toBeInTheDocument();
});
@@ -28,23 +26,18 @@ describe('SettingsLayout', () => {
expect(active).toHaveAttribute('href', '/admin/subscription');
});
it('renders every visible item as a navigable link', () => {
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');
expect(screen.queryByText('به‌زودی')).not.toBeInTheDocument();
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('hides role-specific items from other roles', () => {
// doctor sees مدیریت پزشک but not مدیریت مطب (clinic-only)
it('shows the same menu to every role (ungated, mirroring tauri)', () => {
// the desktop sidebar is not role-gated: مدیریت مطب shows even for a doctor
renderWithProviders(<SettingsLayout active="subscription"><div /></SettingsLayout>);
expect(screen.getByText('مدیریت پزشک')).toBeInTheDocument();
expect(screen.queryByText('مدیریت مطب')).not.toBeInTheDocument();
// clinic sees مدیریت مطب but not مدیریت پزشک / نوبت دهی
expect(menuForRole('clinic').map((i) => i.key)).toContain('clinic');
expect(menuForRole('clinic').map((i) => i.key)).not.toContain('doctor');
expect(menuForRole('clinic').map((i) => i.key)).not.toContain('appointment');
expect(screen.getByText('مدیریت مطب')).toBeInTheDocument();
});
it('filters the menu by the search query', () => {
@@ -53,4 +46,11 @@ describe('SettingsLayout', () => {
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');
expect(menuForRole('clinic').map((i) => i.key)).not.toContain('doctor');
expect(menuForRole('clinic').map((i) => i.key)).not.toContain('appointment');
});
});