ant-design/components/notification/__tests__/index.test.js

82 lines
2.2 KiB
JavaScript
Raw Normal View History

2017-03-19 02:04:32 +08:00
import notification from '..';
describe('notification', () => {
2017-11-13 10:46:22 +08:00
beforeAll(() => {
jest.useFakeTimers();
});
2017-11-09 20:33:25 +08:00
afterAll(() => {
jest.useRealTimers();
});
2017-03-19 02:04:32 +08:00
afterEach(() => {
notification.destroy();
});
2017-10-20 15:10:53 +08:00
it('should be able to hide manually', () => {
2017-03-19 02:04:32 +08:00
notification.open({
message: 'Notification Title',
duration: 0,
key: '1',
});
notification.open({
message: 'Notification Title',
duration: 0,
key: '2',
});
expect(document.querySelectorAll('.ant-notification-notice').length).toBe(2);
notification.close('1');
2017-10-20 15:10:53 +08:00
jest.runAllTimers();
2017-03-19 02:04:32 +08:00
expect(document.querySelectorAll('.ant-notification-notice').length).toBe(1);
notification.close('2');
2017-10-20 15:10:53 +08:00
jest.runAllTimers();
2017-03-19 02:04:32 +08:00
expect(document.querySelectorAll('.ant-notification-notice').length).toBe(0);
});
it('should be able to destroy globally', () => {
notification.open({
message: 'Notification Title',
duration: 0,
});
notification.open({
message: 'Notification Title',
duration: 0,
});
expect(document.querySelectorAll('.ant-notification').length).toBe(1);
expect(document.querySelectorAll('.ant-notification-notice').length).toBe(2);
notification.destroy();
expect(document.querySelectorAll('.ant-notification').length).toBe(0);
expect(document.querySelectorAll('.ant-notification-notice').length).toBe(0);
});
it('should be able to destroy after config', () => {
notification.config({
bottom: 100,
});
notification.destroy();
});
it('should be able to open with icon', () => {
2018-12-07 16:17:45 +08:00
const openNotificationWithIcon = type => {
const iconPrefix = '.ant-notification-notice-icon';
notification[type]({
message: 'Notification Title',
duration: 0,
description: 'This is the content of the notification.',
});
expect(document.querySelectorAll(`${iconPrefix}-${type}`).length).toBe(1);
};
2018-12-07 16:17:45 +08:00
['success', 'info', 'warning', 'error'].forEach(type => {
openNotificationWithIcon(type);
});
});
it('trigger onClick', () => {
notification.open({
message: 'Notification Title',
duration: 0,
});
expect(document.querySelectorAll('.ant-notification').length).toBe(1);
});
2017-03-19 02:04:32 +08:00
});