/** * Tests for LassoToolsUIChip — covers both visible/invisible branches, * custom label overrides, custom chip/tooltip props, and the delete + * click callbacks. */ import { describe, it, expect, vi } from 'vitest' import { render, fireEvent, screen } from '@testing-library/react' import { LassoToolsUIChip } from './chip' import type { LassoToolsData } from './types' const baseValue: LassoToolsData = { id: 'p1', label: 'Polygon 1', visible: true, } describe('LassoToolsUIChip', () => { it('renders with active state when value.visible=true (color=secondary)', () => { const { container } = render( , ) // MUI Chip with color=secondary has a class containing 'colorSecondary'. const chip = container.querySelector('.MuiChip-root') expect(chip).not.toBeNull() expect(chip!.className).toContain('colorSecondary') }) it('renders with inactive state when value.visible=false (color=default)', () => { const { container } = render( , ) const chip = container.querySelector('.MuiChip-root') expect(chip).not.toBeNull() expect(chip!.className).not.toContain('colorSecondary') }) it('renders the value.label as the chip text', () => { render( , ) expect(screen.getByText('My polygon')).toBeDefined() }) it('invokes onChipToggle with id + !visible when chip is clicked', () => { const onChipToggle = vi.fn() render( , ) fireEvent.click(screen.getByText('Polygon 1')) expect(onChipToggle).toHaveBeenCalledWith('p1', false) }) it('invokes onChipToggle with id + true when starting from invisible', () => { const onChipToggle = vi.fn() render( , ) fireEvent.click(screen.getByText('Polygon 1')) expect(onChipToggle).toHaveBeenCalledWith('p1', true) }) it('invokes onDelete with id when delete icon is clicked', () => { const onDelete = vi.fn() const { getByTestId } = render( , ) // MUI Chip delete icon has data-testid='CancelIcon' by default. fireEvent.click(getByTestId('CancelIcon')) expect(onDelete).toHaveBeenCalledWith('p1') }) it('uses custom labels.tooltip.active when provided + visible=true', () => { // The tooltip is rendered lazily on hover; we just confirm the chip // renders without throwing when a custom label is supplied. expect(() => render( , ), ).not.toThrow() }) it('uses custom labels.tooltip.inactive when provided + visible=false', () => { expect(() => render( , ), ).not.toThrow() }) it('falls back to default labels when labels is omitted', () => { // Just renders without crashing; the labels?. chain falls back to // LASSO_TOOLS_LABELS.chip.tooltip[chipState]. expect(() => render( , ), ).not.toThrow() }) it('threads chipProps.ChipsProps onto the underlying MUI Chip', () => { const { container } = render( , ) expect( container.querySelector('[data-testid="pinned-chip"]'), ).not.toBeNull() }) it('threads chipProps.TooltipProps onto the wrapping Tooltip', () => { // The Tooltip wrapper isn't directly assertable without rendering it // open; we confirm no throw on the spread. expect(() => render( , ), ).not.toThrow() }) })