/** * @license * Copyright 2025 Google LLC * SPDX-License-Identifier: Apache-2.0 */ import { describe, it, expect, vi, beforeEach } from 'vitest'; import { renderWithProviders } from '../../../test-utils/render.js'; import { DescriptiveRadioButtonSelect, type DescriptiveRadioSelectItem, type DescriptiveRadioButtonSelectProps, } from './DescriptiveRadioButtonSelect.js'; vi.mock('./BaseSelectionList.js', async (importOriginal) => { const actual = await importOriginal(); return { ...actual, BaseSelectionList: vi.fn(({ children, ...props }) => ( {children} )), }; }); vi.mock('../../semantic-colors.js', () => ({ theme: { text: { primary: 'COLOR_PRIMARY', secondary: 'COLOR_SECONDARY', }, ui: { focus: 'COLOR_FOCUS', }, background: { focus: 'COLOR_FOCUS_BG', }, status: { success: 'COLOR_SUCCESS', }, }, })); describe('DescriptiveRadioButtonSelect', () => { const mockOnSelect = vi.fn(); const mockOnHighlight = vi.fn(); const ITEMS: Array> = [ { title: 'Foo Title', description: 'This is Foo.', value: 'foo', key: 'foo', }, { title: 'Bar Title', description: 'This is Bar.', value: 'bar', key: 'bar', }, { title: 'Baz Title', description: 'This is Baz.', value: 'baz', disabled: true, key: 'baz', }, ]; const renderComponent = async ( props: Partial> = {}, ) => { const defaultProps: DescriptiveRadioButtonSelectProps = { items: ITEMS, onSelect: mockOnSelect, ...props, }; const result = await renderWithProviders( , ); await result.waitUntilReady(); return result; }; beforeEach(() => { vi.clearAllMocks(); }); it('should render correctly with default props', async () => { const { lastFrame, unmount } = await renderComponent(); expect(lastFrame()).toMatchSnapshot(); unmount(); }); it('should render correctly with custom props', async () => { const { lastFrame, unmount } = await renderComponent({ initialIndex: 1, isFocused: false, showScrollArrows: true, maxItemsToShow: 5, showNumbers: true, onHighlight: mockOnHighlight, }); expect(lastFrame()).toMatchSnapshot(); unmount(); }); });