From 5e7f3ae9512a634a12ea57bd12e4bbdfd32dce6a Mon Sep 17 00:00:00 2001 From: Giampaolo Bellavite Date: Sat, 28 Sep 2024 16:49:13 -0500 Subject: [PATCH 1/7] fix: month not being localized with `dropdown-years` caption layout --- src/DayPicker.test.tsx | 13 + src/DayPicker.tsx | 5 +- src/__snapshots__/DayPicker.test.tsx.snap | 420 ++++++++++++++++++++++ 3 files changed, 437 insertions(+), 1 deletion(-) create mode 100644 src/__snapshots__/DayPicker.test.tsx.snap diff --git a/src/DayPicker.test.tsx b/src/DayPicker.test.tsx index 8a29018bd..6cbcf9362 100644 --- a/src/DayPicker.test.tsx +++ b/src/DayPicker.test.tsx @@ -16,6 +16,7 @@ import { user } from "@/test/user"; import { DayPicker } from "./DayPicker"; import { MonthProps } from "./components/Month"; import { MonthsProps } from "./components/Months"; +import { es } from "./locale"; const testId = "test"; const dayPicker = () => screen.getByTestId(testId); @@ -193,3 +194,15 @@ describe("when not interactive", () => { expect(document.body).toHTMLValidate(); }); }); + +describe("should localize the calendar", () => { + const today = new Date(2024, 10, 25); + + beforeAll(() => jest.setSystemTime(today)); + afterAll(() => jest.useRealTimers()); + + test("should use the custom locale", () => { + render(); + expect(document.body).toMatchSnapshot(); + }); +}); diff --git a/src/DayPicker.tsx b/src/DayPicker.tsx index 2f54520db..8a176bb14 100644 --- a/src/DayPicker.tsx +++ b/src/DayPicker.tsx @@ -363,7 +363,10 @@ export function DayPicker(props: DayPickerProps) { /> ) : ( - {formatMonthDropdown(calendarMonth.date.getMonth())} + {formatMonthDropdown( + calendarMonth.date.getMonth(), + locale + )} )} {captionLayout === "dropdown" || diff --git a/src/__snapshots__/DayPicker.test.tsx.snap b/src/__snapshots__/DayPicker.test.tsx.snap new file mode 100644 index 000000000..4f6682f0e --- /dev/null +++ b/src/__snapshots__/DayPicker.test.tsx.snap @@ -0,0 +1,420 @@ +// Jest Snapshot v1, https://goo.gl/fbAQLP + +exports[`should localize the calendar should use the custom locale 1`] = ` + +
+
+
+ +
+
+ + noviembre 2024 + +
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
+ lu + + ma + + mi + + ju + + vi + + sá + + do +
+ 1 + + 2 + + 3 +
+ 4 + + 5 + + 6 + + 7 + + 8 + + 9 + + 10 +
+ 11 + + 12 + + 13 + + 14 + + 15 + + 16 + + 17 +
+ 18 + + 19 + + 20 + + 21 + + 22 + + 23 + + 24 +
+ 25 + + 26 + + 27 + + 28 + + 29 + + 30 +
+
+
+
+
+ +`; From 1dc61695a8680f4f0fd344ecfa5b635c8bc80e5d Mon Sep 17 00:00:00 2001 From: Giampaolo Bellavite Date: Sat, 28 Sep 2024 16:56:15 -0500 Subject: [PATCH 2/7] Update test --- src/DayPicker.test.tsx | 2 +- src/__snapshots__/DayPicker.test.tsx.snap | 546 +++++++++++++++++++++- 2 files changed, 541 insertions(+), 7 deletions(-) diff --git a/src/DayPicker.test.tsx b/src/DayPicker.test.tsx index 6cbcf9362..17c835765 100644 --- a/src/DayPicker.test.tsx +++ b/src/DayPicker.test.tsx @@ -202,7 +202,7 @@ describe("should localize the calendar", () => { afterAll(() => jest.useRealTimers()); test("should use the custom locale", () => { - render(); + render(); expect(document.body).toMatchSnapshot(); }); }); diff --git a/src/__snapshots__/DayPicker.test.tsx.snap b/src/__snapshots__/DayPicker.test.tsx.snap index 4f6682f0e..0ad51ffa6 100644 --- a/src/__snapshots__/DayPicker.test.tsx.snap +++ b/src/__snapshots__/DayPicker.test.tsx.snap @@ -52,13 +52,547 @@ exports[`should localize the calendar should use the custom locale 1`] = `
- - noviembre 2024 - + + noviembre + + + + + +
Date: Sat, 28 Sep 2024 17:02:27 -0500 Subject: [PATCH 3/7] Update test --- src/DayPicker.test.tsx | 8 +- src/__snapshots__/DayPicker.test.tsx.snap | 212 +++++++++++----------- 2 files changed, 109 insertions(+), 111 deletions(-) diff --git a/src/DayPicker.test.tsx b/src/DayPicker.test.tsx index 17c835765..b51d838b1 100644 --- a/src/DayPicker.test.tsx +++ b/src/DayPicker.test.tsx @@ -196,13 +196,11 @@ describe("when not interactive", () => { }); describe("should localize the calendar", () => { - const today = new Date(2024, 10, 25); - - beforeAll(() => jest.setSystemTime(today)); - afterAll(() => jest.useRealTimers()); - test("should use the custom locale", () => { + const today = new Date(2025, 10, 25); + jest.setSystemTime(today); render(); expect(document.body).toMatchSnapshot(); + jest.useRealTimers(); }); }); diff --git a/src/__snapshots__/DayPicker.test.tsx.snap b/src/__snapshots__/DayPicker.test.tsx.snap index 0ad51ffa6..c0269b6bf 100644 --- a/src/__snapshots__/DayPicker.test.tsx.snap +++ b/src/__snapshots__/DayPicker.test.tsx.snap @@ -69,11 +69,6 @@ exports[`should localize the calendar should use the custom locale 1`] = ` aria-label="Choose the Year" class="rdp-dropdown rdp-years_dropdown" > - +
+ + + - - + + - - + + - - + + - - -
1 2
3
4 5 6 7 8 9
10
11 12 13 14 15 16
17
18 19 20 21 22 23
24
25 26 27 28 29 30
From dd0d9b452acc824f41c8cec88173dac21aa8db20 Mon Sep 17 00:00:00 2001 From: Giampaolo Bellavite Date: Sat, 28 Sep 2024 17:05:27 -0500 Subject: [PATCH 4/7] Update test --- src/DayPicker.test.tsx | 8 +- src/__snapshots__/DayPicker.test.tsx.snap | 279 ++++++++++++++-------- 2 files changed, 185 insertions(+), 102 deletions(-) diff --git a/src/DayPicker.test.tsx b/src/DayPicker.test.tsx index b51d838b1..4bdedf038 100644 --- a/src/DayPicker.test.tsx +++ b/src/DayPicker.test.tsx @@ -21,6 +21,11 @@ import { es } from "./locale"; const testId = "test"; const dayPicker = () => screen.getByTestId(testId); +const today = new Date(2024, 8, 25); + +beforeAll(() => jest.setSystemTime(today)); +afterAll(() => jest.useRealTimers()); + test("should render a date picker component", () => { render(); expect(dayPicker()).toBeInTheDocument(); @@ -197,10 +202,7 @@ describe("when not interactive", () => { describe("should localize the calendar", () => { test("should use the custom locale", () => { - const today = new Date(2025, 10, 25); - jest.setSystemTime(today); render(); expect(document.body).toMatchSnapshot(); - jest.useRealTimers(); }); }); diff --git a/src/__snapshots__/DayPicker.test.tsx.snap b/src/__snapshots__/DayPicker.test.tsx.snap index c0269b6bf..97eb6e69c 100644 --- a/src/__snapshots__/DayPicker.test.tsx.snap +++ b/src/__snapshots__/DayPicker.test.tsx.snap @@ -59,7 +59,7 @@ exports[`should localize the calendar should use the custom locale 1`] = ` aria-live="polite" role="status" > - noviembre + septiembre + -