import { SmileOutlined } from '@ant-design/icons';
import React, { useState } from 'react';
import type { ConfigConsumerProps } from '..';
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';
import Select from '../../select';
describe('ConfigProvider', () => {
mountTest(() => (
));
it('autoInsertSpaceInButton', () => {
const text = '确定';
const { container } = render(
,
);
expect(container.querySelector('span')?.innerHTML).toBe(text);
});
it('renderEmpty', () => {
const text = 'empty placeholder';
const { container } = render(
{text}
}>
,
);
expect(container.querySelector('.ant-table-placeholder')?.querySelector('div')?.innerHTML).toBe(
text,
);
});
it('nest prefixCls', () => {
const { container } = render(
,
);
expect(container.querySelector('button.bamboo-btn')).toBeTruthy();
});
it('dynamic prefixCls', () => {
const DynamicPrefixCls: React.FC = () => {
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 { container } = render(
,
);
expect(container.querySelector('[role="img"]')).toHaveClass('bamboo');
expect(container.querySelector('[role="img"]')).toHaveClass('bamboo-smile');
});
it('input autoComplete', () => {
const { container } = render(
,
);
expect(container.querySelector('input')?.autocomplete).toEqual('off');
});
it('select showSearch', () => {
const { container } = render(
,
);
expect(container.querySelectorAll('.ant-select-show-search').length).toBe(1);
});
it('render empty', () => {
let rendered = false;
let cacheRenderEmpty;
const App: React.FC = () => {
const { renderEmpty } = React.useContext(ConfigContext);
rendered = true;
cacheRenderEmpty = renderEmpty;
return null;
};
render(
,
);
expect(rendered).toBeTruthy();
expect(cacheRenderEmpty).toBeFalsy();
});
});