2021-05-24 11:46:12 +08:00
|
|
|
import React, { useState } from 'react';
|
2019-01-10 11:47:11 +08:00
|
|
|
import { mount } from 'enzyme';
|
2021-01-19 17:33:05 +08:00
|
|
|
import { SmileOutlined } from '@ant-design/icons';
|
2020-06-29 14:52:46 +08:00
|
|
|
import ConfigProvider, { ConfigContext } from '..';
|
2018-12-05 19:12:18 +08:00
|
|
|
import Button from '../../button';
|
2020-02-14 19:02:53 +08:00
|
|
|
import Table from '../../table';
|
2020-04-22 10:38:43 +08:00
|
|
|
import Input from '../../input';
|
2019-08-26 22:53:20 +08:00
|
|
|
import mountTest from '../../../tests/shared/mountTest';
|
2018-12-05 19:12:18 +08:00
|
|
|
|
|
|
|
describe('ConfigProvider', () => {
|
2019-09-02 10:47:32 +08:00
|
|
|
mountTest(() => (
|
|
|
|
<ConfigProvider>
|
|
|
|
<div />
|
|
|
|
</ConfigProvider>
|
|
|
|
));
|
2019-08-26 22:53:20 +08:00
|
|
|
|
2019-01-10 11:47:11 +08:00
|
|
|
it('Content Security Policy', () => {
|
|
|
|
const csp = { nonce: 'test-antd' };
|
|
|
|
const wrapper = mount(
|
|
|
|
<ConfigProvider csp={csp}>
|
|
|
|
<Button />
|
|
|
|
</ConfigProvider>,
|
|
|
|
);
|
|
|
|
|
|
|
|
expect(wrapper.find('Wave').instance().csp).toBe(csp);
|
|
|
|
});
|
2018-12-05 19:12:18 +08:00
|
|
|
|
2019-01-10 11:47:11 +08:00
|
|
|
it('autoInsertSpaceInButton', () => {
|
|
|
|
const wrapper = mount(
|
|
|
|
<ConfigProvider autoInsertSpaceInButton={false}>
|
|
|
|
<Button>确定</Button>
|
|
|
|
</ConfigProvider>,
|
|
|
|
);
|
2018-12-05 19:12:18 +08:00
|
|
|
|
2019-01-10 11:47:11 +08:00
|
|
|
expect(wrapper.find('Button').text()).toBe('确定');
|
2018-12-05 19:12:18 +08:00
|
|
|
});
|
2020-02-14 19:02:53 +08:00
|
|
|
|
|
|
|
it('renderEmpty', () => {
|
|
|
|
const wrapper = mount(
|
|
|
|
<ConfigProvider renderEmpty={() => <div>empty placeholder</div>}>
|
|
|
|
<Table />
|
|
|
|
</ConfigProvider>,
|
|
|
|
);
|
|
|
|
|
|
|
|
expect(wrapper.text()).toContain('empty placeholder');
|
|
|
|
});
|
2020-04-21 11:16:33 +08:00
|
|
|
|
|
|
|
it('nest prefixCls', () => {
|
|
|
|
const wrapper = mount(
|
|
|
|
<ConfigProvider prefixCls="bamboo">
|
|
|
|
<ConfigProvider>
|
|
|
|
<Button />
|
|
|
|
</ConfigProvider>
|
|
|
|
</ConfigProvider>,
|
|
|
|
);
|
|
|
|
|
2022-02-11 15:02:59 +08:00
|
|
|
expect(wrapper.exists('button.bamboo-btn')).toBeTruthy();
|
2020-04-21 11:16:33 +08:00
|
|
|
});
|
2020-04-22 10:38:43 +08:00
|
|
|
|
2021-05-24 11:46:12 +08:00
|
|
|
it('dynamic prefixCls', () => {
|
|
|
|
const DynamicPrefixCls = () => {
|
|
|
|
const [prefixCls, setPrefixCls] = useState('bamboo');
|
|
|
|
return (
|
|
|
|
<div>
|
|
|
|
<Button onClick={() => setPrefixCls('light')} className="toggle-button">
|
|
|
|
toggle
|
|
|
|
</Button>
|
|
|
|
<ConfigProvider prefixCls={prefixCls}>
|
|
|
|
<ConfigProvider>
|
|
|
|
<Button />
|
|
|
|
</ConfigProvider>
|
|
|
|
</ConfigProvider>
|
|
|
|
</div>
|
|
|
|
);
|
|
|
|
};
|
|
|
|
|
|
|
|
const wrapper = mount(<DynamicPrefixCls />);
|
|
|
|
|
2022-02-11 15:02:59 +08:00
|
|
|
expect(wrapper.exists('button.bamboo-btn')).toBeTruthy();
|
2021-05-24 11:46:12 +08:00
|
|
|
wrapper.find('.toggle-button').first().simulate('click');
|
2022-02-11 15:02:59 +08:00
|
|
|
expect(wrapper.exists('button.light-btn')).toBeTruthy();
|
2021-05-24 11:46:12 +08:00
|
|
|
});
|
|
|
|
|
2021-01-19 17:33:05 +08:00
|
|
|
it('iconPrefixCls', () => {
|
|
|
|
const wrapper = mount(
|
|
|
|
<ConfigProvider iconPrefixCls="bamboo">
|
|
|
|
<SmileOutlined />
|
|
|
|
</ConfigProvider>,
|
|
|
|
);
|
|
|
|
|
|
|
|
expect(wrapper.find('[role="img"]').hasClass('bamboo')).toBeTruthy();
|
|
|
|
expect(wrapper.find('[role="img"]').hasClass('bamboo-smile')).toBeTruthy();
|
|
|
|
});
|
|
|
|
|
2020-04-22 10:38:43 +08:00
|
|
|
it('input autoComplete', () => {
|
|
|
|
const wrapper = mount(
|
|
|
|
<ConfigProvider input={{ autoComplete: 'off' }}>
|
|
|
|
<Input />
|
|
|
|
</ConfigProvider>,
|
|
|
|
);
|
|
|
|
|
|
|
|
expect(wrapper.find('input').props().autoComplete).toEqual('off');
|
|
|
|
});
|
2020-06-29 14:52:46 +08:00
|
|
|
|
|
|
|
it('render empty', () => {
|
|
|
|
const App = () => {
|
|
|
|
const { renderEmpty } = React.useContext(ConfigContext);
|
|
|
|
return renderEmpty();
|
2020-07-01 10:11:39 +08:00
|
|
|
};
|
2020-06-29 14:52:46 +08:00
|
|
|
const wrapper = mount(
|
|
|
|
<ConfigProvider>
|
|
|
|
<App />
|
|
|
|
</ConfigProvider>,
|
|
|
|
);
|
|
|
|
|
2021-12-04 17:06:36 +08:00
|
|
|
expect(wrapper.render()).toMatchSnapshot();
|
2020-06-29 14:52:46 +08:00
|
|
|
});
|
2018-12-05 19:12:18 +08:00
|
|
|
});
|