docbrown/app/javascript/Snackbar/__tests__/Snackbar.test.jsx
Nick Taylor d3171fb3c8
Created Snackbar components (#7415)
Created the Snackbar components.
2020-04-23 08:27:50 -04:00

46 lines
1.1 KiB
JavaScript

import { h } from 'preact';
import render from 'preact-render-to-json';
import { Snackbar, SnackbarItem } from '..';
describe('<Snackbar />', () => {
it('should render with one snackbar item', () => {
const tree = render(
<Snackbar>
<SnackbarItem message="File uploaded successfully" />
</Snackbar>,
);
expect(tree).toMatchSnapshot();
});
it('should render with multiple snackbar items', () => {
const snackbarItems = [
{
message: 'File uploaded successfully',
},
{
message: 'Unable to save file',
actions: [
{ text: 'Retry', handler: jest.fn() },
{ text: 'Abort', handler: jest.fn() },
],
},
{
message: 'There was a network error',
actions: [{ text: 'Retry', handler: jest.fn() }],
},
];
const tree = render(
<Snackbar>
{snackbarItems.map(({ message, actions = [] }) => (
<SnackbarItem message={message} actions={actions} />
))}
</Snackbar>,
);
expect(tree).toMatchSnapshot();
});
});