You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
88 lines
1.9 KiB
88 lines
1.9 KiB
3 years ago
|
import notification, { actWrapper } from '..';
|
||
|
import { act } from '../../../tests/utils';
|
||
|
import { awaitPromise, triggerMotionEnd } from './util';
|
||
|
|
||
|
describe('notification.config', () => {
|
||
|
beforeAll(() => {
|
||
|
actWrapper(act);
|
||
|
});
|
||
|
|
||
|
beforeEach(() => {
|
||
|
jest.useFakeTimers();
|
||
|
});
|
||
|
|
||
|
afterEach(async () => {
|
||
|
// Clean up
|
||
|
notification.destroy();
|
||
|
await triggerMotionEnd();
|
||
|
|
||
|
notification.config({
|
||
|
prefixCls: null,
|
||
|
getContainer: null,
|
||
|
});
|
||
|
|
||
|
jest.useRealTimers();
|
||
|
|
||
|
await awaitPromise();
|
||
|
});
|
||
|
|
||
|
it('should be able to config maxCount', async () => {
|
||
|
notification.config({
|
||
|
maxCount: 5,
|
||
|
duration: 0.5,
|
||
|
});
|
||
|
|
||
|
for (let i = 0; i < 10; i += 1) {
|
||
|
notification.open({
|
||
|
message: 'Notification message',
|
||
|
key: i,
|
||
|
duration: 999,
|
||
|
});
|
||
|
|
||
|
// eslint-disable-next-line no-await-in-loop
|
||
|
await awaitPromise();
|
||
|
|
||
|
act(() => {
|
||
|
// One frame is 16ms
|
||
|
jest.advanceTimersByTime(100);
|
||
|
});
|
||
|
|
||
|
// eslint-disable-next-line no-await-in-loop
|
||
|
await triggerMotionEnd(false);
|
||
|
|
||
|
const count = document.querySelectorAll('.ant-notification-notice').length;
|
||
|
expect(count).toBeLessThanOrEqual(5);
|
||
|
}
|
||
|
|
||
|
act(() => {
|
||
|
notification.open({
|
||
|
message: 'Notification last',
|
||
|
key: '11',
|
||
|
duration: 999,
|
||
|
});
|
||
|
});
|
||
|
|
||
|
act(() => {
|
||
|
// One frame is 16ms
|
||
|
jest.advanceTimersByTime(100);
|
||
|
});
|
||
|
await triggerMotionEnd(false);
|
||
|
|
||
|
expect(document.querySelectorAll('.ant-notification-notice')).toHaveLength(5);
|
||
|
expect(document.querySelectorAll('.ant-notification-notice')[4].textContent).toBe(
|
||
|
'Notification last',
|
||
|
);
|
||
|
|
||
|
act(() => {
|
||
|
jest.runAllTimers();
|
||
|
});
|
||
|
act(() => {
|
||
|
jest.runAllTimers();
|
||
|
});
|
||
|
|
||
|
await triggerMotionEnd(false);
|
||
|
|
||
|
expect(document.querySelectorAll('.ant-notification-notice')).toHaveLength(0);
|
||
|
});
|
||
|
});
|