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);
|
|
|
|
});
|
2017-05-08 16:57:43 +08:00
|
|
|
|
2017-05-17 10:24:16 +08:00
|
|
|
it('should be able to destroy after config', () => {
|
|
|
|
notification.config({
|
|
|
|
bottom: 100,
|
|
|
|
});
|
|
|
|
notification.destroy();
|
|
|
|
});
|
|
|
|
|
2017-05-08 16:57:43 +08:00
|
|
|
it('should be able to open with icon', () => {
|
2018-12-07 16:17:45 +08:00
|
|
|
const openNotificationWithIcon = type => {
|
2017-05-08 16:57:43 +08:00
|
|
|
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 => {
|
2017-05-08 16:57:43 +08:00
|
|
|
openNotificationWithIcon(type);
|
|
|
|
});
|
|
|
|
});
|
2018-10-18 10:16:56 +08:00
|
|
|
|
|
|
|
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
|
|
|
});
|