fix(wiki): compact mobile cards and add pagination
Deploy Canina / deploy (push) Successful in 2m9s

This commit is contained in:
devops committed 2026-10-17 11:18:52 +00:00
1 parent 092933860a
commit 80d9dc2f45
2 files changed
+141 -31

No files matched your search

@@ -32,8 +32,8 @@ vi.mock('next/image', () => ({
// Mock next/link
vi.mock('next/link', () => ({
default: ({ children, href, className }: any) => (
<a href={href} className={className}>
default: ({ children, href, className, ...props }: any) => (
<a href={href} className={className} {...props}>
{children}
</a>
),
@@ -217,4 +217,77 @@ describe('IngredientWiki Component', () => {
expect(screen.getByText(/آغوز گاو/)).toBeInTheDocument();
});
});
it('shows only the first 8 ingredients and loads the next page on demand', async () => {
(productService.getProducts as any).mockResolvedValueOnce({ data: [] });
const ingredients = Array.from({ length: 18 }, (_, index) => ({
id: `ingredient-${index + 1}`,
slug: `ingredient-${index + 1}`,
nameFa: `ماده شماره ${index + 1}`,
description: `توضیح ماده ${index + 1}`,
benefits: [],
}));
(api.get as any).mockResolvedValueOnce({ data: ingredients });
render(<IngredientWiki />);
await waitFor(() => expect(screen.getByText('ماده شماره 1')).toBeInTheDocument());
expect(screen.getByText('ماده شماره 8')).toBeInTheDocument();
expect(screen.queryByText('ماده شماره 9')).not.toBeInTheDocument();
expect(screen.getByText(/نمایش ۸ از ۱۸ ماده/)).toBeInTheDocument();
fireEvent.click(screen.getByRole('button', { name: /مشاهده ۸ ماده بیشتر/ }));
expect(screen.getByText('ماده شماره 16')).toBeInTheDocument();
expect(screen.queryByText('ماده شماره 17')).not.toBeInTheDocument();
expect(screen.getByText(/نمایش ۱۶ از ۱۸ ماده/)).toBeInTheDocument();
});
it('resets ingredient pagination when the search query changes', async () => {
(productService.getProducts as any).mockResolvedValueOnce({ data: [] });
const ingredients = Array.from({ length: 12 }, (_, index) => ({
id: `item-${index + 1}`,
slug: `item-${index + 1}`,
nameFa: index < 10 ? `مشترک ${index + 1}` : `دیگر ${index + 1}`,
description: 'توضیح مشترک',
benefits: [],
}));
(api.get as any).mockResolvedValueOnce({ data: ingredients });
render(<IngredientWiki />);
await waitFor(() => expect(screen.getByText('مشترک 1')).toBeInTheDocument());
fireEvent.click(screen.getByRole('button', { name: /مشاهده ۴ ماده بیشتر/ }));
expect(screen.getByText('دیگر 12')).toBeInTheDocument();
fireEvent.change(screen.getByPlaceholderText(/جستجوی ماده مؤثره/), { target: { value: 'مشترک' } });
expect(screen.getByText('مشترک 8')).toBeInTheDocument();
expect(screen.queryByText('مشترک 9')).not.toBeInTheDocument();
});
it('uses compact two-column related-product cards on mobile', async () => {
(api.get as any).mockResolvedValueOnce({ data: [{
id: 'biotin', slug: 'biotin', nameFa: 'بیوتین', description: 'توضیح', benefits: [],
}] });
(productService.getProducts as any).mockResolvedValueOnce({ data: [{
id: 'p-1', slug: 'biotin-tabs', name: 'محصول بیوتین', main_ingredients: ['بیوتین'], image: '/biotin.png',
}] });
render(<IngredientWiki />);
await waitFor(() => expect(screen.getByText('محصول بیوتین')).toBeInTheDocument());
expect(screen.getByTestId('wiki-related-products-grid')).toHaveClass('grid-cols-2');
expect(screen.getByTestId('wiki-related-product-card')).toHaveClass('p-2');
expect(screen.getByTestId('wiki-related-product-image')).toHaveClass('h-20');
});
it('keeps the mobile breadcrumb close to the top edge', () => {
(productService.getProducts as any).mockResolvedValueOnce({ data: [] });
(api.get as any).mockResolvedValueOnce({ data: [] });
const { container } = render(<IngredientWiki />);
expect(container.firstElementChild).toHaveClass('pt-3', 'pb-8', 'sm:py-12');
expect(container.firstElementChild).not.toHaveClass('py-12');
});
});