2019-01-12 11:33:27 +08:00
|
|
|
import { mount } from '@vue/test-utils';
|
|
|
|
import Vue from 'vue';
|
|
|
|
import moment from 'moment';
|
|
|
|
import MockDate from 'mockdate';
|
|
|
|
import {
|
|
|
|
LocaleProvider,
|
|
|
|
Pagination,
|
|
|
|
DatePicker,
|
|
|
|
TimePicker,
|
|
|
|
Calendar,
|
|
|
|
Popconfirm,
|
|
|
|
Table,
|
|
|
|
Modal,
|
|
|
|
Select,
|
|
|
|
Transfer,
|
|
|
|
} from '../..';
|
|
|
|
import arEG from '../ar_EG';
|
|
|
|
import bgBG from '../bg_BG';
|
|
|
|
import caES from '../ca_ES';
|
|
|
|
import csCZ from '../cs_CZ';
|
|
|
|
import daDK from '../da_DK';
|
|
|
|
import deDE from '../de_DE';
|
|
|
|
import elGR from '../el_GR';
|
|
|
|
import enGB from '../en_GB';
|
|
|
|
import enUS from '../en_US';
|
|
|
|
import esES from '../es_ES';
|
|
|
|
import etEE from '../et_EE';
|
|
|
|
import faIR from '../fa_IR';
|
|
|
|
import fiFI from '../fi_FI';
|
|
|
|
import frBE from '../fr_BE';
|
|
|
|
import frFR from '../fr_FR';
|
|
|
|
import heIL from '../he_IL';
|
2019-03-07 13:26:03 +08:00
|
|
|
import hiIN from '../hi_IN';
|
2019-01-12 11:33:27 +08:00
|
|
|
import huHU from '../hu_HU';
|
|
|
|
import isIS from '../is_IS';
|
|
|
|
import itIT from '../it_IT';
|
|
|
|
import jaJP from '../ja_JP';
|
2019-03-07 13:26:03 +08:00
|
|
|
import knIN from '../kn_IN';
|
2019-01-12 11:33:27 +08:00
|
|
|
import koKR from '../ko_KR';
|
|
|
|
import kuIQ from '../ku_IQ';
|
|
|
|
import mnMN from '../mn_MN';
|
|
|
|
import nbNO from '../nb_NO';
|
|
|
|
import neNP from '../ne-NP';
|
|
|
|
import nlBE from '../nl_BE';
|
|
|
|
import nlNL from '../nl_NL';
|
|
|
|
import plPL from '../pl_PL';
|
|
|
|
import ptBR from '../pt_BR';
|
|
|
|
import ptPT from '../pt_PT';
|
|
|
|
import ruRU from '../ru_RU';
|
|
|
|
import skSK from '../sk_SK';
|
|
|
|
import slSI from '../sl_SI';
|
|
|
|
import srRS from '../sr_RS';
|
|
|
|
import svSE from '../sv_SE';
|
|
|
|
import thTH from '../th_TH';
|
|
|
|
import trTR from '../tr_TR';
|
|
|
|
import ukUA from '../uk_UA';
|
|
|
|
import viVN from '../vi_VN';
|
|
|
|
import idID from '../id_ID';
|
|
|
|
import zhCN from '../zh_CN';
|
|
|
|
import zhTW from '../zh_TW';
|
2018-05-19 12:53:37 +08:00
|
|
|
|
2019-01-05 10:40:34 +08:00
|
|
|
const locales = [
|
|
|
|
arEG,
|
|
|
|
bgBG,
|
|
|
|
caES,
|
|
|
|
csCZ,
|
|
|
|
daDK,
|
|
|
|
deDE,
|
|
|
|
elGR,
|
|
|
|
enGB,
|
|
|
|
enUS,
|
|
|
|
esES,
|
|
|
|
etEE,
|
|
|
|
faIR,
|
|
|
|
fiFI,
|
|
|
|
frBE,
|
|
|
|
frFR,
|
|
|
|
heIL,
|
2019-03-07 13:26:03 +08:00
|
|
|
hiIN,
|
2019-01-05 10:40:34 +08:00
|
|
|
huHU,
|
|
|
|
isIS,
|
|
|
|
itIT,
|
|
|
|
jaJP,
|
2019-03-07 13:26:03 +08:00
|
|
|
knIN,
|
2019-01-05 10:40:34 +08:00
|
|
|
koKR,
|
|
|
|
kuIQ,
|
|
|
|
mnMN,
|
|
|
|
nbNO,
|
|
|
|
neNP,
|
|
|
|
nlBE,
|
|
|
|
nlNL,
|
|
|
|
plPL,
|
|
|
|
ptBR,
|
|
|
|
ptPT,
|
|
|
|
ruRU,
|
|
|
|
skSK,
|
|
|
|
slSI,
|
|
|
|
srRS,
|
|
|
|
svSE,
|
|
|
|
thTH,
|
|
|
|
trTR,
|
|
|
|
ukUA,
|
|
|
|
viVN,
|
|
|
|
idID,
|
|
|
|
zhCN,
|
|
|
|
zhTW,
|
2019-01-12 11:33:27 +08:00
|
|
|
];
|
2018-05-19 12:53:37 +08:00
|
|
|
|
2019-01-12 11:33:27 +08:00
|
|
|
const { Option } = Select;
|
|
|
|
const { RangePicker } = DatePicker;
|
2018-05-19 12:53:37 +08:00
|
|
|
|
2019-01-12 11:33:27 +08:00
|
|
|
const columns = [
|
|
|
|
{
|
|
|
|
title: 'Name',
|
|
|
|
dataIndex: 'name',
|
|
|
|
filters: [
|
|
|
|
{
|
|
|
|
text: 'filter1',
|
|
|
|
value: 'filter1',
|
|
|
|
},
|
|
|
|
],
|
|
|
|
},
|
|
|
|
{
|
|
|
|
title: 'Age',
|
|
|
|
dataIndex: 'age',
|
|
|
|
},
|
|
|
|
];
|
2018-05-19 12:53:37 +08:00
|
|
|
|
|
|
|
const App = {
|
2019-02-01 17:23:00 +08:00
|
|
|
render() {
|
2018-05-19 12:53:37 +08:00
|
|
|
return (
|
|
|
|
<div>
|
|
|
|
<Pagination defaultCurrent={1} total={50} showSizeChanger />
|
|
|
|
<Select showSearch style={{ width: '200px' }}>
|
2019-01-12 11:33:27 +08:00
|
|
|
<Option value="jack">jack</Option>
|
|
|
|
<Option value="lucy">lucy</Option>
|
2018-05-19 12:53:37 +08:00
|
|
|
</Select>
|
|
|
|
<DatePicker open />
|
|
|
|
<TimePicker open defaultOpenValue={moment()} />
|
|
|
|
<RangePicker open style={{ width: '200px' }} />
|
2019-01-12 11:33:27 +08:00
|
|
|
<Popconfirm title="Question?" visible>
|
2018-05-19 12:53:37 +08:00
|
|
|
<a>Click to confirm</a>
|
|
|
|
</Popconfirm>
|
2019-01-12 11:33:27 +08:00
|
|
|
<Transfer dataSource={[]} showSearch targetKeys={[]} render={item => item.title} />
|
2018-05-19 12:53:37 +08:00
|
|
|
<Calendar fullscreen={false} value={moment()} />
|
|
|
|
<Table dataSource={[]} columns={columns} />
|
2019-01-12 11:33:27 +08:00
|
|
|
<Modal title="Locale Modal" visible>
|
2018-05-19 12:53:37 +08:00
|
|
|
<p>Locale Modal</p>
|
|
|
|
</Modal>
|
|
|
|
</div>
|
2019-01-12 11:33:27 +08:00
|
|
|
);
|
|
|
|
},
|
|
|
|
};
|
2018-05-19 12:53:37 +08:00
|
|
|
|
|
|
|
describe('Locale Provider', () => {
|
|
|
|
beforeAll(() => {
|
2019-01-12 11:33:27 +08:00
|
|
|
document.body.innerHTML = '';
|
|
|
|
MockDate.set(moment('2017-09-18T03:30:07.795'));
|
|
|
|
});
|
2018-05-19 12:53:37 +08:00
|
|
|
|
|
|
|
afterAll(() => {
|
2019-01-12 11:33:27 +08:00
|
|
|
MockDate.reset();
|
|
|
|
});
|
2018-05-19 12:53:37 +08:00
|
|
|
|
2019-01-12 11:33:27 +08:00
|
|
|
locales.forEach(locale => {
|
|
|
|
it(`should display the text as ${locale.locale}`, done => {
|
2018-05-19 12:53:37 +08:00
|
|
|
const wrapper = mount(
|
|
|
|
{
|
2019-01-12 11:33:27 +08:00
|
|
|
render() {
|
2018-05-19 12:53:37 +08:00
|
|
|
return (
|
|
|
|
<LocaleProvider locale={locale}>
|
|
|
|
<App />
|
|
|
|
</LocaleProvider>
|
2019-01-12 11:33:27 +08:00
|
|
|
);
|
2018-05-19 12:53:37 +08:00
|
|
|
},
|
|
|
|
},
|
2019-01-12 11:33:27 +08:00
|
|
|
{ sync: false },
|
|
|
|
);
|
2018-05-19 12:53:37 +08:00
|
|
|
Vue.nextTick(() => {
|
2019-01-12 11:33:27 +08:00
|
|
|
expect(wrapper.html()).toMatchSnapshot();
|
|
|
|
done();
|
|
|
|
});
|
|
|
|
});
|
|
|
|
});
|
2018-05-19 12:53:37 +08:00
|
|
|
|
|
|
|
it('should change locale of Modal.xxx', () => {
|
|
|
|
const ModalDemo = {
|
2019-01-12 11:33:27 +08:00
|
|
|
mounted() {
|
2018-05-19 12:53:37 +08:00
|
|
|
Modal.confirm({
|
|
|
|
title: 'Hello World!',
|
2019-01-12 11:33:27 +08:00
|
|
|
});
|
2018-05-19 12:53:37 +08:00
|
|
|
},
|
2019-01-12 11:33:27 +08:00
|
|
|
render() {
|
|
|
|
return null;
|
2018-05-19 12:53:37 +08:00
|
|
|
},
|
2019-01-12 11:33:27 +08:00
|
|
|
};
|
|
|
|
locales.forEach(locale => {
|
2018-05-19 12:53:37 +08:00
|
|
|
mount(
|
|
|
|
{
|
2019-01-12 11:33:27 +08:00
|
|
|
render() {
|
2018-05-19 12:53:37 +08:00
|
|
|
return (
|
|
|
|
<LocaleProvider locale={locale}>
|
|
|
|
<ModalDemo />
|
|
|
|
</LocaleProvider>
|
2019-01-12 11:33:27 +08:00
|
|
|
);
|
2018-05-19 12:53:37 +08:00
|
|
|
},
|
|
|
|
},
|
2019-01-12 11:33:27 +08:00
|
|
|
{ sync: false },
|
|
|
|
);
|
|
|
|
const currentConfirmNode = document.querySelectorAll('.ant-modal-confirm')[
|
|
|
|
document.querySelectorAll('.ant-modal-confirm').length - 1
|
|
|
|
];
|
|
|
|
let cancelButtonText = currentConfirmNode.querySelectorAll(
|
|
|
|
'.ant-btn:not(.ant-btn-primary) span',
|
|
|
|
)[0].innerHTML;
|
|
|
|
let okButtonText = currentConfirmNode.querySelectorAll('.ant-btn-primary span')[0].innerHTML;
|
2018-05-19 12:53:37 +08:00
|
|
|
if (locale.locale === 'zh-cn') {
|
2019-01-12 11:33:27 +08:00
|
|
|
cancelButtonText = cancelButtonText.replace(' ', '');
|
|
|
|
okButtonText = okButtonText.replace(' ', '');
|
2018-05-19 12:53:37 +08:00
|
|
|
}
|
2019-01-12 11:33:27 +08:00
|
|
|
expect(cancelButtonText).toBe(locale.Modal.cancelText);
|
|
|
|
expect(okButtonText).toBe(locale.Modal.okText);
|
|
|
|
});
|
|
|
|
});
|
2018-05-19 12:53:37 +08:00
|
|
|
|
2019-01-12 11:33:27 +08:00
|
|
|
it('set moment locale when locale changes', done => {
|
|
|
|
document.body.innerHTML = '';
|
2018-05-19 12:53:37 +08:00
|
|
|
const Test = {
|
2019-01-12 11:33:27 +08:00
|
|
|
data() {
|
2018-05-19 12:53:37 +08:00
|
|
|
return {
|
|
|
|
locale: zhCN,
|
2019-01-12 11:33:27 +08:00
|
|
|
};
|
2018-05-19 12:53:37 +08:00
|
|
|
},
|
2019-01-12 11:33:27 +08:00
|
|
|
render() {
|
2018-05-19 12:53:37 +08:00
|
|
|
return (
|
|
|
|
<LocaleProvider locale={this.locale}>
|
|
|
|
<div>
|
|
|
|
<DatePicker defaultValue={moment()} open />
|
|
|
|
</div>
|
|
|
|
</LocaleProvider>
|
2019-01-12 11:33:27 +08:00
|
|
|
);
|
2018-05-19 12:53:37 +08:00
|
|
|
},
|
2019-01-12 11:33:27 +08:00
|
|
|
};
|
|
|
|
const wrapper = mount(Test, { sync: false, attachToDocument: true });
|
2018-05-30 14:12:43 +08:00
|
|
|
setTimeout(() => {
|
2019-01-12 11:33:27 +08:00
|
|
|
expect(document.body.innerHTML).toMatchSnapshot();
|
|
|
|
wrapper.setData({ locale: frFR });
|
2018-05-30 14:12:43 +08:00
|
|
|
setTimeout(() => {
|
2019-01-12 11:33:27 +08:00
|
|
|
expect(document.body.innerHTML).toMatchSnapshot();
|
|
|
|
wrapper.setData({ locale: null });
|
2018-05-30 14:12:43 +08:00
|
|
|
setTimeout(() => {
|
2019-01-12 11:33:27 +08:00
|
|
|
expect(document.body.innerHTML).toMatchSnapshot();
|
|
|
|
done();
|
|
|
|
});
|
|
|
|
});
|
|
|
|
});
|
|
|
|
});
|
|
|
|
});
|