|
2 | 2 | import { act, createEvent, fireEvent, render } from '@testing-library/react';
|
3 | 3 | import type { Moment } from 'moment';
|
4 | 4 | import moment from 'moment';
|
| 5 | +import 'moment/locale/zh-cn'; |
5 | 6 | import KeyCode from 'rc-util/lib/KeyCode';
|
6 | 7 | import { spyElementPrototypes } from 'rc-util/lib/test/domHook';
|
7 | 8 | import { resetWarned } from 'rc-util/lib/warning';
|
8 | 9 | import React from 'react';
|
9 | 10 | import type { PanelMode, PickerMode } from '../src/interface';
|
| 11 | +import enUS from '../src/locale/en_US'; |
| 12 | +import zhCN from '../src/locale/zh_CN'; |
10 | 13 | import {
|
11 | 14 | clearValue,
|
12 | 15 | closePicker,
|
@@ -555,7 +558,7 @@ describe('Picker.Basic', () => {
|
555 | 558 | );
|
556 | 559 | expect(document.querySelector('.rc-picker-input')).toMatchSnapshot();
|
557 | 560 | expect(errorSpy).toHaveBeenCalledWith(
|
558 |
| - 'Warning: `clearIcon` will be removed in future. Please use `allowClear` instead.' |
| 561 | + 'Warning: `clearIcon` will be removed in future. Please use `allowClear` instead.', |
559 | 562 | );
|
560 | 563 | });
|
561 | 564 |
|
@@ -626,7 +629,9 @@ describe('Picker.Basic', () => {
|
626 | 629 | expect(errorSpy).not.toBeCalled();
|
627 | 630 | const { container } = render(<MomentPicker picker="time" hourStep={9} />);
|
628 | 631 | openPicker(container);
|
629 |
| - expect(errorSpy).toBeCalledWith('Warning: `hourStep` 9 is invalid. It should be a factor of 24.'); |
| 632 | + expect(errorSpy).toBeCalledWith( |
| 633 | + 'Warning: `hourStep` 9 is invalid. It should be a factor of 24.', |
| 634 | + ); |
630 | 635 | });
|
631 | 636 |
|
632 | 637 | it('should show warning when minute step is invalid', () => {
|
@@ -656,7 +661,9 @@ describe('Picker.Basic', () => {
|
656 | 661 | const { container } = render(<MomentPicker picker="time" {...props} />);
|
657 | 662 | openPicker(container);
|
658 | 663 |
|
659 |
| - const column = document.querySelector(`.rc-picker-time-panel-column:nth-child(${index + 1})`); |
| 664 | + const column = document.querySelector( |
| 665 | + `.rc-picker-time-panel-column:nth-child(${index + 1})`, |
| 666 | + ); |
660 | 667 | expect(column).toBeTruthy();
|
661 | 668 |
|
662 | 669 | const cells = column.querySelectorAll('.rc-picker-time-panel-cell-inner');
|
@@ -748,7 +755,7 @@ describe('Picker.Basic', () => {
|
748 | 755 | it('defaultOpenValue in timePicker', () => {
|
749 | 756 | resetWarned();
|
750 | 757 | const onChange = jest.fn();
|
751 |
| - const errSpy = jest.spyOn(console, 'error').mockImplementation(() => { }); |
| 758 | + const errSpy = jest.spyOn(console, 'error').mockImplementation(() => {}); |
752 | 759 |
|
753 | 760 | const { container } = render(
|
754 | 761 | <MomentPicker
|
@@ -1085,4 +1092,19 @@ describe('Picker.Basic', () => {
|
1085 | 1092 |
|
1086 | 1093 | expect(onChange.mock.calls[1][0].format('YYYY-MM-DD HH:mm:ss')).toEqual('2023-05-01 12:34:56');
|
1087 | 1094 | });
|
| 1095 | + |
| 1096 | + it('switch picker locale should reformat value', () => { |
| 1097 | + const { container, rerender } = render( |
| 1098 | + <MomentPicker value={getMoment('2011-11-11')} format={'dddd'} locale={enUS} />, |
| 1099 | + ); |
| 1100 | + expect(container.querySelector('input').value).toEqual('Friday'); |
| 1101 | + |
| 1102 | + // Switch locale |
| 1103 | + moment.locale('zh-cn'); |
| 1104 | + rerender(<MomentPicker value={getMoment('2011-11-11')} format={'dddd'} locale={zhCN} />); |
| 1105 | + expect(container.querySelector('input').value).toEqual('星期五'); |
| 1106 | + |
| 1107 | + // Reset locale |
| 1108 | + moment.locale('en'); |
| 1109 | + }); |
1088 | 1110 | });
|
0 commit comments