import dayjs from 'dayjs';
import customParseFormat from 'dayjs/plugin/customParseFormat';
import React from 'react';
import ConfigProvider from '..';
import Alert from '../../alert';
import Anchor from '../../anchor';
import AutoComplete from '../../auto-complete';
import Avatar from '../../avatar';
import BackTop from '../../back-top';
import Badge from '../../badge';
import Breadcrumb from '../../breadcrumb';
import Button from '../../button';
import Calendar from '../../calendar';
import Card from '../../card';
import Carousel from '../../carousel';
import Cascader from '../../cascader';
import Checkbox from '../../checkbox';
import Collapse from '../../collapse';
import DatePicker from '../../date-picker';
import Divider from '../../divider';
import Drawer from '../../drawer';
import Dropdown from '../../dropdown';
import Empty from '../../empty';
import Form from '../../form';
import { Col, Row } from '../../grid';
import Input from '../../input';
import InputNumber from '../../input-number';
import Layout from '../../layout';
import List from '../../list';
import Menu from '../../menu';
import Modal from '../../modal';
import Pagination from '../../pagination';
import Popconfirm from '../../popconfirm';
import Popover from '../../popover';
import Progress from '../../progress';
import Radio from '../../radio';
import Rate from '../../rate';
import Select from '../../select';
import Skeleton from '../../skeleton';
import type { SliderTooltipProps } from '../../slider';
import Slider from '../../slider';
// eslint-disable-next-line import/no-named-as-default
import Spin from '../../spin';
import Statistic from '../../statistic';
import Steps from '../../steps';
import Switch from '../../switch';
import type { ColumnsType } from '../../table';
import Table from '../../table';
import Tabs from '../../tabs';
import Tag from '../../tag';
import TimePicker from '../../time-picker';
import Timeline from '../../timeline';
import Tooltip from '../../tooltip';
import Transfer from '../../transfer';
import Tree from '../../tree';
import TreeSelect from '../../tree-select';
import Upload from '../../upload';
import { render } from '../../../tests/utils';
dayjs.extend(customParseFormat);
jest.mock('rc-util/lib/Portal');
describe('ConfigProvider', () => {
describe('components', () => {
function testPair(name: string, renderComponent: (props?: any) => React.ReactElement): void {
const isArray = ['Menu', 'TimePicker', 'Tooltip'].includes(name);
describe(`${name}`, () => {
// normal
it('normal', () => {
const { container } = render(renderComponent({}));
expect(isArray ? container.children : container.firstChild).toMatchSnapshot();
});
// prefixCls
it('prefixCls', () => {
const { container } = render(renderComponent({ prefixCls: `prefix-${name}` }));
expect(isArray ? container.children : container.firstChild).toMatchSnapshot();
});
// configProvider
it('configProvider', () => {
const { container } = render(
{renderComponent({})}
,
);
expect(isArray ? container.children : container.firstChild).toMatchSnapshot();
});
it('configProvider componentSize large', () => {
const { container } = render(
{renderComponent({})}
,
);
expect(isArray ? container.children : container.firstChild).toMatchSnapshot();
});
it('configProvider componentSize middle', () => {
const { container } = render(
{renderComponent({})}
,
);
expect(isArray ? container.children : container.firstChild).toMatchSnapshot();
});
it('configProvider componentDisabled', () => {
const { container } = render(
{renderComponent({})}
,
);
expect(isArray ? container.children : container.firstChild).toMatchSnapshot();
});
it('configProvider virtual and dropdownMatchSelectWidth', () => {
const { container } = render(
{renderComponent({})}
,
);
expect(isArray ? container.children : container.firstChild).toMatchSnapshot();
});
});
}
// Alert
testPair('Alert', (props) => (
));
// Anchor
testPair('Anchor', (props) => (
));
// AutoComplete
testPair('AutoComplete', (props) => );
// Avatar
testPair('Avatar', (props) => );
// BackTop
testPair('BackTop', (props) => );
// Badge
testPair('Badge', (props) => {
const newProps = { ...props };
// Hook for additional `scrollNumberPrefixCls` prop
if (props.prefixCls) {
newProps.scrollNumberPrefixCls = 'prefix-scroll-number';
}
return (
);
});
// Breadcrumb
testPair('Breadcrumb', (props) => (
Bamboo
Light
));
// Button
testPair('Button', (props) => (
));
// Calendar
testPair('Calendar', (props) => (
));
// Card
testPair('Card', (props) => (
));
// Carousel
testPair('Carousel', (props) => (
Bamboo
Light
));
// Cascader
testPair('Cascader', (props) => );
// Checkbox
testPair('Checkbox', (props) => (
Bamboo
));
// Collapse
testPair('Collapse', (props) => (
Light
));
// DatePicker
describe('DatePicker', () => {
testPair('DatePicker', (props) => (
));
// RangePicker
testPair('RangePicker', (props) => (
));
// MonthPicker
testPair('MonthPicker', (props) => (
));
// WeekPicker
testPair('WeekPicker', (props) => (
));
});
// Empty
testPair('Empty', (props) => );
// Divider
testPair('Divider', (props) => );
// Drawer
testPair('Drawer', (props) => );
// Dropdown
testPair('Dropdown', (props) => Light);
// Form
testPair('Form', (props) => (
));
// Grid
testPair('Grid', (props) => {
const rowProps: { prefixCls?: string } = {};
const colProps: { prefixCls?: string } = {};
if (props.prefixCls) {
rowProps.prefixCls = 'prefix-row';
colProps.prefixCls = 'prefix-col';
}
return (
);
});
// Input
testPair('Input', (props) => (
));
// InputNumber
testPair('InputNumber', (props) => );
// Layout
testPair('Layout', (props) => {
const siderProps: { prefixCls?: string } = {};
const headerProps: { prefixCls?: string } = {};
const contentProps: { prefixCls?: string } = {};
const footerProps: { prefixCls?: string } = {};
if (props.prefixCls) {
siderProps.prefixCls = 'prefix-sider';
headerProps.prefixCls = 'prefix-header';
contentProps.prefixCls = 'prefix-content';
footerProps.prefixCls = 'prefix-footer';
}
return (
);
});
// List
testPair('List', (props) => (
(
}
title="Ant Design"
description="Ant Design, a design language for background applications, is refined by Ant UED Team"
/>
)}
/>
));
// Menu
testPair('Menu', (props) => (
));
// Modal
testPair('Modal', (props) => (
Bamboo is Little Light
));
// Pagination
testPair('Pagination', (props) => (
));
// Popconfirm
testPair('Popconfirm', (props) => (
));
// Popover
testPair('Popover', (props) => (
));
// Progress
testPair('Progress', (props) => );
// Radio
testPair('Radio', (props) => (
Bamboo
Light
));
// Rate
testPair('Rate', (props) => );
// Select
testPair('Select', (props) => (
));
// Skeleton
testPair('Skeleton', (props) => );
// Slider
testPair('Slider', (props) => {
const myProps = { ...props };
const tooltip: SliderTooltipProps = {
open: true,
};
if (myProps.prefixCls) {
tooltip.prefixCls = `${myProps.prefixCls}-tooltip`;
}
return ;
});
// Spin
testPair('Spin', (props) => );
// Statistic
testPair('Statistic', (props) => );
// Steps
testPair('Steps', (props) => {
const myProps = { ...props };
if (props.prefixCls) {
myProps.iconPrefix = 'prefixIcon';
}
return (
);
});
// Switch
testPair('Switch', (props) => );
// Table
testPair('Table', (props) => {
const columns: ColumnsType = [
{
title: 'Name',
dataIndex: 'name',
filters: [
{ text: 'Joe', value: 'Joe' },
{
text: 'Submenu',
value: 'Submenu',
children: [{ text: 'Green', value: 'Green' }],
},
],
filterDropdownOpen: true,
onFilter: (value, record) => record.name.indexOf(value) === 0,
sorter: (a, b) => a.name.length - b.name.length,
},
];
const myProps = { ...props };
if (props.prefixCls) {
myProps.dropdownPrefixCls = 'prefix-dropdown';
}
return ;
});
// Tabs
testPair('Tabs', (props) => (
));
// Tags
testPair('Tags', (props) => (
Bamboo
Light
));
// TimePicker
testPair('TimePicker', (props) => (
));
// Timeline
testPair('Timeline', (props) => (
Bamboo
));
// Tooltip
testPair('Tooltip', (props) => (
Light
));
// Transfer
testPair('Transfer', (props) => );
// Tree
testPair('Tree', (props) => (
));
// TreeSelect
testPair('TreeSelect', (props) => (
));
// Upload
testPair('Upload', (props) => (
));
});
});