mirror of
https://github.com/ant-design/ant-design.git
synced 2024-11-28 21:19:37 +08:00
fix: 修复切换页面 changeConfirmLocale 被清空问题 (#29570)
* fix: 修复切换页面 changeConfirmLocale 被清空问题 * feat: 恢复 constructor * feat: test
This commit is contained in:
parent
79224cab83
commit
e7938cad1c
73
components/locale-provider/__tests__/config.test.js
Normal file
73
components/locale-provider/__tests__/config.test.js
Normal file
@ -0,0 +1,73 @@
|
||||
import React from 'react';
|
||||
|
||||
import { mount } from 'enzyme';
|
||||
|
||||
import ConfigProvider from '../../config-provider';
|
||||
|
||||
import { Modal } from '../..';
|
||||
|
||||
import zhCN from '../zh_CN';
|
||||
|
||||
class Demo extends React.Component {
|
||||
static defaultProps = {};
|
||||
|
||||
constructor(props) {
|
||||
super(props);
|
||||
console.log('constructor', props.type);
|
||||
}
|
||||
|
||||
componentDidMount() {
|
||||
if (this.props.type === 'dashboard') {
|
||||
Modal.confirm({ title: 'Hello World!' });
|
||||
}
|
||||
console.log('componentDidMount', this.props.type);
|
||||
}
|
||||
|
||||
componentWillUnmount() {
|
||||
console.log('componentWillUnmount', this.props.type);
|
||||
}
|
||||
|
||||
render() {
|
||||
return <div>{this.props.type}</div>;
|
||||
}
|
||||
}
|
||||
|
||||
describe('Locale Provider demo', () => {
|
||||
it('change type', () => {
|
||||
jest.useFakeTimers();
|
||||
|
||||
const BasicExample = () => {
|
||||
const [type, setType] = React.useState('');
|
||||
return (
|
||||
<div>
|
||||
<a className="about" onClick={() => setType('about')}>
|
||||
about
|
||||
</a>
|
||||
<a className="dashboard" onClick={() => setType('dashboard')}>
|
||||
dashboard
|
||||
</a>
|
||||
<div>
|
||||
{type === 'about' && (
|
||||
<ConfigProvider locale={zhCN}>
|
||||
<Demo type="about" />
|
||||
</ConfigProvider>
|
||||
)}
|
||||
{type === 'dashboard' && (
|
||||
<ConfigProvider locale={zhCN}>
|
||||
<Demo type="dashboard" />
|
||||
</ConfigProvider>
|
||||
)}
|
||||
</div>
|
||||
</div>
|
||||
);
|
||||
};
|
||||
const wrapper = mount(<BasicExample />);
|
||||
wrapper.find('.about').at(0).simulate('click');
|
||||
jest.runAllTimers();
|
||||
wrapper.find('.dashboard').at(0).simulate('click');
|
||||
jest.runAllTimers();
|
||||
expect(document.body.querySelectorAll('.ant-btn-primary span')[0].textContent).toBe('确 定');
|
||||
Modal.destroyAll();
|
||||
jest.useRealTimers();
|
||||
});
|
||||
});
|
@ -62,6 +62,10 @@ export default class LocaleProvider extends React.Component<LocaleProviderProps,
|
||||
);
|
||||
}
|
||||
|
||||
componentDidMount() {
|
||||
changeConfirmLocale(this.props.locale && this.props.locale.Modal);
|
||||
}
|
||||
|
||||
componentDidUpdate(prevProps: LocaleProviderProps) {
|
||||
const { locale } = this.props;
|
||||
if (prevProps.locale !== locale) {
|
||||
|
Loading…
Reference in New Issue
Block a user