- Backend (NestJS): 82 suites, 641 tests passing; 0 ESLint errors; 0 tsc errors. Hardened SSL cert/key matching, SSRF IP pinning, and eBank validation. - Admin Panel (Vite/React): 48 suites, 300 tests passing; 0 ESLint errors; 0 tsc errors. Full coverage across all pages and settings. - Storefront (Next.js): 62 suites, 368 tests passing; 0 ESLint errors; 0 tsc errors. - Fixed unmount lifecycle guards, promise error handling, and component edge cases.
61 lines
2.0 KiB
TypeScript
61 lines
2.0 KiB
TypeScript
import { render, screen, fireEvent } from '@testing-library/react';
|
|
import { describe, it, expect, vi, beforeEach } from 'vitest';
|
|
import Tooltip from '../Tooltip';
|
|
|
|
vi.mock('motion/react', () => ({
|
|
motion: {
|
|
div: ({ children, className, onClick }: any) => (
|
|
<div className={className} onClick={onClick}>
|
|
{children}
|
|
</div>
|
|
),
|
|
},
|
|
AnimatePresence: ({ children }: any) => <>{children}</>,
|
|
}));
|
|
|
|
vi.mock('../../lib/store/settingsStore', () => ({
|
|
useSettingsStore: () => ({
|
|
glucosamine: {
|
|
term: 'گلوکوزامین',
|
|
definition: 'ترکیب طبیعی ضروری برای حفظ غضروفها',
|
|
wikiId: 'glucosamine-wiki',
|
|
},
|
|
}),
|
|
}));
|
|
|
|
describe('Tooltip Component', () => {
|
|
beforeEach(() => {
|
|
vi.clearAllMocks();
|
|
});
|
|
|
|
it('renders children normally', () => {
|
|
render(<Tooltip termKey="glucosamine">توضیح گلوکوزامین</Tooltip>);
|
|
expect(screen.getByText('توضیح گلوکوزامین')).toBeInTheDocument();
|
|
});
|
|
|
|
it('shows tooltip content on click', () => {
|
|
render(<Tooltip termKey="glucosamine">توضیح گلوکوزامین</Tooltip>);
|
|
const trigger = screen.getByText('توضیح گلوکوزامین');
|
|
fireEvent.click(trigger);
|
|
|
|
expect(screen.getByText('دانشنامه علمی کنینا')).toBeInTheDocument();
|
|
expect(screen.getByText('گلوکوزامین')).toBeInTheDocument();
|
|
expect(screen.getByText('ترکیب طبیعی ضروری برای حفظ غضروفها')).toBeInTheDocument();
|
|
});
|
|
|
|
it('triggers onWikiNavigate when article link is clicked', () => {
|
|
const onWikiNavigate = vi.fn();
|
|
render(
|
|
<Tooltip termKey="glucosamine" onWikiNavigate={onWikiNavigate}>
|
|
توضیح گلوکوزامین
|
|
</Tooltip>,
|
|
);
|
|
fireEvent.click(screen.getByText('توضیح گلوکوزامین'));
|
|
|
|
const wikiBtn = screen.getByText('مطالعه مقاله کامل');
|
|
fireEvent.click(wikiBtn);
|
|
|
|
expect(onWikiNavigate).toHaveBeenCalledWith('glucosamine-wiki');
|
|
});
|
|
});
|