mirror of
https://github.com/ant-design/ant-design.git
synced 2024-12-23 23:18:36 +08:00
6848b23169
* fix: global icon style * chore: code clean * feat: icon style in CP * chore: code clean * chore: code clean * chore: support ss * feat: wrapSSR only if iconPrefixCls does not equal parent * chore: code clean * chore: fix lint * chore: fix lint * chore: test * chore: wrap children * chore: code clean * chore: fix lint
95 lines
2.3 KiB
TypeScript
95 lines
2.3 KiB
TypeScript
import * as React from 'react';
|
|
import { SmileOutlined } from '@ant-design/icons';
|
|
import ConfigProvider from '..';
|
|
import Button from '../../button';
|
|
import Divider from '../../divider';
|
|
import { render } from '../../../tests/utils';
|
|
|
|
describe('ConfigProvider.DynamicTheme', () => {
|
|
beforeEach(() => {
|
|
Array.from(document.querySelectorAll('style')).forEach((style) => {
|
|
style.parentNode?.removeChild(style);
|
|
});
|
|
});
|
|
|
|
it('customize primary color', () => {
|
|
render(
|
|
<ConfigProvider
|
|
theme={{
|
|
token: {
|
|
colorPrimary: '#f00000',
|
|
},
|
|
}}
|
|
>
|
|
<Button />
|
|
</ConfigProvider>,
|
|
);
|
|
|
|
const dynamicStyles = Array.from(document.querySelectorAll('style[data-css-hash]'));
|
|
|
|
expect(
|
|
dynamicStyles.some((style) => {
|
|
const { innerHTML } = style;
|
|
return (
|
|
innerHTML.includes('.ant-btn-primary') && innerHTML.includes('background-color:#f00000')
|
|
);
|
|
}),
|
|
).toBeTruthy();
|
|
});
|
|
|
|
it('not crash on null token', () => {
|
|
expect(() => {
|
|
render(
|
|
<ConfigProvider
|
|
theme={{
|
|
token: null as any,
|
|
}}
|
|
/>,
|
|
);
|
|
}).not.toThrow();
|
|
});
|
|
|
|
it('should support overriding aliasToken', () => {
|
|
render(
|
|
<ConfigProvider
|
|
theme={{
|
|
token: {
|
|
colorSplit: 'blue',
|
|
},
|
|
}}
|
|
>
|
|
<Divider />
|
|
</ConfigProvider>,
|
|
);
|
|
|
|
const dynamicStyles = Array.from(document.querySelectorAll('style[data-css-hash]'));
|
|
|
|
expect(
|
|
dynamicStyles.some((style) => {
|
|
const { innerHTML } = style;
|
|
return (
|
|
innerHTML.includes('.ant-divider') && innerHTML.includes('border-block-start:0 blue')
|
|
);
|
|
}),
|
|
).toBeTruthy();
|
|
});
|
|
|
|
it('should support iconPrefixCls', () => {
|
|
const { container } = render(
|
|
<ConfigProvider iconPrefixCls="test-icon">
|
|
<SmileOutlined />
|
|
</ConfigProvider>,
|
|
);
|
|
|
|
expect(container.querySelector('.test-icon')).toBeTruthy();
|
|
|
|
const dynamicStyles = Array.from(document.querySelectorAll('style[data-css-hash]'));
|
|
expect(
|
|
dynamicStyles.some((style) => {
|
|
const { innerHTML } = style;
|
|
return innerHTML.includes('.test-icon');
|
|
}),
|
|
).toBeTruthy();
|
|
});
|
|
});
|