Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion frontend/src/pages/Settings/Providers/components.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@ import {
Text as MantineText,
} from "@mantine/core";
import { useForm } from "@mantine/form";
import { capitalize } from "lodash";
import { Selector } from "@/components";
import { useModals, withModal } from "@/modules/modals";
import {
Expand All @@ -42,6 +41,7 @@ import {
SettingsProvider,
useSettings,
} from "@/pages/Settings/utilities/SettingsProvider";
import { capitalize } from "@/utilities";
import { BuildKey, useSelectorOptions } from "@/utilities";
import { ASSERT } from "@/utilities/console";
import { ProviderInfo, ProviderList } from "./list";
Expand Down
2 changes: 1 addition & 1 deletion frontend/src/pages/Settings/components/pathMapper.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ import { Button } from "@mantine/core";
import { faArrowCircleRight, faTrash } from "@fortawesome/free-solid-svg-icons";
import { FontAwesomeIcon } from "@fortawesome/react-fontawesome";
import { ColumnDef } from "@tanstack/react-table";
import { capitalize } from "lodash";
import { Action, FileBrowser } from "@/components";
import SimpleTable from "@/components/tables/SimpleTable";
import {
Expand All @@ -14,6 +13,7 @@ import {
} from "@/pages/Settings/keys";
import { useFormActions } from "@/pages/Settings/utilities/FormValues";
import { useSettingValue } from "@/pages/Settings/utilities/hooks";
import { capitalize } from "@/utilities";
import { useArrayAction } from "@/utilities";
import { Message } from "./Message";

Expand Down
1 change: 1 addition & 0 deletions frontend/src/utilities/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -70,3 +70,4 @@ export function toPython(value: boolean): PythonBoolean {
export * from "./env";
export * from "./hooks";
export * from "./validate";
export * from "./strings";
38 changes: 38 additions & 0 deletions frontend/src/utilities/strings.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
import { describe, expect, it } from "vitest";
import { capitalize } from "./strings";

describe("capitalize", () => {
it("should capitalize the first letter of a string", () => {
expect(capitalize("hello")).toBe("Hello");
expect(capitalize("world")).toBe("World");
});

it("should return an empty string if given an empty string", () => {
expect(capitalize("")).toBe("");
});

it("should handle already capitalized strings", () => {
expect(capitalize("Hello")).toBe("Hello");
expect(capitalize("World")).toBe("World");
});

it("should handle single character strings", () => {
expect(capitalize("a")).toBe("A");
expect(capitalize("z")).toBe("Z");
});

it("should keep subsequent capital letters unchanged", () => {
expect(capitalize("javaScript")).toBe("Javascript");
expect(capitalize("reactJS")).toBe("Reactjs");
});

it("should handle strings with leading spaces", () => {
expect(capitalize(" hello")).toBe(" hello");
expect(capitalize(" world")).toBe(" world");
});

it("should handle non-letter characters at the beginning", () => {
expect(capitalize("123abc")).toBe("123abc");
expect(capitalize("!test")).toBe("!test");
});
});
5 changes: 5 additions & 0 deletions frontend/src/utilities/strings.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
export const capitalize = (string: string) => {
return string
? string.charAt(0).toUpperCase() + string.slice(1).toLowerCase()
: "";
};