import { screen, render, mockMatchMedia, mockResizeObserver, waitFor } from '../test-utils'; import { Sentiment } from '../common'; import ExpressiveMoneyInput from './ExpressiveMoneyInput'; import type { Props as ExpressiveMoneyInputProps } from './ExpressiveMoneyInput'; import { Confetti } from '@transferwise/icons'; const defaultProps: ExpressiveMoneyInputProps = { label: 'You send', currency: 'GBP', amount: 1234.56, onAmountChange: jest.fn(), }; const currencySelectorOptions = [ { title: 'Popular', currencies: [ { code: 'USD', label: 'US Dollar', keywords: ['dollar', 'us'] }, { code: 'AUD', label: 'Australia Dollar', keywords: ['dollar', 'au'] }, ], }, { title: 'Others', currencies: [ { code: 'GBP', label: 'Pound', keywords: ['british'] }, { code: 'EUR', label: 'Euro', keywords: ['euro'] }, ], }, ]; mockMatchMedia(); mockResizeObserver(); describe('ExpressiveMoneyInput', () => { beforeEach(() => { jest.clearAllMocks(); }); describe('Basic rendering', () => { it('renders with basic props', () => { render(); expect(screen.getByText('You send')).toBeInTheDocument(); expect(screen.getByDisplayValue('1,234.56')).toBeInTheDocument(); }); it('renders with custom label', () => { render(); expect(screen.getByText('Amount to transfer')).toBeInTheDocument(); }); it('renders without label', () => { render(); expect(screen.getByRole('textbox')).toBeInTheDocument(); expect(screen.queryByText('You send')).not.toBeInTheDocument(); }); it('renders with different currencies', () => { render(); expect(screen.getByText('USD')).toBeInTheDocument(); }); it('renders with null amount', () => { render(); const input = screen.getByRole('textbox'); expect(input).toHaveValue(''); }); }); describe('Inline prompt', () => { it('renders basic message without sentiment', () => { render( , ); expect(screen.getByText('This is a basic message')).toBeInTheDocument(); }); it('renders inline prompt with sentiment', () => { render( , ); expect(screen.getByText('Success message')).toBeInTheDocument(); }); it('renders inline prompt with media', () => { render( , }} />, ); expect(screen.getByText('Message with icon')).toBeInTheDocument(); expect(screen.getByTestId('test-icon')).toBeInTheDocument(); }); it('does not render inline prompt when not provided', () => { render(); expect(document.querySelector('.wds-inline-prompt')).not.toBeInTheDocument(); }); it('animates inline prompt appearance', async () => { const { rerender } = render(); expect(screen.queryByText('New message')).not.toBeInTheDocument(); rerender( , ); await waitFor(() => { expect(screen.getByText('New message')).toBeInTheDocument(); }); }); it('sets correct aria-describedby when inline prompt is present', () => { render( , ); const group = screen.getByRole('group'); expect(group).toHaveAttribute('aria-describedby'); }); }); describe('Chevron', () => { it('shows chevron when showChevron is true', () => { render(); const chevronContainer = document.querySelector('.wds-expressive-money-input-chevron'); expect(chevronContainer).toBeInTheDocument(); }); it('hides chevron when showChevron is false', () => { render(); const chevronContainer = document.querySelector('.wds-expressive-money-input-chevron'); expect(chevronContainer).toBeInTheDocument(); }); it('does not show chevron by default', () => { render(); const chevronContainer = document.querySelector('.wds-expressive-money-input-chevron'); expect(chevronContainer).toBeInTheDocument(); }); }); describe('Accessibility', () => { it('has proper ARIA structure', () => { render(); const group = screen.getByRole('group'); const label = screen.getByText('You send'); const input = screen.getByRole('textbox'); expect(group).toHaveAttribute('aria-labelledby'); expect(label).toHaveAttribute('for'); expect(input).toHaveAttribute('id'); }); it('associates label with input correctly', () => { render(); const label = screen.getByText('You send'); const input = screen.getByRole('textbox'); expect(label).toHaveAttribute('for', input.getAttribute('id')); }); it('links currency selector to main label', () => { render( , ); const currencySelector = screen.getByRole('combobox'); const mainLabel = screen.getByText('You send'); expect(currencySelector).toHaveAttribute('aria-describedby', mainLabel.getAttribute('id')); }); it('describes amount input with currency selector', () => { render( , ); const input = screen.getByRole('textbox'); const currencySelector = screen.getByRole('combobox'); expect(input).toHaveAttribute('aria-describedby', currencySelector.getAttribute('id')); }); }); });