import { SmileOutlined } from '@ant-design/icons';
import { mount } from 'enzyme';
import React, { useState } from 'react';
import ConfigProvider, { ConfigContext } from '..';
import mountTest from '../../../tests/shared/mountTest';
import { fireEvent, render } from '../../../tests/utils';
import Button from '../../button';
import Input from '../../input';
import Table from '../../table';
describe('ConfigProvider', () => {
mountTest(() => (
));
it('Content Security Policy', () => {
const csp = { nonce: 'test-antd' };
const wrapper = mount(
,
);
expect(wrapper.find('InternalWave').instance().csp).toBe(csp);
});
it('autoInsertSpaceInButton', () => {
const wrapper = mount(
,
);
expect(wrapper.find('Button').text()).toBe('确定');
});
it('renderEmpty', () => {
const wrapper = mount(
empty placeholder
}>
,
);
expect(wrapper.text()).toContain('empty placeholder');
});
it('nest prefixCls', () => {
const wrapper = mount(
,
);
expect(wrapper.exists('button.bamboo-btn')).toBeTruthy();
});
it('dynamic prefixCls', () => {
const DynamicPrefixCls = () => {
const [prefixCls, setPrefixCls] = useState('bamboo');
return (
);
};
const { container } = render();
expect(container.querySelector('button.bamboo-btn')).toBeTruthy();
fireEvent.click(container.querySelector('.toggle-button'));
expect(container.querySelector('button.light-btn')).toBeTruthy();
});
it('iconPrefixCls', () => {
const wrapper = mount(
,
);
expect(wrapper.find('[role="img"]').hasClass('bamboo')).toBeTruthy();
expect(wrapper.find('[role="img"]').hasClass('bamboo-smile')).toBeTruthy();
});
it('input autoComplete', () => {
const wrapper = mount(
,
);
expect(wrapper.find('input').props().autoComplete).toEqual('off');
});
it('render empty', () => {
let rendered = false;
let cacheRenderEmpty;
const App = () => {
const { renderEmpty } = React.useContext(ConfigContext);
rendered = true;
cacheRenderEmpty = renderEmpty;
return null;
};
render(
,
);
expect(rendered).toBeTruthy();
expect(cacheRenderEmpty).toBeFalsy();
});
});