|
1 | | -import type { PanelMode } from '../src/interface'; |
2 | 1 | import { fireEvent, render } from '@testing-library/react'; |
3 | 2 | import type { Moment } from 'moment'; |
4 | 3 | import moment from 'moment'; |
5 | 4 | import { spyElementPrototypes } from 'rc-util/lib/test/domHook'; |
6 | 5 | import { resetWarned } from 'rc-util/lib/warning'; |
7 | 6 | import React from 'react'; |
| 7 | +import type { PanelMode } from '../src/interface'; |
8 | 8 | import enUS from '../src/locale/en_US'; |
9 | 9 | import zhCN from '../src/locale/zh_CN'; |
10 | 10 | import { |
@@ -475,7 +475,6 @@ describe('Picker.Panel', () => { |
475 | 475 |
|
476 | 476 | errSpy.mockRestore(); |
477 | 477 | }); |
478 | | - |
479 | 478 | it('should render correctly in rtl', () => { |
480 | 479 | const { container } = render(<MomentPickerPanel direction="rtl" />); |
481 | 480 | expect(container).toMatchSnapshot(); |
@@ -568,7 +567,15 @@ describe('Picker.Panel', () => { |
568 | 567 | }); |
569 | 568 | }); |
570 | 569 |
|
571 | | - const supportCellRenderPicker: PanelMode[] = ['year', 'month', 'date', 'quarter', 'week', 'time', 'decade']; |
| 570 | + const supportCellRenderPicker: PanelMode[] = [ |
| 571 | + 'year', |
| 572 | + 'month', |
| 573 | + 'date', |
| 574 | + 'quarter', |
| 575 | + 'week', |
| 576 | + 'time', |
| 577 | + 'decade', |
| 578 | + ]; |
572 | 579 |
|
573 | 580 | const getCurText = (picker: PanelMode, current: Moment | number) => { |
574 | 581 | switch (picker) { |
@@ -618,6 +625,28 @@ describe('Picker.Panel', () => { |
618 | 625 | expect(container.querySelector(`.rc-picker-${picker}-panel`)).toBeTruthy(); |
619 | 626 | expect(container).toMatchSnapshot(); |
620 | 627 | }); |
| 628 | + |
| 629 | + it('warning with dateRender and monthCellRender', () => { |
| 630 | + resetWarned(); |
| 631 | + const errSpy = jest.spyOn(console, 'error').mockImplementation(() => {}); |
| 632 | + |
| 633 | + render( |
| 634 | + <MomentPickerPanel |
| 635 | + picker={picker as any} |
| 636 | + dateRender={(current) => ( |
| 637 | + <div className="customWrapper">{getCurText(picker, current)}</div> |
| 638 | + )} |
| 639 | + monthCellRender={(current) => ( |
| 640 | + <div className="customWrapper">{getCurText(picker, current)}</div> |
| 641 | + )} |
| 642 | + />, |
| 643 | + ); |
| 644 | + expect(errSpy).toHaveBeenCalledWith("Warning: 'dateRender' is deprecated. Please use 'cellRender' instead."); |
| 645 | + expect(errSpy).toHaveBeenCalledWith("Warning: 'monthCellRender' is deprecated. Please use 'cellRender' instead."); |
| 646 | + |
| 647 | + errSpy.mockRestore(); |
| 648 | + }); |
| 649 | + |
621 | 650 | it(`append cell with cellRender in ${picker}`, () => { |
622 | 651 | const App = () => ( |
623 | 652 | <MomentPickerPanel |
|
0 commit comments