2019-08-05 11:27:32 +08:00
|
|
|
import React from 'react';
|
|
|
|
import { mount } from 'enzyme';
|
|
|
|
import ConfigProvider from '..';
|
2019-08-06 00:27:47 +08:00
|
|
|
import LocaleProvider from '../../locale-provider';
|
2019-09-09 11:44:54 +08:00
|
|
|
import zhCN from '../../locale/zh_CN';
|
|
|
|
import enUS from '../../locale/en_US';
|
2019-08-06 00:27:47 +08:00
|
|
|
import TimePicker from '../../time-picker';
|
2019-09-09 11:44:54 +08:00
|
|
|
import Modal from '../../modal';
|
2019-08-05 11:27:32 +08:00
|
|
|
|
|
|
|
describe('ConfigProvider.Locale', () => {
|
2019-09-09 11:44:54 +08:00
|
|
|
function $$(className) {
|
|
|
|
return document.body.querySelectorAll(className);
|
|
|
|
}
|
|
|
|
|
2019-08-05 11:27:32 +08:00
|
|
|
it('not throw', () => {
|
|
|
|
if (process.env.REACT === '15') {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
mount(
|
|
|
|
<ConfigProvider locale={{}}>
|
|
|
|
<span />
|
|
|
|
<span />
|
|
|
|
</ConfigProvider>,
|
|
|
|
);
|
|
|
|
});
|
2019-08-06 00:27:47 +08:00
|
|
|
|
2019-09-09 11:44:54 +08:00
|
|
|
// https://github.com/ant-design/ant-design/issues/18731
|
|
|
|
it('should not reset locale for Modal', () => {
|
|
|
|
class App extends React.Component {
|
|
|
|
state = {
|
|
|
|
showButton: false,
|
|
|
|
};
|
|
|
|
|
|
|
|
componentDidMount() {
|
|
|
|
this.setState({
|
|
|
|
showButton: true,
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
openConfirm = () => {
|
|
|
|
Modal.confirm({
|
|
|
|
title: 'title',
|
|
|
|
content: 'Some descriptions',
|
|
|
|
});
|
|
|
|
};
|
|
|
|
|
|
|
|
render() {
|
|
|
|
return (
|
|
|
|
<ConfigProvider locale={zhCN}>
|
|
|
|
{this.state.showButton ? (
|
|
|
|
<ConfigProvider locale={enUS}>
|
|
|
|
<button type="button" onClick={this.openConfirm}>
|
|
|
|
open
|
|
|
|
</button>
|
|
|
|
</ConfigProvider>
|
|
|
|
) : null}
|
|
|
|
</ConfigProvider>
|
|
|
|
);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
const wrapper = mount(<App />);
|
|
|
|
wrapper.find('button').simulate('click');
|
|
|
|
expect($$('.ant-btn-primary')[0].textContent).toBe('OK');
|
|
|
|
});
|
|
|
|
|
2019-08-06 00:27:47 +08:00
|
|
|
describe('support legacy LocaleProvider', () => {
|
|
|
|
function testLocale(wrapper) {
|
2019-09-09 11:44:54 +08:00
|
|
|
expect(wrapper.find('input').props().placeholder).toBe(zhCN.TimePicker.placeholder);
|
2019-08-06 00:27:47 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
it('LocaleProvider', () => {
|
|
|
|
const wrapper = mount(
|
2019-09-09 11:44:54 +08:00
|
|
|
<LocaleProvider locale={zhCN}>
|
2019-08-06 00:27:47 +08:00
|
|
|
<TimePicker />
|
|
|
|
</LocaleProvider>,
|
|
|
|
);
|
|
|
|
|
|
|
|
testLocale(wrapper);
|
|
|
|
});
|
|
|
|
|
|
|
|
it('LocaleProvider > ConfigProvider', () => {
|
|
|
|
const wrapper = mount(
|
2019-09-09 11:44:54 +08:00
|
|
|
<LocaleProvider locale={zhCN}>
|
2019-08-06 00:27:47 +08:00
|
|
|
<ConfigProvider>
|
|
|
|
<TimePicker />
|
|
|
|
</ConfigProvider>
|
|
|
|
</LocaleProvider>,
|
|
|
|
);
|
|
|
|
|
|
|
|
testLocale(wrapper);
|
|
|
|
});
|
|
|
|
|
|
|
|
it('ConfigProvider > ConfigProvider', () => {
|
|
|
|
const wrapper = mount(
|
2019-09-09 11:44:54 +08:00
|
|
|
<ConfigProvider locale={zhCN}>
|
2019-08-06 00:27:47 +08:00
|
|
|
<ConfigProvider>
|
|
|
|
<TimePicker />
|
|
|
|
</ConfigProvider>
|
|
|
|
</ConfigProvider>,
|
|
|
|
);
|
|
|
|
|
|
|
|
testLocale(wrapper);
|
|
|
|
});
|
|
|
|
});
|
2019-08-05 11:27:32 +08:00
|
|
|
});
|