From ec9c4addd08fde045a2d729b3798f207b33a1655 Mon Sep 17 00:00:00 2001 From: ngchikin <57823909+NgChiKin@users.noreply.github.com> Date: Tue, 25 Jul 2023 17:38:52 +0800 Subject: [PATCH] fix: shows current week as selected in correct year (#313) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit * fix: shows current week as selected in correct year * test: add test case --------- Co-authored-by: 二货机器人 --- src/utils/dateUtil.ts | 1 + tests/panel.spec.tsx | 14 ++++++++++++++ 2 files changed, 15 insertions(+) diff --git a/src/utils/dateUtil.ts b/src/utils/dateUtil.ts index 185caaad3..d78e57c50 100644 --- a/src/utils/dateUtil.ts +++ b/src/utils/dateUtil.ts @@ -125,6 +125,7 @@ export function isSameWeek( } return ( + isSameYear(generateConfig, date1!, date2!) && generateConfig.locale.getWeek(locale, date1!) === generateConfig.locale.getWeek(locale, date2!) ); } diff --git a/tests/panel.spec.tsx b/tests/panel.spec.tsx index a5a3b5ad6..e3415739b 100644 --- a/tests/panel.spec.tsx +++ b/tests/panel.spec.tsx @@ -682,4 +682,18 @@ describe('Picker.Panel', () => { expect(container).toMatchSnapshot(); }); }); + + it('week picker current should check year', () => { + const { container } = render( + , + ); + expect( + container.querySelector('.rc-picker-week-panel-row-selected td[title="1990-09-03"]'), + ).toBeTruthy(); + + // Diff year + fireEvent.click(container.querySelector('.rc-picker-header-super-next-btn')); + expect(container.querySelector('td[title="1991-09-03"]')).toBeTruthy(); + expect(container.querySelector('.rc-picker-week-panel-row-selected')).toBeFalsy(); + }); });