The easy-to-use open source Business Intelligence and Embedded Analytics tool that lets everyone work with data :bar_chart:
TypeScript analyticsbibusiness-intelligencebusinessintelligenceclojuredashboarddatadata-analysisdata-visualizationdatabasemetabasemysqlpostgrespostgresqlreportingslacksql-editorvisualization
fix date picker month navigation timezone issue (#63366)
Aleksandr Lesnenko4e851e0e192e
diff --git a/frontend/src/metabase/querying/filters/components/DatePicker/SpecificDatePicker/SingleDatePicker/SingleDatePickerBody/SingleDatePickerBody.tsx b/frontend/src/metabase/querying/filters/components/DatePicker/SpecificDatePicker/SingleDatePicker/SingleDatePickerBody/SingleDatePickerBody.tsxindex 6234572f769..ecf47249363 100644--- a/frontend/src/metabase/querying/filters/components/DatePicker/SpecificDatePicker/SingleDatePicker/SingleDatePickerBody/SingleDatePickerBody.tsx+++ b/frontend/src/metabase/querying/filters/components/DatePicker/SpecificDatePicker/SingleDatePicker/SingleDatePickerBody/SingleDatePickerBody.tsx@@ -36,7 +36,7 @@ export function SingleDatePickerBody({popoverProps={{ opened: false }}aria-label={t`Date`}onChange={handleDateChange}- onDateChange={(val) => val && setDate(new Date(val))}+ onDateChange={(val) => val && setDate(dayjs(val).toDate())}/>{hasTime && (<TimeInput@@ -49,7 +49,7 @@ export function SingleDatePickerBody({value={value}date={date}onChange={handleDateChange}- onDateChange={(val) => val && setDate(new Date(val))}+ onDateChange={(val) => val && setDate(dayjs(val).toDate())}/></Stack>);diff --git a/frontend/src/metabase/querying/filters/components/DatePicker/SpecificDatePicker/SingleDatePicker/SingleDatePickerBody/SingleDatePickerBody.unit.spec.tsx b/frontend/src/metabase/querying/filters/components/DatePicker/SpecificDatePicker/SingleDatePicker/SingleDatePickerBody/SingleDatePickerBody.unit.spec.tsxnew file mode 100644index 00000000000..04b14cb2f0e--- /dev/null+++ b/frontend/src/metabase/querying/filters/components/DatePicker/SpecificDatePicker/SingleDatePicker/SingleDatePickerBody/SingleDatePickerBody.unit.spec.tsx@@ -0,0 +1,54 @@+import _userEvent from "@testing-library/user-event";++import { renderWithProviders, screen } from "__support__/ui";++import { SingleDatePickerBody } from "./SingleDatePickerBody";++const userEvent = _userEvent.setup({+ advanceTimers: jest.advanceTimersByTime,+});++interface SetupOpts {+ value?: Date;+ hasTime?: boolean;+}++function setup({+ value = new Date(2020, 0, 10),+ hasTime = false,+}: SetupOpts = {}) {+ renderWithProviders(+ <SingleDatePickerBody+ value={value}+ hasTime={hasTime}+ onChange={jest.fn()}+ />,+ );+}++describe("SingleDatePickerBody", () => {+ beforeAll(() => {+ jest.useFakeTimers();+ jest.setSystemTime(new Date(2020, 0, 15));+ });++ afterAll(() => {+ jest.useRealTimers();+ });++ it("should navigate back one month when clicking previous month button from September 1st (metabase#63308)", async () => {+ setup({ value: new Date(2020, 8, 1) });++ expect(screen.getByText("September 2020")).toBeInTheDocument();++ const prevButton = screen+ .getAllByRole("button")+ .find((button) => button.getAttribute("data-direction") === "previous");++ expect(prevButton).toBeTruthy();+ await userEvent.click(prevButton!);++ expect(await screen.findByText("August 2020")).toBeInTheDocument();+ expect(screen.queryByText("July 2020")).not.toBeInTheDocument();+ });+});