Skip to content
This repository has been archived by the owner on Jul 2, 2024. It is now read-only.

Commit

Permalink
Add test
Browse files Browse the repository at this point in the history
  • Loading branch information
sophstad committed Feb 28, 2024
1 parent d7439bd commit 17235c0
Show file tree
Hide file tree
Showing 5 changed files with 36 additions and 9 deletions.
2 changes: 1 addition & 1 deletion src/components/Header/UserDropdown.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ export const UserDropdown = () => {
},
];
if (permissions?.canEditAdminSettings) {
menuItems.splice(1, 0, {
menuItems.splice(2, 0, {
"data-cy": "admin-link",
text: "Admin",
href: adminSettingsURL,
Expand Down
10 changes: 6 additions & 4 deletions src/components/SpruceForm/Widgets/LeafyGreenWidgets.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -225,7 +225,9 @@ export const LeafyGreenRadio: React.FC<EnumSpruceWidgetProps> = ({
} = options;
return (
<ElementWrapper css={elementWrapperCSS}>
<Label htmlFor={id}>{label}</Label>
<LabelContainer>
<Label htmlFor={id}>{label}</Label>
</LabelContainer>
<RadioGroup
data-cy={dataCy}
id={id}
Expand Down Expand Up @@ -278,12 +280,12 @@ export const LeafyGreenRadioBox: React.FC<
return (
<ElementWrapper css={elementWrapperCSS}>
{showLabel !== false && (
<RadioBoxLabelContainer>
<LabelContainer>
<Label htmlFor={id} disabled={disabled}>
{label}
</Label>
{description && <Description>{description}</Description>}
</RadioBoxLabelContainer>
</LabelContainer>
)}
{!!errors && (
<StyledBanner variant="danger" data-cy="error-banner">
Expand Down Expand Up @@ -323,7 +325,7 @@ const StyledBanner = styled(Banner)`
margin-bottom: ${size.s};
`;

const RadioBoxLabelContainer = styled.div`
const LabelContainer = styled.div`
margin-bottom: ${size.xs};
`;

Expand Down
5 changes: 5 additions & 0 deletions src/constants/fieldMaps.ts
Original file line number Diff line number Diff line change
Expand Up @@ -185,6 +185,11 @@ export const dateFormats = listOfDateFormatStrings.map((format) => ({
})}`,
}));

export enum TimeFormat {
TwelveHour = "h:mm:ss aa",
TwentyFourHour = "H:mm:ss",
}

export const notificationFields = {
patchFinish: "Patch finish",
patchFirstFailure: "Patch first task failure",
Expand Down
9 changes: 5 additions & 4 deletions src/pages/preferences/preferencesTabs/ProfileTab.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import { Skeleton } from "antd";
import { usePreferencesAnalytics } from "analytics";
import { SettingsCard } from "components/SettingsCard";
import { SpruceForm } from "components/SpruceForm";
import { timeZones, dateFormats } from "constants/fieldMaps";
import { timeZones, dateFormats, TimeFormat } from "constants/fieldMaps";
import { useToastContext } from "context/toast";
import {
UpdateUserSettingsMutation,
Expand All @@ -27,10 +27,11 @@ export const ProfileTab: React.FC = () => {
dateFormat,
githubUser,
region,
timeFormat = "h:mm:ss aa",
timeFormat: dbTimeFormat,
timezone,
} = userSettings ?? {};
const lastKnownAs = githubUser?.lastKnownAs || "";
const timeFormat = dbTimeFormat || TimeFormat.TwelveHour;

const { data: awsRegionData, loading: awsRegionLoading } =
useQuery<AwsRegionsQuery>(AWS_REGIONS);
Expand Down Expand Up @@ -170,14 +171,14 @@ export const ProfileTab: React.FC = () => {
type: "string" as "string",
title: "12-hour clock",
description: "Display time with AM/PM, e.g. 12:34 PM",
enum: ["h:mm:ss aa"],
enum: [TimeFormat.TwelveHour],
},

{
type: "string" as "string",
title: "24-hour clock",
description: "Use 24-hour notation, e.g. 13:34",
enum: ["H:mm:ss"],
enum: [TimeFormat.TwentyFourHour],
},
],
},
Expand Down
19 changes: 19 additions & 0 deletions src/utils/string/string.test.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import { TimeFormat } from "constants/fieldMaps";
import {
msToDuration,
sortFunctionDate,
Expand Down Expand Up @@ -292,7 +293,25 @@ describe("getDateCopy", () => {
getDateCopy("08/31/1996", { dateFormat: "MM/dd/yyyy", dateOnly: true }),
).toBe("08/31/1996");
});

it("returns dates with a custom time format when supplied with the option", () => {
expect(
getDateCopy(new Date("2020-11-16T22:17:29z"), {
omitTimezone: true,
timeFormat: TimeFormat.TwentyFourHour,
}),
).toBe("Nov 16, 2020, 22:17:29");

expect(
getDateCopy(new Date("2020-11-16T22:17:29z"), {
omitSeconds: true,
omitTimezone: true,
timeFormat: TimeFormat.TwelveHour,
}),
).toBe("Nov 16, 2020, 10:17 PM");
});
});

describe("applyStrictRegex", () => {
it("converts string to strict regex", () => {
expect(applyStrictRegex("dog")).toBe("^dog$");
Expand Down

0 comments on commit 17235c0

Please sign in to comment.