81 lines
2.6 KiB
TypeScript
81 lines
2.6 KiB
TypeScript
import React from 'react';
|
|
import { render } from '@testing-library/react';
|
|
import { describe, it, expect, vi } from 'vitest';
|
|
import PetProfile from '../PetProfile';
|
|
import FlipbookCatalog from '../catalog/FlipbookCatalog';
|
|
|
|
vi.mock('motion/react', () => ({
|
|
AnimatePresence: ({ children }: { children: React.ReactNode }) => <>{children}</>,
|
|
motion: {
|
|
div: ({ children, ...props }: any) => <div {...props}>{children}</div>,
|
|
article: ({ children, ...props }: any) => <article {...props}>{children}</article>,
|
|
button: ({ children, ...props }: any) => <button {...props}>{children}</button>,
|
|
},
|
|
}));
|
|
|
|
vi.mock('../SafeImage', () => ({
|
|
default: ({ alt, className }: { alt: string; className?: string }) => (
|
|
<img alt={alt} className={className} data-testid="safe-image" />
|
|
),
|
|
}));
|
|
|
|
vi.mock('sonner', () => ({
|
|
toast: { success: vi.fn(), error: vi.fn(), info: vi.fn() },
|
|
}));
|
|
|
|
vi.mock('next/navigation', () => ({
|
|
useRouter: () => ({ back: vi.fn(), push: vi.fn() }),
|
|
useSearchParams: () => new URLSearchParams(),
|
|
}));
|
|
|
|
vi.mock('../../lib/store/settingsStore', () => ({
|
|
useSettingsStore: Object.assign(
|
|
(fn: (s: any) => any) =>
|
|
fn({
|
|
getText: () => '',
|
|
getBoolean: () => true,
|
|
}),
|
|
{
|
|
getState: () => ({
|
|
getText: () => '',
|
|
getBoolean: () => true,
|
|
}),
|
|
}
|
|
),
|
|
}));
|
|
|
|
vi.mock('../../lib/services/productService', () => ({
|
|
productService: { getProducts: vi.fn().mockResolvedValue([]) },
|
|
}));
|
|
|
|
vi.mock('../../lib/services/api', () => ({
|
|
default: { get: vi.fn(), post: vi.fn() },
|
|
BASE_DOMAIN: 'https://canina.ir',
|
|
}));
|
|
|
|
describe('UX-24 Semantic H1 Single-Instance Tests', () => {
|
|
it('PetProfile renders exactly one semantic H1 across all view states', () => {
|
|
const { rerender, container } = render(<PetProfile initialView="index" />);
|
|
let h1Elements = container.querySelectorAll('h1');
|
|
expect(h1Elements.length).toBe(1);
|
|
expect(h1Elements[0].textContent).toContain('همدمهای من');
|
|
|
|
rerender(<PetProfile initialView="add" />);
|
|
h1Elements = container.querySelectorAll('h1');
|
|
expect(h1Elements.length).toBe(1);
|
|
|
|
rerender(<PetProfile initialView="edit" />);
|
|
h1Elements = container.querySelectorAll('h1');
|
|
expect(h1Elements.length).toBe(1);
|
|
});
|
|
|
|
it('FlipbookCatalog renders exactly one H1 across toolbar and visible spreads', () => {
|
|
const { container: flipbookContainer } = render(
|
|
<FlipbookCatalog products={[]} />
|
|
);
|
|
const flipbookH1s = flipbookContainer.querySelectorAll('h1');
|
|
expect(flipbookH1s.length).toBe(1);
|
|
expect(flipbookH1s[0].textContent).toContain('کاتالوگ دیجیتال Canina Pharma');
|
|
});
|
|
});
|