fix: Timezone Select invalid labels as DST unsupported in spacetime (#14056)
* Fix: Timezone Select invalid labels as DST unsupported in spacetime * Missed a _ -> (empty string) replace causing invalid TZs * fix: getTimezone tests didnt support DST
This commit is contained in:
1 parent
12e171823b
commit
e3a5ce5f6e
3 files changed
+45
-27
No files matched your search
@@ -1,5 +1,6 @@
|
||||
import type { ITimezoneOption } from "react-timezone-select";
|
||||
|
||||
import dayjs from "@calcom/dayjs";
|
||||
import type { ICity } from "@calcom/ui/components/form/timezone-select";
|
||||
|
||||
import isProblematicTimezone from "./isProblematicTimezone";
|
||||
@@ -32,9 +33,15 @@ export const addCitiesToDropdown = (cities: ICity[]) => {
|
||||
return cityTimezones || {};
|
||||
};
|
||||
|
||||
const formatOffset = (offset: string) =>
|
||||
offset.replace(/^([-+])(0)(\d):00$/, (_, sign, _zero, hour) => `${sign}${hour}:00`);
|
||||
|
||||
export const handleOptionLabel = (option: ITimezoneOption, cities: ICity[]) => {
|
||||
const timezoneValue = option.label.split(")")[0].replace("(", " ").replace("T", "T ");
|
||||
const offsetUnit = option.label.split("-")[0].substring(1);
|
||||
const cityName = option.label.split(") ")[1];
|
||||
const refactoredOption = option.value.replace(/_/g, " ");
|
||||
return cities.length > 0 ? `${cityName}${timezoneValue}` : `${refactoredOption}${timezoneValue}`;
|
||||
|
||||
const timezoneValue = ` ${offsetUnit} ${formatOffset(dayjs.tz(undefined, option.value).format("Z"))}`;
|
||||
return cities.length > 0
|
||||
? `${cityName}${timezoneValue}`
|
||||
: `${option.value.replace(/_/g, " ")}${timezoneValue}`;
|
||||
};
|
||||
@@ -107,12 +107,9 @@ describe("Test TimezoneSelect", () => {
|
||||
expect(menuListEl).toHaveClass(classNames.menuList());
|
||||
expect(menuEl).toHaveClass(classNames.menu());
|
||||
|
||||
expect(screen.getByText(optionMockValues[1])).toBeInTheDocument();
|
||||
|
||||
// TODO America/Juneau and America/Toronto failing
|
||||
// for (const mockText of optionMockValues) {
|
||||
// expect(screen.getByText(mockText)).toBeInTheDocument();
|
||||
// }
|
||||
for (const mockText of optionMockValues) {
|
||||
expect(screen.getByText(mockText)).toBeInTheDocument();
|
||||
}
|
||||
});
|
||||
|
||||
test("Should render with the correct CSS when provided with className prop", async () => {
|
||||
@@ -142,13 +139,12 @@ describe("Test TimezoneSelect", () => {
|
||||
const element = screen.getByLabelText("Test");
|
||||
element.focus();
|
||||
fireEvent.keyDown(element, { key: "ArrowDown", code: "ArrowDown" });
|
||||
// TODO: optionMockValues[3] was failing
|
||||
screen.getByText(optionMockValues[1]);
|
||||
screen.getByText(optionMockValues[3]);
|
||||
|
||||
const inputEl = screen.getByRole("combobox", { hidden: true }).parentElement;
|
||||
const menuIsOpenEl = inputEl?.parentElement?.nextSibling;
|
||||
expect(menuIsOpenEl).toHaveClass("rotate-180 transition-transform ");
|
||||
const opt = screen.getByText(optionMockValues[1]);
|
||||
const opt = screen.getByText(optionMockValues[3]);
|
||||
fireEvent.click(opt);
|
||||
fireEvent.keyDown(element, { key: "ArrowDown", code: "ArrowDown" });
|
||||
});
|
||||
|
||||
Reference in new issue
Block a user