fix(ux-24): enforce semantic single H1 in catalog spread and add heading hierarchy regression tests

This commit is contained in:
devops committed 2026-10-17 17:28:27 +00:00
1 parent 0d8125bd37
commit 956ef3b4d3
2 files changed
+82 -2

No files matched your search

@@ -0,0 +1,80 @@
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');
});
});
@@ -140,9 +140,9 @@ export default function CatalogPageSpread({
</div>
<div className="space-y-1.5">
<h1 className="text-xl sm:text-2xl md:text-3xl font-black font-lalezar leading-tight text-transparent bg-clip-text bg-gradient-to-r from-amber-100 via-white to-amber-300">
<h2 className="text-xl sm:text-2xl md:text-3xl font-black font-lalezar leading-tight text-transparent bg-clip-text bg-gradient-to-r from-amber-100 via-white to-amber-300">
کاتالوگ تخصصی و راهنمای بالینی مکمل‌های دارویی کنینا
</h1>
</h2>
<p className="text-[10px] sm:text-[11px] text-slate-300 font-medium max-w-md mx-auto leading-relaxed">
مرجع رسمی مکمل‌های درمانی حیوانات خانگی با استانداردهای داروسازی آلمان (GMP) و تاییدیه‌های ارتوپدی و پوست
</p>