import { describe, it, expect, vi } from 'vitest';
import { render as rtlRender, screen, fireEvent } from '@testing-library/react';
import React from 'react';
import { MantineProvider, Accordion } from '@mantine/core';
import AccordionControl from './AccordionControl';
// Helper wrapper component for testing
const TestWrapper = ({ children }: { children: React.ReactNode }) => (
{children}
);
// Custom render function
const render = (ui: React.ReactElement) => {
return rtlRender(ui, { wrapper: TestWrapper });
};
// Test wrapper component to properly provide Accordion context
const AccordionWrapper: React.FC<{
children: React.ReactNode;
defaultValue?: string[];
}> = ({ children, defaultValue = ['test'] }) => (
{children}
);
describe('AccordionControl', () => {
describe('Normal Operation', () => {
it('renders children as Title with order 4', () => {
render(
Settings Title
);
const title = screen.getByRole('heading', { level: 4 });
expect(title).toHaveTextContent('Settings Title');
});
it('renders complex children correctly', () => {
render(
Complex Content
);
expect(screen.getByTestId('complex-child')).toBeInTheDocument();
expect(screen.getByText('Complex')).toBeInTheDocument();
});
it('functions as accordion control', () => {
render(
Toggle Section
Hidden Content
);
const control = screen.getByRole('button');
fireEvent.click(control);
expect(screen.getByText('Hidden Content')).toBeInTheDocument();
});
});
describe('Edge Cases', () => {
it('handles empty children gracefully', () => {
render(
{''}
);
const title = screen.getByRole('heading', { level: 4 });
expect(title).toBeInTheDocument();
});
it('passes through children props correctly', () => {
const mockClickHandler = vi.fn();
render(
);
const innerButton = screen.getByTestId('inner-button');
fireEvent.click(innerButton);
expect(mockClickHandler).toHaveBeenCalled();
});
});
describe('Accessibility', () => {
it('provides proper semantic structure', () => {
render(
Accessible Title
);
const title = screen.getByRole('heading', { level: 4 });
const button = screen.getByRole('button');
expect(title).toHaveTextContent('Accessible Title');
expect(button).toContainElement(title);
});
});
});