mirror of
https://github.com/ant-design/ant-design.git
synced 2024-11-30 06:09:34 +08:00
775d1800bb
* chore(deps-dev): bump eslint-config-prettier from 6.15.0 to 7.0.0 Bumps [eslint-config-prettier](https://github.com/prettier/eslint-config-prettier) from 6.15.0 to 7.0.0. - [Release notes](https://github.com/prettier/eslint-config-prettier/releases) - [Changelog](https://github.com/prettier/eslint-config-prettier/blob/main/CHANGELOG.md) - [Commits](https://github.com/prettier/eslint-config-prettier/compare/v6.15.0...v7.0.0) Signed-off-by: dependabot[bot] <support@github.com> * chore: fix eslint style * chore: prettier code style Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com> Co-authored-by: afc163 <afc163@gmail.com>
102 lines
2.6 KiB
JavaScript
102 lines
2.6 KiB
JavaScript
import { sleep } from '../../../tests/utils';
|
|
import message, { getInstance } from '..';
|
|
|
|
describe('message.config', () => {
|
|
// Mock for rc-util raf
|
|
window.requestAnimationFrame = callback => window.setTimeout(callback, 16);
|
|
window.cancelAnimationFrame = id => {
|
|
window.clearTimeout(id);
|
|
};
|
|
|
|
beforeEach(() => {
|
|
jest.useFakeTimers();
|
|
});
|
|
|
|
afterEach(() => {
|
|
message.destroy();
|
|
jest.useRealTimers();
|
|
});
|
|
|
|
it('should be able to config top', () => {
|
|
message.config({
|
|
top: 100,
|
|
});
|
|
message.info('whatever');
|
|
expect(document.querySelectorAll('.ant-message')[0].style.top).toBe('100px');
|
|
});
|
|
|
|
it('should be able to config rtl', () => {
|
|
message.config({
|
|
rtl: true,
|
|
});
|
|
message.info('whatever');
|
|
expect(document.querySelectorAll('.ant-message-rtl').length).toBe(1);
|
|
});
|
|
|
|
it('should be able to config getContainer', () => {
|
|
message.config({
|
|
getContainer: () => {
|
|
const div = document.createElement('div');
|
|
div.className = 'custom-container';
|
|
document.body.appendChild(div);
|
|
return div;
|
|
},
|
|
});
|
|
message.info('whatever');
|
|
expect(document.querySelectorAll('.custom-container').length).toBe(1);
|
|
});
|
|
|
|
it('should be able to config maxCount', () => {
|
|
message.config({
|
|
maxCount: 5,
|
|
});
|
|
for (let i = 0; i < 10; i += 1) {
|
|
message.info('test');
|
|
}
|
|
|
|
message.info('last');
|
|
expect(document.querySelectorAll('.ant-message-notice').length).toBe(5);
|
|
expect(document.querySelectorAll('.ant-message-notice')[4].textContent).toBe('last');
|
|
jest.runAllTimers();
|
|
expect(getInstance().component.state.notices).toHaveLength(0);
|
|
});
|
|
|
|
it('should be able to config duration', async () => {
|
|
jest.useRealTimers();
|
|
message.config({
|
|
duration: 0.5,
|
|
});
|
|
message.info('last');
|
|
expect(getInstance().component.state.notices).toHaveLength(1);
|
|
|
|
await sleep(1000);
|
|
expect(getInstance().component.state.notices).toHaveLength(0);
|
|
message.config({
|
|
duration: 3,
|
|
});
|
|
});
|
|
|
|
it('should be able to config prefixCls', () => {
|
|
message.config({
|
|
prefixCls: 'prefix-test',
|
|
});
|
|
message.info('last');
|
|
expect(document.querySelectorAll('.ant-message-notice').length).toBe(0);
|
|
expect(document.querySelectorAll('.prefix-test-notice').length).toBe(1);
|
|
message.config({
|
|
prefixCls: 'ant-message',
|
|
});
|
|
});
|
|
|
|
it('should be able to config transitionName', () => {
|
|
message.config({
|
|
transitionName: '',
|
|
});
|
|
message.info('last');
|
|
expect(document.querySelectorAll('.move-up-enter').length).toBe(0);
|
|
message.config({
|
|
transitionName: 'move-up',
|
|
});
|
|
});
|
|
});
|