2018-12-05 19:12:18 +08:00
|
|
|
import React 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>,
|
|
|
|
);
|
|
|
|
|
|
|
|
expect(wrapper.find('button').props().className).toEqual('bamboo-btn');
|
|
|
|
});
|
2020-04-22 10:38:43 +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>,
|
|
|
|
);
|
|
|
|
|
|
|
|
expect(wrapper).toMatchRenderedSnapshot();
|
|
|
|
});
|
2018-12-05 19:12:18 +08:00
|
|
|
});
|