/* eslint-disable jest/require-top-level-describe */
import { render } from '@testing-library/react';
import React from 'react';
import { renderWithUserEvent } from '../../../../test/lib/render-helpers';
import { BannerAlert, BANNER_ALERT_SEVERITIES } from '.';
describe('BannerAlert', () => {
it('should render BannerAlert element correctly', () => {
const { getByTestId, container } = render(
should render BannerAlert element correctly
,
);
expect(getByTestId('bannerAlert')).toHaveClass('mm-banner-alert');
expect(container).toMatchSnapshot();
});
it('should render with added classname', () => {
const { getByTestId } = render(
should render BannerAlert element correctly
,
);
expect(getByTestId('bannerAlert')).toHaveClass('mm-banner-alert--test');
});
it('should render with different severity classnames', () => {
const { getByTestId } = render(
<>
This is a demo of severity Info.
This is a demo of severity Warning.
This is a demo of severity Danger.
This is a demo of severity Success.
>,
);
expect(getByTestId('info')).toHaveClass('mm-banner-alert--severity-info');
expect(getByTestId('warning')).toHaveClass(
'mm-banner-alert--severity-warning',
);
expect(getByTestId('danger')).toHaveClass(
'mm-banner-alert--severity-danger',
);
expect(getByTestId('success')).toHaveClass(
'mm-banner-alert--severity-success',
);
});
it('should render BannerAlert title', () => {
const { getByText } = render(
,
);
expect(getByText('BannerAlert title test')).toBeDefined();
});
it('should render BannerAlert description', () => {
const { getByText } = render(
,
);
expect(getByText('BannerAlert description test')).toBeDefined();
});
it('should render BannerAlert action button', () => {
const { getByTestId } = render(
console.log('ButtonLink actionButtonOnClick demo')
}
>
Use actionButtonLabel for action text, actionButtonOnClick for the
onClick handler, and actionButtonProps to pass any ButtonLink prop types
such as iconName
,
);
expect(getByTestId('action')).toHaveClass('mm-banner-base__action');
});
it('should render and fire onClose event', async () => {
const onClose = jest.fn();
const { user, getByTestId } = renderWithUserEvent(
,
);
await user.click(getByTestId('close-button'));
expect(onClose).toHaveBeenCalledTimes(1);
});
});