2023-06-19 19:30:16 +08:00
|
|
|
import React from 'react';
|
|
|
|
import ConfigProvider from '..';
|
|
|
|
import { render } from '../../../tests/utils';
|
|
|
|
import Divider from '../../divider';
|
2023-06-25 14:46:13 +08:00
|
|
|
import Image from '../../image';
|
2023-06-25 16:20:39 +08:00
|
|
|
import Result from '../../result';
|
2023-06-25 09:32:53 +08:00
|
|
|
import Segmented from '../../segmented';
|
2023-06-19 19:30:16 +08:00
|
|
|
import Space from '../../space';
|
2023-06-20 19:34:45 +08:00
|
|
|
import Spin from '../../spin';
|
2023-06-25 11:42:31 +08:00
|
|
|
import Steps from '../../steps';
|
2023-06-20 14:35:05 +08:00
|
|
|
import Typography from '../../typography';
|
2023-06-19 19:30:16 +08:00
|
|
|
|
|
|
|
describe('ConfigProvider support style and className props', () => {
|
|
|
|
it('Should Space classNames works', () => {
|
|
|
|
const { container } = render(
|
|
|
|
<ConfigProvider
|
|
|
|
space={{
|
|
|
|
classNames: {
|
|
|
|
item: 'test-classNames',
|
|
|
|
},
|
|
|
|
}}
|
|
|
|
>
|
|
|
|
<Space>
|
|
|
|
<span>Text1</span>
|
|
|
|
<span>Text2</span>
|
|
|
|
</Space>
|
|
|
|
</ConfigProvider>,
|
|
|
|
);
|
2023-06-20 14:35:05 +08:00
|
|
|
expect(container.querySelector('.ant-space-item')).toHaveClass('test-classNames');
|
2023-06-19 19:30:16 +08:00
|
|
|
});
|
|
|
|
|
|
|
|
it('Should Space className works', () => {
|
|
|
|
const { container } = render(
|
|
|
|
<ConfigProvider
|
|
|
|
space={{
|
|
|
|
className: 'test-classNames',
|
|
|
|
}}
|
|
|
|
>
|
|
|
|
<Space>
|
|
|
|
<span>Text1</span>
|
|
|
|
<span>Text2</span>
|
|
|
|
</Space>
|
|
|
|
</ConfigProvider>,
|
|
|
|
);
|
2023-06-20 14:35:05 +08:00
|
|
|
expect(container.querySelector('.ant-space')).toHaveClass('test-classNames');
|
2023-06-19 19:30:16 +08:00
|
|
|
});
|
|
|
|
|
|
|
|
it('Should Space styles works', () => {
|
|
|
|
const { container } = render(
|
|
|
|
<ConfigProvider
|
|
|
|
space={{
|
|
|
|
styles: {
|
|
|
|
item: {
|
|
|
|
color: 'red',
|
|
|
|
},
|
|
|
|
},
|
|
|
|
}}
|
|
|
|
>
|
|
|
|
<Space>
|
|
|
|
<span>Text1</span>
|
|
|
|
<span>Text2</span>
|
|
|
|
</Space>
|
|
|
|
</ConfigProvider>,
|
|
|
|
);
|
2023-06-20 14:35:05 +08:00
|
|
|
expect(container.querySelector('.ant-space-item')).toHaveStyle(
|
2023-06-19 19:30:16 +08:00
|
|
|
'margin-right: 8px; color: red;',
|
|
|
|
);
|
|
|
|
});
|
|
|
|
|
|
|
|
it('Should Space style works', () => {
|
|
|
|
const { container } = render(
|
|
|
|
<ConfigProvider
|
|
|
|
space={{
|
|
|
|
style: {
|
|
|
|
color: 'red',
|
|
|
|
},
|
|
|
|
}}
|
|
|
|
>
|
|
|
|
<Space>
|
|
|
|
<span>Text1</span>
|
|
|
|
<span>Text2</span>
|
|
|
|
</Space>
|
|
|
|
</ConfigProvider>,
|
|
|
|
);
|
2023-06-20 14:35:05 +08:00
|
|
|
expect(container.querySelector('.ant-space')).toHaveStyle('color: red;');
|
2023-06-19 19:30:16 +08:00
|
|
|
});
|
|
|
|
|
|
|
|
it('Should Divider className works', () => {
|
|
|
|
const { container } = render(
|
|
|
|
<ConfigProvider
|
|
|
|
divider={{
|
|
|
|
className: 'config-provider-className',
|
|
|
|
}}
|
|
|
|
>
|
|
|
|
<Divider />
|
|
|
|
</ConfigProvider>,
|
|
|
|
);
|
|
|
|
expect(container.querySelector('.ant-divider')).toHaveClass('config-provider-className');
|
|
|
|
});
|
|
|
|
|
|
|
|
it('Should Divider style works', () => {
|
|
|
|
const { container } = render(
|
|
|
|
<ConfigProvider
|
|
|
|
divider={{
|
|
|
|
style: {
|
|
|
|
color: 'red',
|
|
|
|
height: 80,
|
|
|
|
},
|
|
|
|
}}
|
|
|
|
>
|
|
|
|
<Divider />
|
|
|
|
</ConfigProvider>,
|
|
|
|
);
|
|
|
|
expect(container.querySelector('.ant-divider'))?.toHaveStyle({ color: 'red', height: '80px' });
|
|
|
|
});
|
2023-06-20 14:35:05 +08:00
|
|
|
|
|
|
|
it('Should Typography className & style works', () => {
|
|
|
|
const { container } = render(
|
|
|
|
<ConfigProvider
|
|
|
|
typography={{ className: 'cp-typography', style: { backgroundColor: 'red' } }}
|
|
|
|
>
|
|
|
|
<Typography>test</Typography>
|
|
|
|
</ConfigProvider>,
|
|
|
|
);
|
|
|
|
const element = container.querySelector<HTMLElement>('.ant-typography');
|
|
|
|
expect(element).toHaveClass('cp-typography');
|
|
|
|
expect(element).toHaveStyle({ backgroundColor: 'red' });
|
|
|
|
});
|
2023-06-20 19:34:45 +08:00
|
|
|
|
|
|
|
it('Should Spin className & style works', () => {
|
|
|
|
const { container } = render(
|
|
|
|
<ConfigProvider
|
|
|
|
spin={{ className: 'config-provider-spin', style: { backgroundColor: 'red' } }}
|
|
|
|
>
|
|
|
|
<Spin />
|
|
|
|
</ConfigProvider>,
|
|
|
|
);
|
|
|
|
const element = container.querySelector<HTMLDivElement>('.ant-spin');
|
|
|
|
expect(element).toHaveClass('config-provider-spin');
|
|
|
|
expect(element).toHaveStyle({ backgroundColor: 'red' });
|
|
|
|
});
|
2023-06-25 09:32:53 +08:00
|
|
|
|
|
|
|
it('Should Segmented className & style works', () => {
|
|
|
|
const { container } = render(
|
|
|
|
<ConfigProvider
|
|
|
|
segmented={{ className: 'config-provider-segmented', style: { backgroundColor: 'red' } }}
|
|
|
|
>
|
|
|
|
<Segmented options={['Daily', 'Weekly', 'Monthly', 'Quarterly', 'Yearly']} />
|
|
|
|
</ConfigProvider>,
|
|
|
|
);
|
|
|
|
const element = container.querySelector<HTMLDivElement>('.ant-segmented');
|
|
|
|
expect(element).toHaveClass('config-provider-segmented');
|
|
|
|
expect(element).toHaveStyle({ backgroundColor: 'red' });
|
|
|
|
});
|
2023-06-25 11:42:31 +08:00
|
|
|
|
|
|
|
it('Should Steps className & style works', () => {
|
|
|
|
const { container } = render(
|
|
|
|
<ConfigProvider
|
|
|
|
steps={{ className: 'config-provider-steps', style: { backgroundColor: 'red' } }}
|
|
|
|
>
|
|
|
|
<Steps items={[{ title: 'title', description: 'description' }]} />
|
|
|
|
</ConfigProvider>,
|
|
|
|
);
|
|
|
|
const element = container.querySelector<HTMLDivElement>('.ant-steps');
|
|
|
|
expect(element).toHaveClass('config-provider-steps');
|
|
|
|
expect(element).toHaveStyle({ backgroundColor: 'red' });
|
|
|
|
});
|
2023-06-25 14:46:13 +08:00
|
|
|
|
|
|
|
it('Should Image className & style works', () => {
|
|
|
|
const { container } = render(
|
|
|
|
<ConfigProvider
|
|
|
|
image={{ className: 'config-provider-image', style: { backgroundColor: 'red' } }}
|
|
|
|
>
|
|
|
|
<Image src="https://zos.alipayobjects.com/rmsportal/jkjgkEfvpUPVyRjUImniVslZfWPnJuuZ.png" />
|
|
|
|
</ConfigProvider>,
|
|
|
|
);
|
|
|
|
const element = container
|
|
|
|
?.querySelector<HTMLDivElement>('.ant-image')
|
|
|
|
?.querySelector<HTMLImageElement>('img');
|
|
|
|
expect(element).toHaveClass('config-provider-image');
|
|
|
|
expect(element).toHaveStyle({ backgroundColor: 'red' });
|
|
|
|
});
|
2023-06-25 16:20:39 +08:00
|
|
|
|
|
|
|
it('Should Result className & style works', () => {
|
|
|
|
const { container } = render(
|
|
|
|
<ConfigProvider result={{ className: 'cp-result', style: { backgroundColor: 'red' } }}>
|
|
|
|
<Result />
|
|
|
|
</ConfigProvider>,
|
|
|
|
);
|
|
|
|
const element = container.querySelector<HTMLDivElement>('.ant-result');
|
|
|
|
expect(element).toHaveClass('cp-result');
|
|
|
|
expect(element).toHaveStyle({ backgroundColor: 'red' });
|
|
|
|
});
|
2023-06-19 19:30:16 +08:00
|
|
|
});
|