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';
|
2022-05-16 16:34:42 +08:00
|
|
|
import { render, fireEvent } from '../../../tests/utils';
|
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>
|
|
|
|
);
|
|
|
|
};
|
|
|
|
|
2022-04-17 22:36:36 +08:00
|
|
|
const { container } = render(<DynamicPrefixCls />);
|
2021-05-24 11:46:12 +08:00
|
|
|
|
2022-04-17 22:36:36 +08:00
|
|
|
expect(container.querySelector('button.bamboo-btn')).toBeTruthy();
|
|
|
|
fireEvent.click(container.querySelector('.toggle-button'));
|
|
|
|
expect(container.querySelector('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', () => {
|
2022-05-16 16:34:42 +08:00
|
|
|
let rendered = false;
|
|
|
|
let cacheRenderEmpty;
|
|
|
|
|
2020-06-29 14:52:46 +08:00
|
|
|
const App = () => {
|
|
|
|
const { renderEmpty } = React.useContext(ConfigContext);
|
2022-05-16 16:34:42 +08:00
|
|
|
rendered = true;
|
|
|
|
cacheRenderEmpty = renderEmpty;
|
|
|
|
return null;
|
2020-07-01 10:11:39 +08:00
|
|
|
};
|
2022-05-16 16:34:42 +08:00
|
|
|
|
|
|
|
render(
|
2020-06-29 14:52:46 +08:00
|
|
|
<ConfigProvider>
|
|
|
|
<App />
|
|
|
|
</ConfigProvider>,
|
|
|
|
);
|
|
|
|
|
2022-05-16 16:34:42 +08:00
|
|
|
expect(rendered).toBeTruthy();
|
|
|
|
expect(cacheRenderEmpty).toBeFalsy();
|
2020-06-29 14:52:46 +08:00
|
|
|
});
|
2018-12-05 19:12:18 +08:00
|
|
|
});
|