2022-06-28 15:38:30 +08:00
|
|
|
import { Theme } from '@ant-design/cssinjs';
|
|
|
|
import * as React from 'react';
|
2022-09-01 20:09:32 +08:00
|
|
|
import genRadius from '../themes/shared/genRadius';
|
2022-06-28 15:38:30 +08:00
|
|
|
import { render, renderHook } from '../../../tests/utils';
|
|
|
|
import ConfigProvider from '../../config-provider';
|
2022-06-29 20:34:00 +08:00
|
|
|
import theme from '../export';
|
|
|
|
|
|
|
|
const { useToken } = theme;
|
2022-06-28 15:38:30 +08:00
|
|
|
|
|
|
|
describe('Theme', () => {
|
|
|
|
it('useTheme', () => {
|
2022-08-08 19:08:43 +08:00
|
|
|
const { result } = renderHook(() => useToken());
|
2022-06-28 15:38:30 +08:00
|
|
|
|
2022-08-08 19:08:43 +08:00
|
|
|
expect(result.current!.theme instanceof Theme).toBeTruthy();
|
|
|
|
expect(result.current!.hashId).toBeFalsy();
|
|
|
|
expect(result.current!.token).toEqual(
|
2022-06-28 15:38:30 +08:00
|
|
|
expect.objectContaining({
|
2022-08-26 16:05:16 +08:00
|
|
|
colorPrimary: '#1677ff',
|
2022-06-28 15:38:30 +08:00
|
|
|
}),
|
|
|
|
);
|
|
|
|
});
|
|
|
|
|
|
|
|
it('ConfigProvider with seed', () => {
|
|
|
|
const Demo = React.forwardRef((_, ref: any) => {
|
2022-06-29 20:34:00 +08:00
|
|
|
const themeObj = useToken();
|
2022-06-28 15:38:30 +08:00
|
|
|
ref.current = themeObj;
|
|
|
|
return null;
|
|
|
|
});
|
|
|
|
|
2022-06-29 20:34:00 +08:00
|
|
|
const themeRef = React.createRef<ReturnType<typeof useToken>>();
|
2022-06-28 15:38:30 +08:00
|
|
|
render(
|
|
|
|
<ConfigProvider
|
|
|
|
theme={{
|
|
|
|
token: {
|
2022-07-20 18:35:09 +08:00
|
|
|
colorPrimary: '#ff0000',
|
2022-06-28 15:38:30 +08:00
|
|
|
},
|
|
|
|
}}
|
|
|
|
>
|
|
|
|
<Demo ref={themeRef} />
|
|
|
|
</ConfigProvider>,
|
|
|
|
);
|
|
|
|
|
|
|
|
expect(themeRef.current!.token).toEqual(
|
|
|
|
expect.objectContaining({
|
2022-07-15 19:27:29 +08:00
|
|
|
colorPrimary: '#ff0000',
|
2022-06-28 15:38:30 +08:00
|
|
|
colorPrimaryHover: '#ff3029', // It's safe to modify if theme logic changed
|
|
|
|
}),
|
|
|
|
);
|
|
|
|
});
|
2022-09-01 20:09:32 +08:00
|
|
|
|
|
|
|
describe('radius should be computed as expected', () => {
|
|
|
|
const radiusGroup = {
|
2022-11-01 15:06:38 +08:00
|
|
|
0: {
|
|
|
|
borderRadius: 0,
|
|
|
|
borderRadiusLG: 0,
|
|
|
|
borderRadiusSM: 0,
|
|
|
|
borderRadiusXS: 0,
|
|
|
|
borderRadiusOuter: 0,
|
|
|
|
},
|
|
|
|
2: {
|
|
|
|
borderRadius: 2,
|
|
|
|
borderRadiusLG: 2,
|
|
|
|
borderRadiusSM: 2,
|
|
|
|
borderRadiusXS: 1,
|
|
|
|
borderRadiusOuter: 2,
|
|
|
|
},
|
|
|
|
4: {
|
|
|
|
borderRadius: 4,
|
|
|
|
borderRadiusLG: 4,
|
|
|
|
borderRadiusSM: 4,
|
|
|
|
borderRadiusXS: 1,
|
|
|
|
borderRadiusOuter: 4,
|
|
|
|
},
|
|
|
|
5: {
|
|
|
|
borderRadius: 5,
|
|
|
|
borderRadiusLG: 6,
|
|
|
|
borderRadiusSM: 4,
|
|
|
|
borderRadiusXS: 1,
|
|
|
|
borderRadiusOuter: 4,
|
|
|
|
},
|
|
|
|
6: {
|
|
|
|
borderRadius: 6,
|
|
|
|
borderRadiusLG: 8,
|
|
|
|
borderRadiusSM: 4,
|
|
|
|
borderRadiusXS: 2,
|
|
|
|
borderRadiusOuter: 4,
|
|
|
|
},
|
|
|
|
7: {
|
|
|
|
borderRadius: 7,
|
|
|
|
borderRadiusLG: 9,
|
|
|
|
borderRadiusSM: 5,
|
|
|
|
borderRadiusXS: 2,
|
|
|
|
borderRadiusOuter: 4,
|
|
|
|
},
|
|
|
|
8: {
|
|
|
|
borderRadius: 8,
|
|
|
|
borderRadiusLG: 10,
|
|
|
|
borderRadiusSM: 6,
|
|
|
|
borderRadiusXS: 2,
|
|
|
|
borderRadiusOuter: 6,
|
|
|
|
},
|
|
|
|
10: {
|
|
|
|
borderRadius: 10,
|
|
|
|
borderRadiusLG: 12,
|
|
|
|
borderRadiusSM: 6,
|
|
|
|
borderRadiusXS: 2,
|
|
|
|
borderRadiusOuter: 6,
|
|
|
|
},
|
|
|
|
12: {
|
|
|
|
borderRadius: 12,
|
|
|
|
borderRadiusLG: 14,
|
|
|
|
borderRadiusSM: 6,
|
|
|
|
borderRadiusXS: 2,
|
|
|
|
borderRadiusOuter: 6,
|
|
|
|
},
|
|
|
|
14: {
|
|
|
|
borderRadius: 14,
|
|
|
|
borderRadiusLG: 16,
|
|
|
|
borderRadiusSM: 7,
|
|
|
|
borderRadiusXS: 2,
|
|
|
|
borderRadiusOuter: 6,
|
|
|
|
},
|
|
|
|
16: {
|
|
|
|
borderRadius: 16,
|
|
|
|
borderRadiusLG: 16,
|
|
|
|
borderRadiusSM: 8,
|
|
|
|
borderRadiusXS: 2,
|
|
|
|
borderRadiusOuter: 6,
|
|
|
|
},
|
|
|
|
20: {
|
|
|
|
borderRadius: 16,
|
|
|
|
borderRadiusLG: 16,
|
|
|
|
borderRadiusSM: 8,
|
|
|
|
borderRadiusXS: 2,
|
|
|
|
borderRadiusOuter: 6,
|
|
|
|
},
|
2022-09-01 20:09:32 +08:00
|
|
|
};
|
|
|
|
|
|
|
|
Object.entries(radiusGroup).forEach(([base, result]) => {
|
|
|
|
it(`base ${base}`, () => {
|
|
|
|
expect(genRadius(Number(base))).toMatchObject(result);
|
|
|
|
});
|
|
|
|
});
|
|
|
|
});
|
2022-06-28 15:38:30 +08:00
|
|
|
});
|