mirror of
https://github.com/ant-design/ant-design.git
synced 2024-12-02 15:59:38 +08:00
2341a25d91
* more refactor * chore: motion support * chore: tmp test * test: Hooks * chore: static function * tmp of it * all of it * mv prefix * chore: clean up * chore: clean up * more test case * test: all base test * test: all test case * init * refactor: rm notification.open instance related code * follow up * refactor: singlton * test: notification test case * refactor to destroy * refactor: message base * test: part test case * test: more * test: more * test: all test * chore: clean up * docs: reorder * chore: fix lint * test: fix test case * chore: add act * chore: back * chore: fix style * test: notification test * test: more and more * test: fix more test * test: index * test: more & more * test: fix placement * test: fix coverage * chore: clean up * chore: bundle size * fix: 17 * chore: more * test: message * test: more test * fix: lint * test: rm class in static * chore: clean up * test: coverage * chore: fix lint
88 lines
1.9 KiB
TypeScript
88 lines
1.9 KiB
TypeScript
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);
|
|
});
|
|
});
|