2019-01-03 16:00:55 +03:00
|
|
|
import React from 'react';
|
2021-10-22 07:18:03 +03:00
|
|
|
import { render, screen } from '@testing-library/react';
|
|
|
|
import userEvent from '@testing-library/user-event';
|
2019-01-03 16:00:55 +03:00
|
|
|
import { Notification } from '../src';
|
|
|
|
|
2020-08-08 23:26:39 +03:00
|
|
|
describe('Notification', function () {
|
2019-01-03 16:00:55 +03:00
|
|
|
it('renders correctly', () => {
|
2021-10-22 07:18:03 +03:00
|
|
|
const { container } = render(<Notification>Message</Notification>);
|
|
|
|
expect(container.firstChild).toMatchSnapshot();
|
2019-01-03 16:00:55 +03:00
|
|
|
});
|
|
|
|
|
|
|
|
it('renders with props', () => {
|
2021-10-22 07:18:03 +03:00
|
|
|
const { container } = render(
|
2020-09-09 17:35:22 +03:00
|
|
|
<Notification
|
|
|
|
type="error"
|
|
|
|
onClose={() => {
|
|
|
|
// noop
|
|
|
|
}}
|
|
|
|
>
|
2019-01-10 21:51:14 +03:00
|
|
|
Message
|
|
|
|
</Notification>
|
2019-01-03 16:00:55 +03:00
|
|
|
);
|
2021-10-22 07:18:03 +03:00
|
|
|
expect(container.firstChild).toMatchSnapshot();
|
2019-01-03 16:00:55 +03:00
|
|
|
});
|
|
|
|
|
2022-06-06 19:22:05 +03:00
|
|
|
it('should handle the click event', async () => {
|
2019-01-03 16:00:55 +03:00
|
|
|
const onClose = jest.fn();
|
2021-10-22 07:18:03 +03:00
|
|
|
render(<Notification onClose={onClose}>Message</Notification>);
|
2019-01-03 16:00:55 +03:00
|
|
|
|
2022-06-06 19:22:05 +03:00
|
|
|
await userEvent.click(screen.getByRole('button'));
|
2021-10-22 07:18:03 +03:00
|
|
|
expect(onClose).toHaveBeenCalled();
|
2019-01-03 16:00:55 +03:00
|
|
|
});
|
|
|
|
});
|