From b56c5229dd0ffa27fa169fb56e96c8dbf2b9c7cb Mon Sep 17 00:00:00 2001 From: Frank Niessink Date: Mon, 20 Jan 2025 23:12:06 +0100 Subject: [PATCH] Use browser locale to determine the first day of the week in date pickers. Fixes #7250. --- components/frontend/src/AppUI.js | 5 ++- components/frontend/src/locale.js | 31 +++++++++++++++++++ components/frontend/src/locale.test.js | 9 ++++++ .../src/metric/MetricDebtParameters.js | 1 - .../src/metric/MetricDebtParameters.test.js | 8 ++--- .../src/source/SourceEntityDetails.js | 1 - .../src/source/SourceEntityDetails.test.js | 7 ++--- .../frontend/src/source/SourceParameter.js | 1 - .../src/source/SourceParameter.test.js | 7 ++--- docs/src/changelog.md | 1 + 10 files changed, 52 insertions(+), 19 deletions(-) create mode 100644 components/frontend/src/locale.js create mode 100644 components/frontend/src/locale.test.js diff --git a/components/frontend/src/AppUI.js b/components/frontend/src/AppUI.js index 9aa5a28297..4fad490f6e 100644 --- a/components/frontend/src/AppUI.js +++ b/components/frontend/src/AppUI.js @@ -4,7 +4,6 @@ import "./App.css" import { useColorScheme } from "@mui/material/styles" import { LocalizationProvider } from "@mui/x-date-pickers" import { AdapterDayjs } from "@mui/x-date-pickers/AdapterDayjs" -import { locale_en_gb } from "dayjs/locale/en-gb" import { bool, func, number, object, string } from "prop-types" import HashLinkObserver from "react-hash-link" import { ToastContainer } from "react-toastify" @@ -15,6 +14,7 @@ import { Permissions } from "./context/Permissions" import { Footer } from "./header_footer/Footer" import { Menubar } from "./header_footer/Menubar" import { SettingsPanel } from "./header_footer/SettingsPanel" +import { adapterLocale } from "./locale" import { PageContent } from "./PageContent" import { datePropType, @@ -63,9 +63,8 @@ export function AppUI({ settings.sortColumn.set(column) } } - return ( - + { + expect(adapterLocale("en")).toBe("en-GB") +}) + +it("returns the Dutch locale", () => { + expect(adapterLocale("nl-NL")).toBe("nl") +}) diff --git a/components/frontend/src/metric/MetricDebtParameters.js b/components/frontend/src/metric/MetricDebtParameters.js index 13e43929c6..e5d448f18b 100644 --- a/components/frontend/src/metric/MetricDebtParameters.js +++ b/components/frontend/src/metric/MetricDebtParameters.js @@ -73,7 +73,6 @@ function TechnicalDebtEndDate({ metric, metric_uuid, reload }) { set_metric_attribute(metric_uuid, "debt_end_date", value, reload)} slotProps={{ field: { clearable: true }, textField: { helperText: helperText } }} diff --git a/components/frontend/src/metric/MetricDebtParameters.test.js b/components/frontend/src/metric/MetricDebtParameters.test.js index ef244e6fef..9709c193ba 100644 --- a/components/frontend/src/metric/MetricDebtParameters.test.js +++ b/components/frontend/src/metric/MetricDebtParameters.test.js @@ -3,7 +3,6 @@ import { AdapterDayjs } from "@mui/x-date-pickers/AdapterDayjs" import { render, screen } from "@testing-library/react" import userEvent from "@testing-library/user-event" import dayjs from "dayjs" -import { locale_en_gb } from "dayjs/locale/en-gb" import * as fetch_server_api from "../api/fetch_server_api" import { DataModel } from "../context/DataModel" @@ -38,7 +37,7 @@ const dataModel = { function renderMetricDebtParameters({ accept_debt = false, debt_end_date = null } = {}) { render( - + { it("sets the technical debt end date", async () => { fetch_server_api.fetch_server_api = jest.fn().mockResolvedValue({ ok: true }) renderMetricDebtParameters() - await userEvent.type(screen.getByPlaceholderText(/YYYY-MM-DD/), "20221231{Enter}") - const expectedDate = dayjs("2022-12-31") + await userEvent.type(screen.getByPlaceholderText(/YYYY/), "12312022{Enter}") expect(fetch_server_api.fetch_server_api).toHaveBeenLastCalledWith( "post", "metric/metric_uuid/attribute/debt_end_date", - { debt_end_date: expectedDate }, + { debt_end_date: dayjs("2022-12-31") }, ) }) diff --git a/components/frontend/src/source/SourceEntityDetails.js b/components/frontend/src/source/SourceEntityDetails.js index 83adc3838d..455f0030ed 100644 --- a/components/frontend/src/source/SourceEntityDetails.js +++ b/components/frontend/src/source/SourceEntityDetails.js @@ -103,7 +103,6 @@ export function SourceEntityDetails({ set_source_entity_attribute( diff --git a/components/frontend/src/source/SourceEntityDetails.test.js b/components/frontend/src/source/SourceEntityDetails.test.js index 12c3123224..48e3349885 100644 --- a/components/frontend/src/source/SourceEntityDetails.test.js +++ b/components/frontend/src/source/SourceEntityDetails.test.js @@ -3,7 +3,6 @@ import { AdapterDayjs } from "@mui/x-date-pickers/AdapterDayjs" import { fireEvent, render, screen } from "@testing-library/react" import userEvent from "@testing-library/user-event" import dayjs from "dayjs" -import { locale_en_gb } from "dayjs/locale/en-gb" import * as source from "../api/source" import { EDIT_ENTITY_PERMISSION, Permissions } from "../context/Permissions" @@ -15,7 +14,7 @@ const reload = jest.fn function renderSourceEntityDetails({ report = null, status_end_date = null } = {}) { render( - + { it("shows the entity status end date", async () => { source.set_source_entity_attribute = jest.fn() renderSourceEntityDetails({ status_end_date: "20250112" }) - expect(screen.queryAllByDisplayValue(/2025-01-12/).length).toBe(1) + expect(screen.queryAllByDisplayValue("01/12/2025").length).toBe(1) }) it("changes the entity status end date", async () => { source.set_source_entity_attribute = jest.fn() renderSourceEntityDetails() - await userEvent.type(screen.getByPlaceholderText(/YYYY-MM-DD/), "22220101{Enter}") + await userEvent.type(screen.getByPlaceholderText(/YYYY/), "01012222{Enter}") expect(source.set_source_entity_attribute).toHaveBeenCalledWith( "metric_uuid", "source_uuid", diff --git a/components/frontend/src/source/SourceParameter.js b/components/frontend/src/source/SourceParameter.js index c8b3754702..b5bbac3487 100644 --- a/components/frontend/src/source/SourceParameter.js +++ b/components/frontend/src/source/SourceParameter.js @@ -185,7 +185,6 @@ export function SourceParameter({ + { parameter_value: "2021-10-10", }) expect(screen.queryAllByLabelText(/Date/).length).toBe(1) - expect(screen.queryAllByDisplayValue("2021-10-10").length).toBe(1) + expect(screen.queryAllByDisplayValue("10/10/2021").length).toBe(1) }) it("renders a date parameter without date", () => { @@ -110,7 +109,7 @@ it("renders a date parameter without date", () => { parameter_value: "", }) expect(screen.queryAllByLabelText(/Date/).length).toBe(1) - expect(screen.queryAllByPlaceholderText(/YYYY-MM-DD/).length).toBe(1) + expect(screen.queryAllByPlaceholderText(/YYYY/).length).toBe(1) }) it("renders an integer parameter", () => { diff --git a/docs/src/changelog.md b/docs/src/changelog.md index be781432bd..6c4819d148 100644 --- a/docs/src/changelog.md +++ b/docs/src/changelog.md @@ -16,6 +16,7 @@ If your currently installed *Quality-time* version is not the latest version, pl ### Fixed +- Use browser locale to determine the first day of the week in date pickers. Fixes [#7250](https://github.com/ICTU/quality-time/issues/7250). - Fix accessibility issues in dark mode. Fixes [#7251](https://github.com/ICTU/quality-time/issues/7251). - When measuring security warnings with Trivy JSON as source, be prepared for optional fields not being present. Fixes [#10672](https://github.com/ICTU/quality-time/issues/10672). - Docker compose has been integrated into Docker as a subcommand for a while, but the developer documentation did not reflect that. Change `docker-compose` to `docker compose` in the documentation. Fixes [#10684](https://github.com/ICTU/quality-time/issues/10684).