test: comprehensive test suites and quality gates pass across backend, storefront and admin
- 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.
This commit is contained in:
1 parent
1e73715169
commit
ddbf1ca026
439 files changed
+32911
-6107
No files matched your search
@@ -1,51 +1,60 @@
|
||||
"use client";
|
||||
import { describe, it, expect, vi } from 'vitest';
|
||||
import { render, screen, fireEvent } from '@testing-library/react';
|
||||
import React from 'react';
|
||||
import { describe, it, expect, vi, beforeEach } from 'vitest';
|
||||
import Tooltip from '../Tooltip';
|
||||
import { useSettingsStore } from '../../lib/store/settingsStore';
|
||||
|
||||
vi.mock('../../lib/store/settingsStore', () => ({
|
||||
useSettingsStore: vi.fn(),
|
||||
vi.mock('motion/react', () => ({
|
||||
motion: {
|
||||
div: ({ children, className, onClick }: any) => (
|
||||
<div className={className} onClick={onClick}>
|
||||
{children}
|
||||
</div>
|
||||
),
|
||||
},
|
||||
AnimatePresence: ({ children }: any) => <>{children}</>,
|
||||
}));
|
||||
|
||||
describe('Tooltip', () => {
|
||||
it('should render children correctly', () => {
|
||||
vi.mocked(useSettingsStore).mockReturnValue({});
|
||||
vi.mock('../../lib/store/settingsStore', () => ({
|
||||
useSettingsStore: () => ({
|
||||
glucosamine: {
|
||||
term: 'گلوکوزامین',
|
||||
definition: 'ترکیب طبیعی ضروری برای حفظ غضروفها',
|
||||
wikiId: 'glucosamine-wiki',
|
||||
},
|
||||
}),
|
||||
}));
|
||||
|
||||
render(
|
||||
<Tooltip termKey="mussel">
|
||||
<span>Mussel Term</span>
|
||||
</Tooltip>
|
||||
);
|
||||
|
||||
expect(screen.getByText('Mussel Term')).toBeInTheDocument();
|
||||
describe('Tooltip Component', () => {
|
||||
beforeEach(() => {
|
||||
vi.clearAllMocks();
|
||||
});
|
||||
|
||||
it('should display tooltip definition on hover', async () => {
|
||||
const mockTerms = {
|
||||
mussel: {
|
||||
key: 'mussel',
|
||||
term: 'Green Mussel',
|
||||
definition: 'Scientific definition of NZ green mussel',
|
||||
wikiId: 'green-mussel',
|
||||
},
|
||||
};
|
||||
vi.mocked(useSettingsStore).mockReturnValue(mockTerms);
|
||||
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="mussel">
|
||||
<span>Hover Me</span>
|
||||
</Tooltip>
|
||||
<Tooltip termKey="glucosamine" onWikiNavigate={onWikiNavigate}>
|
||||
توضیح گلوکوزامین
|
||||
</Tooltip>,
|
||||
);
|
||||
fireEvent.click(screen.getByText('توضیح گلوکوزامین'));
|
||||
|
||||
const trigger = screen.getByText('Hover Me');
|
||||
fireEvent.mouseEnter(trigger);
|
||||
const wikiBtn = screen.getByText('مطالعه مقاله کامل');
|
||||
fireEvent.click(wikiBtn);
|
||||
|
||||
expect(screen.getByText('Green Mussel')).toBeInTheDocument();
|
||||
expect(screen.getByText('Scientific definition of NZ green mussel')).toBeInTheDocument();
|
||||
|
||||
fireEvent.mouseLeave(trigger);
|
||||
// Tooltip should exit (though animations might delay actual removal, under standard RTL fireEvent it updates state immediately)
|
||||
expect(onWikiNavigate).toHaveBeenCalledWith('glucosamine-wiki');
|
||||
});
|
||||
});
|
||||
Reference in new issue
Block a user