Files
devops ddbf1ca026
Deploy Canina / deploy (push) Successful in 4m1s
E2E Playwright Tests / Run Full E2E & Security Suites (push) Failing after 7s
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.
2026-10-13 16:01:00 +00:00

20 lines
3.9 KiB
TypeScript

import React from 'react';
import {render,screen,fireEvent,act,cleanup} from '@testing-library/react';
import {vi,beforeEach,afterEach,it,expect} from 'vitest';
import FlipbookCatalog from '../catalog/FlipbookCatalog';
import type {Product} from '../../lib/data/products';
const {push}=vi.hoisted(()=>({push:vi.fn()}));
vi.mock('next/navigation',()=>({useRouter:()=>({push})}));
vi.mock('../../lib/store/settingsStore',()=>({useSettingsStore:Object.assign((fn:(s:unknown)=>unknown)=>fn({getText:()=>''}),{getState:()=>({getText:()=>''})})}));
vi.mock('../SafeImage',()=>({default:({alt}:{alt:string})=><img alt={alt}/>}));
const products=[{id:'1',name:'کلسیم',artNo:'A1',category:'مفاصل',categorySlug:'joints',image:'/x.png',symptoms:[],main_ingredients:['Calcium']},{id:'2',name:'Other supplement',artNo:'B2',category:'unknown',image:'/y.png',symptoms:[],main_ingredients:[]}] as unknown as Product[];
beforeEach(()=>{vi.useFakeTimers();Object.defineProperty(window,'innerWidth',{configurable:true,value:1024});push.mockClear();});
afterEach(()=>{cleanup();vi.useRealTimers();vi.restoreAllMocks();});
const search=()=>screen.getByPlaceholderText('جستجوی نام مکمل، کد کالا، ترکیبات...');
it('guards cover and repeated flips during transition',()=>{render(<FlipbookCatalog products={products}/>);expect(screen.getByRole('button',{name:'صفحه قبلی'})).toBeDisabled();fireEvent.click(screen.getByRole('button',{name:'صفحه بعدی'}));expect(screen.getByRole('button',{name:'صفحه بعدی'})).toBeDisabled();act(()=>vi.advanceTimersByTime(650));expect(screen.getByRole('button',{name:'صفحه قبلی'})).not.toBeDisabled();fireEvent.keyDown(window,{key:'ArrowRight'});act(()=>vi.advanceTimersByTime(650));expect(screen.getByRole('button',{name:'صفحه قبلی'})).toBeDisabled();});
it.each(['كلسيم','Calcium','B2'])('searches normalized names, ingredients, unmatched codes: %s',query=>{render(<FlipbookCatalog products={products}/>);fireEvent.change(search(),{target:{value:query}});const result=screen.getByText(query==='B2'?'Other supplement':'کلسیم',{selector:'span.truncate'});fireEvent.click(result);expect(search()).toHaveValue('');});
it('ignores navigation keys while search focused',()=>{render(<FlipbookCatalog products={products}/>);search().focus();fireEvent.keyDown(window,{key:'ArrowLeft'});act(()=>vi.advanceTimersByTime(1000));expect(screen.getByRole('button',{name:'صفحه قبلی'})).toBeDisabled();});
it('reports no results then jumps with Enter',()=>{render(<FlipbookCatalog products={products}/>);fireEvent.change(search(),{target:{value:'not-found'}});expect(screen.getByText(/یافت نشد/)).toBeInTheDocument();fireEvent.change(search(),{target:{value:'A1'}});fireEvent.keyDown(search(),{key:'Enter'});expect(search()).toHaveValue('');expect(screen.getByRole('button',{name:'صفحه قبلی'})).not.toBeDisabled();});
it('prints and returns home',()=>{vi.spyOn(window,'print').mockImplementation(()=>{});render(<FlipbookCatalog products={[]}/>);fireEvent.click(screen.getByTitle('دانلود یا چاپ نسخه کامل PDF کاتالوگ (تمامی محصولات)'));expect(window.print).toHaveBeenCalledOnce();fireEvent.click(screen.getByText('بازگشت'));expect(push).toHaveBeenCalledWith('/');});
it('responds to horizontal not vertical mobile swipes',()=>{Object.defineProperty(window,'innerWidth',{configurable:true,value:400});const {container}=render(<FlipbookCatalog products={products}/>);const root=container.firstChild!;fireEvent.touchStart(root,{touches:[{clientX:0,clientY:0}]});fireEvent.touchEnd(root,{changedTouches:[{clientX:10,clientY:100}]});act(()=>vi.advanceTimersByTime(350));expect(screen.getByRole('button',{name:'صفحه قبلی'})).toBeDisabled();fireEvent.touchStart(root,{touches:[{clientX:0,clientY:0}]});fireEvent.touchEnd(root,{changedTouches:[{clientX:100,clientY:10}]});act(()=>vi.advanceTimersByTime(350));expect(screen.getByRole('button',{name:'صفحه قبلی'})).not.toBeDisabled();});