2022-06-28 15:38:30 +08:00
|
|
|
import { Theme } from '@ant-design/cssinjs';
|
|
|
|
import * as React from 'react';
|
|
|
|
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-06-29 20:34:00 +08:00
|
|
|
const result = renderHook(() => useToken());
|
2022-06-28 15:38:30 +08:00
|
|
|
|
|
|
|
expect(result.current.theme instanceof Theme).toBeTruthy();
|
|
|
|
expect(result.current.hashId).toBeFalsy();
|
|
|
|
expect(result.current.token).toEqual(
|
|
|
|
expect.objectContaining({
|
|
|
|
colorPrimary: '#1890ff',
|
|
|
|
}),
|
|
|
|
);
|
|
|
|
});
|
|
|
|
|
|
|
|
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: {
|
|
|
|
colorPrimary: 'red',
|
|
|
|
},
|
|
|
|
}}
|
|
|
|
>
|
|
|
|
<Demo ref={themeRef} />
|
|
|
|
</ConfigProvider>,
|
|
|
|
);
|
|
|
|
|
|
|
|
expect(themeRef.current!.token).toEqual(
|
|
|
|
expect.objectContaining({
|
|
|
|
colorPrimary: 'red',
|
|
|
|
colorPrimaryHover: '#ff3029', // It's safe to modify if theme logic changed
|
|
|
|
}),
|
|
|
|
);
|
|
|
|
});
|
|
|
|
});
|