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

94 lines
2.6 KiB
JavaScript
Raw Normal View History

2019-01-12 03:33:27 +00:00
import { asyncExpect } from '@/tests/utils';
import notification from '..';
2018-06-10 08:02:12 +00:00
describe('notification', () => {
beforeEach(() => {
2019-01-12 03:33:27 +00:00
document.body.outerHTML = '';
});
2018-06-10 08:02:12 +00:00
afterEach(() => {
2019-01-12 03:33:27 +00:00
notification.destroy();
});
2018-06-10 08:02:12 +00:00
it('should be able to hide manually', async () => {
notification.open({
message: 'Notification Title',
duration: 0,
key: '1',
2019-01-12 03:33:27 +00:00
});
2018-06-10 08:02:12 +00:00
await asyncExpect(() => {
notification.open({
message: 'Notification Title',
duration: 0,
key: '2',
2019-01-12 03:33:27 +00:00
});
});
2018-06-10 08:02:12 +00:00
await asyncExpect(() => {
2019-01-12 03:33:27 +00:00
expect(document.querySelectorAll('.ant-notification-notice').length).toBe(2);
notification.close('1');
}, 0);
2018-06-10 08:02:12 +00:00
await asyncExpect(() => {
2019-01-12 03:33:27 +00:00
expect(document.querySelectorAll('.ant-notification-notice').length).toBe(1);
notification.close('2');
}, 0);
2018-06-10 08:02:12 +00:00
await asyncExpect(() => {
2019-01-12 03:33:27 +00:00
expect(document.querySelectorAll('.ant-notification-notice').length).toBe(0);
}, 0);
});
2018-06-10 08:02:12 +00:00
it('should be able to destroy globally', async () => {
notification.open({
message: 'Notification Title',
duration: 0,
2019-01-12 03:33:27 +00:00
});
2018-06-10 08:02:12 +00:00
await asyncExpect(() => {
notification.open({
message: 'Notification Title',
duration: 0,
2019-01-12 03:33:27 +00:00
});
});
2018-06-10 08:02:12 +00:00
await asyncExpect(() => {
2019-01-12 03:33:27 +00:00
expect(document.querySelectorAll('.ant-notification').length).toBe(1);
expect(document.querySelectorAll('.ant-notification-notice').length).toBe(2);
notification.destroy();
}, 0);
2018-06-10 08:02:12 +00:00
await asyncExpect(() => {
2019-01-12 03:33:27 +00:00
expect(document.querySelectorAll('.ant-notification').length).toBe(0);
expect(document.querySelectorAll('.ant-notification-notice').length).toBe(0);
}, 0);
});
2018-06-10 08:02:12 +00:00
it('should be able to destroy after config', () => {
notification.config({
bottom: 100,
2019-01-12 03:33:27 +00:00
});
notification.destroy();
});
2018-06-10 08:02:12 +00:00
2019-01-12 03:33:27 +00:00
it('should be able to open with icon', done => {
const openNotificationWithIcon = async type => {
const iconPrefix = '.ant-notification-notice-icon';
2018-06-10 08:02:12 +00:00
notification[type]({
message: 'Notification Title',
duration: 0,
description: 'This is the content of the notification.',
2019-01-12 03:33:27 +00:00
});
2018-06-10 08:02:12 +00:00
await asyncExpect(() => {
2019-01-12 03:33:27 +00:00
expect(document.querySelectorAll(`${iconPrefix}-${type}`).length).toBe(1);
}, 0);
2018-06-10 08:02:12 +00:00
};
2019-01-12 03:33:27 +00:00
['success', 'info', 'warning', 'error'].forEach(type => {
openNotificationWithIcon(type);
});
done();
});
2019-01-05 02:55:03 +00:00
it('trigger onClick', () => {
notification.open({
message: 'Notification Title',
duration: 0,
2019-01-12 03:33:27 +00:00
});
expect(document.querySelectorAll('.ant-notification').length).toBe(1);
});
});