2021-08-17 10:45:33 +08:00
|
|
|
import notification, { getInstance } from '..';
|
2022-10-12 22:44:28 +08:00
|
|
|
import { waitFakeTimer, act } from '../../../tests/utils';
|
2021-08-17 10:45:33 +08:00
|
|
|
|
|
|
|
describe('notification.config', () => {
|
|
|
|
beforeEach(() => {
|
|
|
|
jest.useFakeTimers();
|
|
|
|
});
|
|
|
|
|
|
|
|
afterAll(() => {
|
|
|
|
notification.destroy();
|
|
|
|
});
|
|
|
|
|
|
|
|
it('should be able to config maxCount', async () => {
|
|
|
|
notification.config({
|
|
|
|
maxCount: 5,
|
|
|
|
duration: 0.5,
|
|
|
|
});
|
|
|
|
|
|
|
|
for (let i = 0; i < 10; i += 1) {
|
2022-04-14 18:09:19 +08:00
|
|
|
act(() => {
|
|
|
|
notification.open({
|
|
|
|
message: 'Notification message',
|
2022-08-26 16:00:38 +08:00
|
|
|
key: i as unknown as string,
|
2022-04-14 18:09:19 +08:00
|
|
|
});
|
2021-08-17 10:45:33 +08:00
|
|
|
});
|
|
|
|
}
|
|
|
|
|
2022-04-14 18:09:19 +08:00
|
|
|
act(() => {
|
|
|
|
notification.open({
|
|
|
|
message: 'Notification last',
|
|
|
|
key: '11',
|
|
|
|
});
|
2021-08-17 10:45:33 +08:00
|
|
|
});
|
|
|
|
|
2022-10-12 22:44:28 +08:00
|
|
|
await waitFakeTimer();
|
2021-08-17 10:45:33 +08:00
|
|
|
|
|
|
|
expect(document.querySelectorAll('.ant-notification-notice').length).toBe(5);
|
2022-08-26 16:00:38 +08:00
|
|
|
expect(document.querySelectorAll('.ant-notification-notice')[4]?.textContent).toBe(
|
2021-08-17 10:45:33 +08:00
|
|
|
'Notification last',
|
|
|
|
);
|
|
|
|
|
2022-10-12 22:44:28 +08:00
|
|
|
await waitFakeTimer();
|
2022-04-14 18:09:19 +08:00
|
|
|
|
2022-08-26 16:00:38 +08:00
|
|
|
expect((await getInstance('ant-notification-topRight'))?.component.state.notices).toHaveLength(
|
2021-08-17 10:45:33 +08:00
|
|
|
0,
|
|
|
|
);
|
2022-10-12 22:44:28 +08:00
|
|
|
|
|
|
|
jest.useRealTimers();
|
2021-08-17 10:45:33 +08:00
|
|
|
});
|
|
|
|
});
|