Files
clinicpro/assets/admin/components/layout/Topbar.test.tsx
T
hamedandClaude Opus 4.8 1aa6794786 feat: port tauri header top-menu to admin topbar
Rebuild admin Topbar to match clinic-pro-tauri header:
- Icon order: theme -> settings -> bell (was theme -> bell -> settings)
- Settings gear now navigates to the role-based settings page
  instead of opening the personalization panel
- Search placeholder changed to «جستجو», dropped the ⌘K hint
- Add ProfileMenu: avatar + user name + context/role subtitle + caret,
  with a dropdown (profile / payments / settings / personalization / logout).
  Links are role-aware; personalization keeps the existing settings panel.

Frontend-only, no API changes. Adds ProfileMenu.test + Topbar.test.

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
2026-07-15 17:44:47 +03:30

39 lines
1.4 KiB
TypeScript

import { describe, it, expect, beforeEach, vi } from 'vitest';
import { screen, fireEvent } from '@testing-library/react';
import { renderWithProviders } from '../../test/utils';
const navigateMock = vi.fn();
vi.mock('react-router-dom', async () => {
const actual = await vi.importActual<typeof import('react-router-dom')>('react-router-dom');
return { ...actual, useNavigate: () => navigateMock };
});
import Topbar from './Topbar';
import { useAuthStore } from '../../stores/authStore';
beforeEach(() => {
navigateMock.mockClear();
useAuthStore.setState({
userName: 'ادمین', primaryRole: 'admin', context: null, logout: vi.fn(),
} as any);
});
describe('Topbar — هدر مطابق clinic-pro-tauri', () => {
it('placeholder سرچ «جستجو» است و ⌘K ندارد', () => {
renderWithProviders(<Topbar />);
expect(screen.getByPlaceholderText('جستجو')).toBeInTheDocument();
expect(screen.queryByText('⌘K')).toBeNull();
});
it('دکمه تنظیمات (چرخ‌دنده) به صفحه تنظیمات نقش می‌رود', () => {
renderWithProviders(<Topbar />);
fireEvent.click(screen.getByTitle('تنظیمات'));
expect(navigateMock).toHaveBeenCalledWith('/admin/settings'); // نقش admin
});
it('منوی پروفایل با نام کاربر رندر می‌شود', () => {
renderWithProviders(<Topbar />);
expect(screen.getByText('ادمین')).toBeInTheDocument();
});
});