import { describe, it, expect, vi } from 'vitest' import { render } from '@testing-library/react' import { Formula } from './formula' import { Provider } from '../provider/widget-provider' import type { FormulaWidgetData } from './types' vi.mock('./formula-ui', () => ({ FormulaUI: ({ items, formatter, }: { items: FormulaWidgetData formatter?: (value: number) => string }) => (
{items .map( (it) => `${it.prefix ?? ''}${formatter ? formatter(it.value) : it.value}${it.suffix ?? ''}`, ) .join('|')}
), })) describe(' bridge', () => { it('forwards data + formatter from the store to FormulaUI', () => { const data: FormulaWidgetData = [ { value: 12, prefix: '$' }, { value: 34, suffix: '%' }, ] const { getByTestId } = render( `[${n.toFixed(1)}]`}> , ) const ui = getByTestId('formula-ui') expect(ui.dataset.count).toBe('2') expect(ui.textContent).toBe('$[12.0]|[34.0]%') }) it('falls back to an empty items array when data is null', () => { const { getByTestId } = render( , ) expect(getByTestId('formula-ui').dataset.count).toBe('0') }) })