2023-12-19 14:09:40 +01:00
|
|
|
import { screen } from '@testing-library/react';
|
|
|
|
import { render } from 'utils/testRenderer';
|
|
|
|
import { Banner } from './Banner';
|
|
|
|
|
|
|
|
test('should render correctly when using basic options', () => {
|
|
|
|
render(
|
|
|
|
<Banner
|
|
|
|
banner={{
|
|
|
|
message: 'This is a simple banner message.',
|
|
|
|
variant: 'warning',
|
|
|
|
}}
|
|
|
|
/>,
|
|
|
|
);
|
|
|
|
|
|
|
|
expect(
|
|
|
|
screen.getByText('This is a simple banner message.'),
|
|
|
|
).toBeInTheDocument();
|
|
|
|
expect(screen.getByTestId('WarningAmberIcon')).toBeInTheDocument();
|
|
|
|
});
|
|
|
|
|
2024-06-11 12:59:52 +02:00
|
|
|
test('should render correctly when using advanced options', async () => {
|
2023-12-19 14:09:40 +01:00
|
|
|
render(
|
|
|
|
<Banner
|
|
|
|
banner={{
|
|
|
|
message: 'This is a more advanced banner message.',
|
|
|
|
variant: 'success',
|
|
|
|
sticky: false,
|
|
|
|
icon: 'star',
|
|
|
|
link: 'dialog',
|
|
|
|
linkText: 'Click me',
|
|
|
|
dialogTitle: 'Dialog title',
|
|
|
|
dialog: 'Dialog content',
|
|
|
|
}}
|
|
|
|
/>,
|
|
|
|
);
|
|
|
|
|
|
|
|
expect(
|
|
|
|
screen.getByText('This is a more advanced banner message.'),
|
|
|
|
).toBeInTheDocument();
|
|
|
|
|
|
|
|
const link = screen.getByText('Click me');
|
|
|
|
expect(link).toBeInTheDocument();
|
|
|
|
link.click();
|
|
|
|
|
2024-06-11 12:59:52 +02:00
|
|
|
expect(await screen.findByText('Dialog title')).toBeInTheDocument();
|
2023-12-19 14:09:40 +01:00
|
|
|
expect(screen.getByText('Dialog content')).toBeInTheDocument();
|
|
|
|
});
|
|
|
|
|
|
|
|
test('should default to info variant when an invalid variant is provided', () => {
|
|
|
|
render(
|
|
|
|
<Banner
|
|
|
|
banner={{
|
|
|
|
message: 'This defaulted to an info banner message.',
|
|
|
|
// @ts-expect-error
|
|
|
|
variant: 'invalid',
|
|
|
|
}}
|
|
|
|
/>,
|
|
|
|
);
|
|
|
|
|
|
|
|
expect(
|
|
|
|
screen.getByText('This defaulted to an info banner message.'),
|
|
|
|
).toBeInTheDocument();
|
|
|
|
expect(screen.getByTestId('InfoOutlinedIcon')).toBeInTheDocument();
|
|
|
|
});
|