Files
clinicpro/assets/admin/components/layout/Topbar.test.tsx
T
hamed 6876135a53 feat: add BlogBodySanitizer for HTML sanitization on article save
- Implemented BlogBodySanitizer to clean HTML content before saving articles, ensuring security against XSS attacks.
- Added tests for BlogBodySanitizer to verify that unsafe tags and attributes are stripped from the content.
- Introduced ApiLeastPrivilegeTest to ensure that unauthorized users cannot access sensitive API routes, maintaining strict access control.
2026-08-07 21:13:38 +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', async () => {
const actual = await vi.importActual<typeof import('react-router')>('react-router');
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();
});
});