feat(ux-27): normalize persian text, add persistent error/retry state and accessible aria empty-state to search

This commit is contained in:
devops committed 2026-10-17 18:27:21 +00:00
1 parent 21f7768cce
commit 23724df4e4
3 files changed
+132 -65

No files matched your search

@@ -70,4 +70,29 @@ describe('SearchResultsPage',()=>{
it('recomputes query without fetching and limits fallback suggestions',async()=>{const view=render(<SearchResultsPage query="Joint"/>);await screen.findByText('Joint Alpha');view.rerender(<SearchResultsPage query="missing"/>);expect(screen.getByText('نتیجه‌ای یافت نشد')).toBeInTheDocument();expect(screen.getAllByRole('link')).toHaveLength(3);expect(screen.queryByText('Fourth')).not.toBeInTheDocument();expect(productService.getProducts).toHaveBeenCalledTimes(1);fireEvent.click(screen.getByRole('button',{name:'بازگشت'}));expect(h.back).toHaveBeenCalled();});
it('handles service failure',async()=>{const err=vi.spyOn(console,'error').mockImplementation(()=>{});vi.mocked(productService.getProducts).mockRejectedValueOnce(new Error('offline'));render(<SearchResultsPage query="Joint"/>);await waitFor(()=>expect(err).toHaveBeenCalled());expect(screen.queryAllByRole('link')).toHaveLength(0);err.mockRestore();});
it('shows recommendation, species mismatch and neutral compatibility',async()=>{pet.active={type:'سگ',name:'Rex',medicalConditions:['pain']};render(<SearchResultsPage query=""/>);await screen.findByText('Joint Alpha');expect(screen.getByText('توصیه شده برای Rex')).toBeInTheDocument();expect(screen.getByText('مخصوص گربه')).toBeInTheDocument();expect(screen.getAllByText('مناسب برای Rex')).toHaveLength(2);});
it('matches Persian queries with arabic letters, half-space, and different diacritics via normalization', async () => {
render(<SearchResultsPage query="مادهٔ مراقبت" />);
expect(await screen.findByRole('link', { name: /ماده مراقبت/ })).toBeInTheDocument();
});
it('displays error state and recovers upon clicking retry', async () => {
vi.mocked(productService.getProducts).mockRejectedValueOnce(new Error('Network error'));
vi.mocked(api.get).mockRejectedValueOnce(new Error('Network error'));
render(<SearchResultsPage query="Joint" />);
const alertBox = await screen.findByRole('alert');
expect(alertBox).toHaveTextContent('خطا در بارگذاری نتایج جستجو');
vi.mocked(productService.getProducts).mockResolvedValueOnce({ data: products } as any);
vi.mocked(api.get).mockResolvedValueOnce({ data: { data: [] } } as any);
const retryBtn = screen.getByTestId('search-retry-button');
fireEvent.click(retryBtn);
await waitFor(() => {
expect(screen.queryByRole('alert')).not.toBeInTheDocument();
});
});
});