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 = {
|
|
|
|
0: { radiusBase: 0, radiusLG: 0, radiusSM: 0, radiusXS: 0, radiusOuter: 0 },
|
|
|
|
2: { radiusBase: 2, radiusLG: 2, radiusSM: 2, radiusXS: 1, radiusOuter: 2 },
|
|
|
|
4: { radiusBase: 4, radiusLG: 4, radiusSM: 4, radiusXS: 1, radiusOuter: 4 },
|
|
|
|
5: { radiusBase: 5, radiusLG: 6, radiusSM: 4, radiusXS: 1, radiusOuter: 4 },
|
|
|
|
6: { radiusBase: 6, radiusLG: 8, radiusSM: 4, radiusXS: 2, radiusOuter: 4 },
|
|
|
|
7: { radiusBase: 7, radiusLG: 9, radiusSM: 5, radiusXS: 2, radiusOuter: 4 },
|
|
|
|
8: { radiusBase: 8, radiusLG: 10, radiusSM: 6, radiusXS: 2, radiusOuter: 6 },
|
|
|
|
10: { radiusBase: 10, radiusLG: 12, radiusSM: 6, radiusXS: 2, radiusOuter: 6 },
|
|
|
|
12: { radiusBase: 12, radiusLG: 14, radiusSM: 6, radiusXS: 2, radiusOuter: 6 },
|
|
|
|
14: { radiusBase: 14, radiusLG: 16, radiusSM: 7, radiusXS: 2, radiusOuter: 6 },
|
|
|
|
16: { radiusBase: 16, radiusLG: 16, radiusSM: 8, radiusXS: 2, radiusOuter: 6 },
|
|
|
|
20: { radiusBase: 20, radiusLG: 20, radiusSM: 10, radiusXS: 2, radiusOuter: 6 },
|
|
|
|
};
|
|
|
|
|
|
|
|
Object.entries(radiusGroup).forEach(([base, result]) => {
|
|
|
|
it(`base ${base}`, () => {
|
|
|
|
expect(genRadius(Number(base))).toMatchObject(result);
|
|
|
|
});
|
|
|
|
});
|
|
|
|
});
|
2022-06-28 15:38:30 +08:00
|
|
|
});
|