import React from 'react';
import userEvent from '@testing-library/user-event';
import renderWithTheme from '../../../testUtils/renderWithTheme';
import Notification from '..';
describe('rendering', () => {
it('shows title & content', () => {
const { getByText } = renderWithTheme(
);
expect(getByText('A title')).toBeInTheDocument();
expect(getByText('A content')).toBeInTheDocument();
});
it('shows close icon button when onClose is defined', () => {
const onClose = jest.fn();
const { getByTestId } = renderWithTheme(
);
userEvent.click(getByTestId('close-notification-button'));
expect(onClose).toHaveBeenCalledTimes(1);
});
});
describe('Notification Icon', () => {
it.each`
intent | expectedClass
${'success'} | ${'hero-icon-circle-ok'}
${'info'} | ${'hero-icon-circle-info'}
${'warning'} | ${'hero-icon-circle-warning'}
${'danger'} | ${'hero-icon-circle-cancel'}
${'error'} | ${'hero-icon-circle-cancel'}
${'any'} | ${'hero-icon-circle-ok'}
`('shows $intent icon based on intent prop', ({ intent, expectedClass }) => {
const { getByTestId } = renderWithTheme(
);
expect(getByTestId('notification-icon')).toHaveClass(expectedClass);
});
it('shows icon based on icon prop (IconName)', () => {
const { getByTestId } = renderWithTheme(
);
expect(getByTestId('notification-icon')).toHaveClass('hero-icon-coin');
});
it('shows icon based on icon prop (ReactElement)', () => {
const { getByText } = renderWithTheme(
An icon
} />
);
expect(getByText('An icon')).toBeInTheDocument();
});
it('shows no icon', () => {
const { queryByTestId } = renderWithTheme(
);
expect(queryByTestId('notification-icon')).not.toBeInTheDocument();
});
});