From 956ef3b4d3c8c3b22b36fe916afb63edff0e20f1 Mon Sep 17 00:00:00 2001 From: devops Date: Sat, 17 Oct 2026 17:28:27 +0000 Subject: [PATCH] fix(ux-24): enforce semantic single H1 in catalog spread and add heading hierarchy regression tests --- .../__tests__/HeadingHierarchyUX24.test.tsx | 80 +++++++++++++++++++ .../components/catalog/CatalogPageSpread.tsx | 4 +- 2 files changed, 82 insertions(+), 2 deletions(-) create mode 100644 frontend/application/components/__tests__/HeadingHierarchyUX24.test.tsx diff --git a/frontend/application/components/__tests__/HeadingHierarchyUX24.test.tsx b/frontend/application/components/__tests__/HeadingHierarchyUX24.test.tsx new file mode 100644 index 00000000..574ea51b --- /dev/null +++ b/frontend/application/components/__tests__/HeadingHierarchyUX24.test.tsx @@ -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) =>
{children}
, + article: ({ children, ...props }: any) =>
{children}
, + button: ({ children, ...props }: any) => , + }, +})); + +vi.mock('../SafeImage', () => ({ + default: ({ alt, className }: { alt: string; className?: string }) => ( + {alt} + ), +})); + +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(); + let h1Elements = container.querySelectorAll('h1'); + expect(h1Elements.length).toBe(1); + expect(h1Elements[0].textContent).toContain('همدم‌های من'); + + rerender(); + h1Elements = container.querySelectorAll('h1'); + expect(h1Elements.length).toBe(1); + + rerender(); + h1Elements = container.querySelectorAll('h1'); + expect(h1Elements.length).toBe(1); + }); + + it('FlipbookCatalog renders exactly one H1 across toolbar and visible spreads', () => { + const { container: flipbookContainer } = render( + + ); + const flipbookH1s = flipbookContainer.querySelectorAll('h1'); + expect(flipbookH1s.length).toBe(1); + expect(flipbookH1s[0].textContent).toContain('کاتالوگ دیجیتال Canina Pharma'); + }); +}); diff --git a/frontend/application/components/catalog/CatalogPageSpread.tsx b/frontend/application/components/catalog/CatalogPageSpread.tsx index 5b2fd053..2922f082 100644 --- a/frontend/application/components/catalog/CatalogPageSpread.tsx +++ b/frontend/application/components/catalog/CatalogPageSpread.tsx @@ -140,9 +140,9 @@ export default function CatalogPageSpread({
-

+

کاتالوگ تخصصی و راهنمای بالینی مکمل‌های دارویی کنینا -

+

مرجع رسمی مکمل‌های درمانی حیوانات خانگی با استانداردهای داروسازی آلمان (GMP) و تاییدیه‌های ارتوپدی و پوست