import { describe, it, expect, vi } from 'vitest' import { fireEvent, render, screen } from '@testing-library/react' import StarIcon from '@mui/icons-material/Star' import { SelectionSummary } from './selection-summary' describe('', () => { it('renders nothing when total === 0 (no data to summarize)', () => { const { container } = render() expect(container.textContent).toBe('') }) it('renders nothing when total is omitted (undefined)', () => { const { container } = render() expect(container.textContent).toBe('') }) it('renders total / total when nothing is selected (count === 0)', () => { render() expect(screen.getByLabelText('10 / 10')).toBeTruthy() // No Clear button when nothing is selected. expect(screen.queryByText('Clear')).toBeNull() }) it('renders count / total + Clear when count > 0', () => { const onClear = vi.fn() render() expect(screen.getByLabelText('3 / 10')).toBeTruthy() fireEvent.click(screen.getByText('Clear')) expect(onClear).toHaveBeenCalledTimes(1) }) it('hides the Clear link when no onClear is provided', () => { render() expect(screen.queryByText('Clear')).toBeNull() }) it('honors a custom summary renderer and clear label', () => { render( `${selected} of ${total} pinned`, clear: 'Reset', }} onClear={() => undefined} />, ) expect(screen.getByText('3 of 10 pinned')).toBeTruthy() expect(screen.getByText('Reset')).toBeTruthy() }) it('renders the custom icon component when provided', () => { const { container } = render( , ) expect(container.querySelector('[data-testid="StarIcon"]')).toBeTruthy() }) })