import { render, screen, mockMatchMedia } from '../test-utils';
import CriticalCommsBanner from './CriticalCommsBanner';
mockMatchMedia();
describe('CriticalCommsBanner', () => {
const defaultProps = {
title: 'Test title',
subtitle: 'Test subtitle',
action: { label: 'Take action', href: 'https://wise.com' },
};
it('renders with default negative sentiment', () => {
render();
expect(screen.getByText('Test title')).toBeInTheDocument();
expect(screen.getByText('Test subtitle')).toBeInTheDocument();
expect(screen.getByTestId('alert')).toHaveClass('alert-negative');
});
it('renders the action as a link with correct href', () => {
render();
const action = screen.getByText('Take action');
expect(action.closest('a')).toHaveAttribute('href', 'https://wise.com');
});
it('renders the action as a button when only onClick is provided', () => {
const onClick = jest.fn();
render();
expect(screen.getByText('Take action').closest('button')).toBeInTheDocument();
});
it('passes target to the action link', () => {
render(
,
);
expect(screen.getByText('Take action').closest('a')).toHaveAttribute('target', '_blank');
});
it('does not render the action when action is undefined', () => {
render();
expect(screen.queryByRole('link')).not.toBeInTheDocument();
expect(screen.queryByRole('button')).not.toBeInTheDocument();
});
describe('sentiment variants', () => {
it('renders negative sentiment with correct alert type and icon', () => {
render();
expect(screen.getByTestId('alert')).toHaveClass('alert-negative');
// Custom icon replaces the default StatusIcon
expect(screen.queryByTestId('status-icon')).not.toBeInTheDocument();
});
it('renders warning sentiment with correct alert type and icon', () => {
render();
expect(screen.getByTestId('alert')).toHaveClass('alert-warning');
expect(screen.queryByTestId('status-icon')).not.toBeInTheDocument();
});
it('renders neutral sentiment with correct alert type and icon', () => {
render();
expect(screen.getByTestId('alert')).toHaveClass('alert-neutral');
expect(screen.queryByTestId('status-icon')).not.toBeInTheDocument();
});
});
it('wraps content in SentimentSurface with elevated emphasis', () => {
render();
const surface = screen.getByTestId('alert').closest('.critical-comms');
expect(surface).toHaveClass('wds-sentiment-surface');
expect(surface).toHaveClass('wds-sentiment-surface-warning-elevated');
});
it('applies className to the wrapper', () => {
render();
const surface = screen.getByTestId('alert').closest('.critical-comms');
expect(surface).toHaveClass('custom-class');
});
});