import { Clock } from '@transferwise/icons'; import { mockMatchMedia, render, screen } from '../../test-utils'; import { InlinePrompt, InlinePromptProps } from './InlinePrompt'; import { Sentiment } from '../../common'; mockMatchMedia(); const MEDIA = Custom Media; describe('InlinePrompt', () => { const defaultProps: InlinePromptProps = { children: 'Prompt message', }; it('renders children', () => { render(Hello world); expect(screen.getByText('Hello world')).toBeInTheDocument(); }); it('renders with GiftBox icon as default for `proposition` sentiment', () => { render(); expect(screen.getByText('Prompt message')).toBeInTheDocument(); expect(screen.getByTestId('gift-box-icon')).toBeInTheDocument(); }); [ { sentiment: Sentiment.NEGATIVE as const, statusIconLabel: 'Error:' }, { sentiment: Sentiment.WARNING as const, statusIconLabel: 'Warning:' }, { sentiment: Sentiment.NEUTRAL as const, statusIconLabel: 'Information:' }, { sentiment: Sentiment.POSITIVE as const, statusIconLabel: 'Success:' }, { sentiment: 'proposition' as const, statusIconLabel: '' }, ].forEach(({ sentiment, statusIconLabel }) => { describe(sentiment, () => { if (statusIconLabel) { it('should render StatusIcon', () => { render(); expect(screen.getByLabelText(statusIconLabel)).toBeInTheDocument(); }); } describe('muted state', () => { it('should render icon and apply css', () => { render(); expect(screen.getByText('Prompt message').parentElement?.parentElement).toHaveClass( 'wds-inline-prompt--muted', ); expect(screen.getByTestId('InlinePrompt_Muted')).toBeInTheDocument(); }); it('should trump `media`', () => { render(); expect(screen.getByTestId('InlinePrompt_Muted')).toBeInTheDocument(); expect(screen.queryByTestId('custom-media')).not.toBeInTheDocument(); }); }); describe('loading state', () => { it('should render icon and apply css', () => { render(); expect(screen.getByText('Prompt message').parentElement?.parentElement).toHaveClass( 'wds-inline-prompt--loading', ); expect(screen.getByTestId('InlinePrompt_ProcessIndicator')).toBeInTheDocument(); }); it('should trump `media`', () => { render(); expect(screen.getByTestId('InlinePrompt_ProcessIndicator')).toBeInTheDocument(); expect(screen.queryByTestId('custom-media')).not.toBeInTheDocument(); }); }); describe('custom media', () => { it('should respect `media`', () => { render(); expect(screen.getByTestId('custom-media')).toBeInTheDocument(); }); }); describe('mediaLabel', () => { const mediaLabel = 'Custom icon label'; if (!statusIconLabel) { it('should not have accessible name for the icon', () => { const { container } = render(); expect(container.querySelector('svg')).not.toHaveAccessibleName(); }); } else { it('should use default aria label', () => { render(); expect(screen.getByLabelText(statusIconLabel)).toBeInTheDocument(); }); } it('should allow for customisation of aria label for StatusIcon', () => { render(); expect(screen.getByLabelText(mediaLabel)).toBeInTheDocument(); }); it('should allow for customisation of aria label for a custom Icon', () => { render( } />, ); expect(screen.getByLabelText(mediaLabel)).toBeInTheDocument(); }); it('should retain custom label while muted', () => { render( , ); expect(screen.getByLabelText(mediaLabel)).toBeInTheDocument(); }); }); }); }); it('forwards props to PrimitivePrompt', () => { render(); const el = screen.getByTestId('custom-test'); expect(el).toHaveClass('custom-class'); expect(el).toBeInTheDocument(); }); describe('width', () => { it('defaults to auto width (no full-width class)', () => { render(); expect(screen.getByTestId('prompt')).not.toHaveClass('wds-inline-prompt--full-width'); }); it('applies auto width (no full-width class) when explicitly set', () => { render(); expect(screen.getByTestId('prompt')).not.toHaveClass('wds-inline-prompt--full-width'); }); describe('width', () => { it('applies auto width class by default', () => { render(); expect(screen.getByTestId('prompt')).toHaveClass('wds-inline-prompt--auto-width'); }); it('strips the class if `width` is set to `full`', () => { render(); expect(screen.getByTestId('prompt')).not.toHaveClass('wds-inline-prompt--auto-width'); }); }); }); });