2023-02-14 17:39:35 +08:00
|
|
|
import React from 'react';
|
2024-04-11 15:29:10 +08:00
|
|
|
import { Button } from 'antd';
|
2024-04-08 14:04:08 +08:00
|
|
|
|
2023-02-14 17:39:35 +08:00
|
|
|
import ConfigProvider from '..';
|
|
|
|
import { resetWarned } from '../../_util/warning';
|
2024-04-08 14:04:08 +08:00
|
|
|
import { render } from '../../../tests/utils';
|
2023-06-07 11:54:50 +08:00
|
|
|
import Form from '../../form';
|
2023-02-14 17:39:35 +08:00
|
|
|
|
|
|
|
describe('ConfigProvider.useConfig', () => {
|
|
|
|
it('useConfig - componentSize', () => {
|
|
|
|
let size;
|
|
|
|
|
|
|
|
const App: React.FC = () => {
|
|
|
|
const { componentSize } = ConfigProvider.useConfig();
|
|
|
|
size = componentSize;
|
|
|
|
|
|
|
|
return null;
|
|
|
|
};
|
|
|
|
|
|
|
|
render(
|
2023-06-07 11:54:50 +08:00
|
|
|
<ConfigProvider componentSize="small">
|
2023-02-14 17:39:35 +08:00
|
|
|
<App />
|
|
|
|
</ConfigProvider>,
|
|
|
|
);
|
|
|
|
|
|
|
|
expect(size).toBe('small');
|
|
|
|
});
|
|
|
|
|
|
|
|
it('useConfig - componentDisabled', () => {
|
|
|
|
let disabled;
|
|
|
|
const App: React.FC = () => {
|
|
|
|
const { componentDisabled } = ConfigProvider.useConfig();
|
|
|
|
disabled = componentDisabled;
|
|
|
|
return null;
|
|
|
|
};
|
|
|
|
|
|
|
|
render(
|
|
|
|
<Form disabled>
|
|
|
|
<App />
|
|
|
|
</Form>,
|
|
|
|
);
|
|
|
|
|
|
|
|
expect(disabled).toBe(true);
|
|
|
|
});
|
|
|
|
|
|
|
|
it('deprecated SizeContext', () => {
|
|
|
|
resetWarned();
|
|
|
|
|
|
|
|
const App: React.FC = () => {
|
|
|
|
const { SizeContext } = ConfigProvider;
|
|
|
|
const ctx = React.useContext(SizeContext);
|
|
|
|
|
|
|
|
return <div>{ctx}</div>;
|
|
|
|
};
|
|
|
|
|
2023-06-07 21:59:21 +08:00
|
|
|
const errSpy = jest.spyOn(console, 'error').mockImplementation(() => {});
|
2023-02-14 17:39:35 +08:00
|
|
|
|
|
|
|
render(<App />);
|
|
|
|
|
|
|
|
expect(errSpy).toHaveBeenCalledWith(
|
|
|
|
'Warning: [antd: ConfigProvider] ConfigProvider.SizeContext is deprecated. Please use `ConfigProvider.useConfig().componentSize` instead.',
|
|
|
|
);
|
|
|
|
errSpy.mockRestore();
|
|
|
|
});
|
2024-04-11 15:29:10 +08:00
|
|
|
|
|
|
|
it('deprecated autoInsertSpaceInButton', () => {
|
|
|
|
resetWarned();
|
|
|
|
const errSpy = jest.spyOn(console, 'error').mockImplementation(() => {});
|
|
|
|
render(
|
|
|
|
<ConfigProvider autoInsertSpaceInButton={false}>
|
|
|
|
<Button>测试</Button>
|
|
|
|
</ConfigProvider>,
|
|
|
|
);
|
|
|
|
expect(errSpy).toHaveBeenCalledWith(
|
|
|
|
'Warning: [antd: ConfigProvider] `autoInsertSpaceInButton` is deprecated. Please use `{ button: { autoInsertSpace: boolean }}` instead.',
|
|
|
|
);
|
|
|
|
errSpy.mockRestore();
|
|
|
|
});
|
2023-02-14 17:39:35 +08:00
|
|
|
});
|