feat(wiki): add accessible accordion disclosures for ingredients
Deploy Canina / deploy (push) Successful in 2m6s

This commit is contained in:
devops committed 2026-10-17 14:01:23 +00:00
1 parent 2c3e4bb752
commit 5b20bab381
2 files changed
+130 -12

No files matched your search

@@ -281,6 +281,88 @@ describe('IngredientWiki Component', () => {
});
it('renders accessible disclosures and preserves complete content while toggling', 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',
}] });
const { container } = render(<IngredientWiki />);
await waitFor(() => expect(screen.getByRole('button', { name: /بیوتین.*نمایش جزئیات/ })).toBeInTheDocument());
const trigger = screen.getByRole('button', { name: /بیوتین.*نمایش جزئیات/ });
expect(trigger).toHaveAttribute('aria-expanded', 'false');
const panelId = trigger.getAttribute('aria-controls');
expect(panelId).toBeTruthy();
const panel = container.querySelector(`#${panelId}`);
expect(panel).toHaveAttribute('role', 'region');
expect(panel).toHaveAttribute('aria-labelledby', trigger.id);
expect(panel).not.toBeVisible();
expect(screen.getByText('توضیح کامل بیوتین')).toBeInTheDocument();
expect(screen.getByText('فایده اول')).toBeInTheDocument();
expect(screen.getByText('فایده دوم')).toBeInTheDocument();
expect(screen.getByText('محصول بیوتین')).toBeInTheDocument();
fireEvent.click(trigger);
expect(trigger).toHaveAttribute('aria-expanded', 'true');
expect(panel).toBeVisible();
expect(screen.getByText('توضیح کامل بیوتین')).toBeInTheDocument();
expect(screen.getByText('محصول بیوتین')).toBeInTheDocument();
fireEvent.click(trigger);
expect(trigger).toHaveAttribute('aria-expanded', 'false');
expect(panel).not.toBeVisible();
expect(screen.getByText('توضیح کامل بیوتین')).toBeInTheDocument();
expect(screen.getByText('محصول بیوتین')).toBeInTheDocument();
});
it('auto-expands a deep-linked ingredient beyond the first page', async () => {
mockSearchParamsGet.mockImplementation((param: string) => param === 'term' ? 'ingredient-13' : null);
(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 />);
const targetTrigger = await screen.findByRole('button', { name: /ماده شماره 13.*بستن جزئیات/ });
expect(targetTrigger).toHaveAttribute('aria-expanded', 'true');
expect(document.getElementById(targetTrigger.getAttribute('aria-controls')!)).toBeVisible();
expect(screen.getByText(/نمایش ۱۶ از ۱۸ ماده/)).toBeInTheDocument();
expect(document.getElementById('wiki-trigger-ingredient-1')).toHaveAttribute('aria-expanded', 'false');
});
it('keeps an expanded ingredient open after loading another page', 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 />);
const firstTrigger = await screen.findByRole('button', { name: /ماده شماره 1.*نمایش جزئیات/ });
fireEvent.click(firstTrigger);
expect(firstTrigger).toHaveAttribute('aria-expanded', 'true');
fireEvent.click(screen.getByRole('button', { name: /مشاهده ۸ ماده بیشتر/ }));
expect(firstTrigger).toHaveAttribute('aria-expanded', 'true');
expect(screen.getByRole('button', { name: /ماده شماره 9.*نمایش جزئیات/ })).toHaveAttribute('aria-expanded', 'false');
expect(screen.getByText(/نمایش ۱۶ از ۱۸ ماده/)).toBeInTheDocument();
});
it('keeps the mobile breadcrumb close to the top edge', () => {
(productService.getProducts as any).mockResolvedValueOnce({ data: [] });
(api.get as any).mockResolvedValueOnce({ data: [] });