2022-05-11 14:26:18 +08:00
|
|
|
import notification, { actWrapper } from '..';
|
|
|
|
import { act } from '../../../tests/utils';
|
|
|
|
import { awaitPromise, triggerMotionEnd } from './util';
|
|
|
|
|
|
|
|
describe('notification.config', () => {
|
|
|
|
beforeAll(() => {
|
|
|
|
actWrapper(act);
|
|
|
|
});
|
|
|
|
|
|
|
|
beforeEach(() => {
|
2023-06-07 21:59:21 +08:00
|
|
|
jest.useFakeTimers();
|
2022-05-11 14:26:18 +08:00
|
|
|
});
|
|
|
|
|
|
|
|
afterEach(async () => {
|
|
|
|
// Clean up
|
|
|
|
notification.destroy();
|
|
|
|
await triggerMotionEnd();
|
|
|
|
|
|
|
|
notification.config({
|
|
|
|
prefixCls: null,
|
|
|
|
getContainer: null,
|
|
|
|
});
|
|
|
|
|
2023-06-07 21:59:21 +08:00
|
|
|
jest.useRealTimers();
|
2022-05-11 14:26:18 +08:00
|
|
|
|
|
|
|
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
|
2023-06-07 21:59:21 +08:00
|
|
|
jest.advanceTimersByTime(100);
|
2022-05-11 14:26:18 +08:00
|
|
|
});
|
|
|
|
|
|
|
|
// 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
|
2023-06-07 21:59:21 +08:00
|
|
|
jest.advanceTimersByTime(100);
|
2022-05-11 14:26:18 +08:00
|
|
|
});
|
|
|
|
await triggerMotionEnd(false);
|
|
|
|
|
|
|
|
expect(document.querySelectorAll('.ant-notification-notice')).toHaveLength(5);
|
|
|
|
expect(document.querySelectorAll('.ant-notification-notice')[4].textContent).toBe(
|
|
|
|
'Notification last',
|
|
|
|
);
|
|
|
|
|
|
|
|
act(() => {
|
2023-06-07 21:59:21 +08:00
|
|
|
jest.runAllTimers();
|
2022-05-11 14:26:18 +08:00
|
|
|
});
|
|
|
|
act(() => {
|
2023-06-07 21:59:21 +08:00
|
|
|
jest.runAllTimers();
|
2022-05-11 14:26:18 +08:00
|
|
|
});
|
|
|
|
|
|
|
|
await triggerMotionEnd(false);
|
|
|
|
|
|
|
|
expect(document.querySelectorAll('.ant-notification-notice')).toHaveLength(0);
|
|
|
|
});
|
|
|
|
});
|