mirror of
https://gitee.com/ant-design/ant-design.git
synced 2024-12-02 20:19:44 +08:00
✅ add test case for message.config (#21556)
This commit is contained in:
parent
b53cf30fc0
commit
b35498aa73
84
components/message/__tests__/config.test.js
Normal file
84
components/message/__tests__/config.test.js
Normal file
@ -0,0 +1,84 @@
|
||||
import { sleep } from '../../../tests/utils';
|
||||
import message from '..';
|
||||
|
||||
describe('message.config', () => {
|
||||
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 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(document.querySelectorAll('.ant-message-notice').length).toBe(0);
|
||||
});
|
||||
|
||||
it('should be able to config duration', async () => {
|
||||
jest.useRealTimers();
|
||||
message.config({
|
||||
duration: 0.5,
|
||||
});
|
||||
message.info('last');
|
||||
await sleep(600);
|
||||
expect(document.querySelectorAll('.ant-message-notice').length).toBe(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',
|
||||
});
|
||||
});
|
||||
});
|
@ -1,7 +1,6 @@
|
||||
import React from 'react';
|
||||
import { mount } from 'enzyme';
|
||||
import { SmileOutlined } from '@ant-design/icons';
|
||||
|
||||
import message from '..';
|
||||
|
||||
describe('message', () => {
|
||||
@ -14,41 +13,6 @@ describe('message', () => {
|
||||
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 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(document.querySelectorAll('.ant-message-notice').length).toBe(0);
|
||||
});
|
||||
|
||||
it('should be able to hide manually', () => {
|
||||
const hide1 = message.info('whatever', 0);
|
||||
const hide2 = message.info('whatever', 0);
|
||||
@ -124,7 +88,7 @@ describe('message', () => {
|
||||
});
|
||||
|
||||
it('should have no icon', () => {
|
||||
message.open({ content: 'Message' });
|
||||
message.open({ content: 'Message', icon: <span /> });
|
||||
expect(document.querySelectorAll('.ant-message-notice .anticon').length).toBe(0);
|
||||
});
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user