import { describe, it, expect } from 'vitest' import { render, screen } from '@testing-library/react' import { SpreadUI } from './spread-ui' describe('', () => { it('renders a single min/max pair', () => { render() expect(screen.getByText('10')).toBeTruthy() expect(screen.getByText('100')).toBeTruthy() expect(screen.getByText('-')).toBeTruthy() }) it('applies the formatter to both bounds', () => { render( n.toLocaleString('en-US')} />, ) expect(screen.getByText('1,234')).toBeTruthy() expect(screen.getByText('9,876')).toBeTruthy() }) it('renders prefix and suffix when provided', () => { render( , ) expect(screen.getByText('Range')).toBeTruthy() expect(screen.getByText('kWh')).toBeTruthy() }) it('renders multiple items as separate rows', () => { render( , ) expect(screen.getByText('Q1')).toBeTruthy() expect(screen.getByText('Q2')).toBeTruthy() expect(screen.getByText('Q3')).toBeTruthy() // One separator dash per item. expect(screen.getAllByText('-')).toHaveLength(3) }) it('renders nothing visible when items is empty', () => { const { container } = render() expect(container.querySelectorAll('h5').length).toBe(0) }) it('renders a series avatar with the first letter of the name', () => { render( , ) expect(screen.getByLabelText('Revenue').textContent).toBe('R') }) it('renders the note when provided', () => { render() expect(screen.getByText('Last 7 days')).toBeTruthy() }) it('omits series / note when fields are absent', () => { const { container } = render() expect(container.querySelector('.MuiAvatar-root')).toBeNull() expect(container.querySelector('p')).toBeNull() }) it('renders the row in order: Series → Prefix → Min → — → Max → Suffix', () => { const { container } = render( , ) // h5 / h6 / caption typography variants cover prefix, value, separator, suffix. const typographies = Array.from( container.querySelectorAll('.MuiTypography-root'), ).map((el) => el.textContent ?? '') // The Series avatar is not Typography; we look at the inline-row text. expect(typographies).toEqual(['$', '10', '-', '20', 'USD']) }) it('still renders both bounds when a per-item color is supplied', () => { // Color threading goes through MUI's `sx` so the runtime inline style // isn't populated in JSDOM — we just check that both bounds render // normally with the color prop set. render() expect(screen.getByText('1')).toBeTruthy() expect(screen.getByText('2')).toBeTruthy() }) })