updates
This commit is contained in:
60
web/util/src/TextFormat.test.ts
Normal file
60
web/util/src/TextFormat.test.ts
Normal file
@@ -0,0 +1,60 @@
|
||||
import TextFormat from "./TextFormat";
|
||||
|
||||
describe("TextFormat", () => {
|
||||
it.each([
|
||||
["Peeter", "Tamm", "Peeter Tamm"],
|
||||
[null, "Tamm", "Tamm"],
|
||||
[undefined, "Tamm", "Tamm"],
|
||||
["", "Tamm", "Tamm"],
|
||||
["Peeter", undefined, "Peeter"],
|
||||
["Peeter", null, "Peeter"],
|
||||
["Peeter", "", "Peeter"],
|
||||
])(
|
||||
"toFullName firstName='%s' lastName='%s' -> '%s'",
|
||||
(firstName, lastName, result) => {
|
||||
expect(TextFormat.toFullName({ firstName, lastName })).toEqual(result);
|
||||
},
|
||||
);
|
||||
|
||||
describe("toTitleCase", () => {
|
||||
test("converts first letter to uppercase", () => {
|
||||
expect(TextFormat.toTitleCase("hello")).toBe("Hello");
|
||||
});
|
||||
|
||||
test("converts each word to title case", () => {
|
||||
expect(TextFormat.toTitleCase("hello world")).toBe("Hello World");
|
||||
});
|
||||
|
||||
test("handles empty string", () => {
|
||||
expect(TextFormat.toTitleCase("")).toBe("");
|
||||
});
|
||||
|
||||
test("handles undefined", () => {
|
||||
expect(TextFormat.toTitleCase(undefined)).toBe("");
|
||||
});
|
||||
|
||||
test("handles already capitalized text", () => {
|
||||
expect(TextFormat.toTitleCase("Hello World")).toBe("Hello World");
|
||||
});
|
||||
|
||||
test("handles mixed case text", () => {
|
||||
expect(TextFormat.toTitleCase("hELLo WoRLd")).toBe("Hello World");
|
||||
});
|
||||
|
||||
test("handles text with apostrophes", () => {
|
||||
expect(TextFormat.toTitleCase("don't stop")).toBe("Don't Stop");
|
||||
});
|
||||
|
||||
test("handles text with hyphens", () => {
|
||||
expect(TextFormat.toTitleCase("well-known fact")).toBe("Well-Known Fact");
|
||||
});
|
||||
|
||||
test("handles single character", () => {
|
||||
expect(TextFormat.toTitleCase("a")).toBe("A");
|
||||
});
|
||||
|
||||
test("handles numbers and special characters", () => {
|
||||
expect(TextFormat.toTitleCase("test123 @#$")).toBe("Test123 @#$");
|
||||
});
|
||||
});
|
||||
});
|
||||
Reference in New Issue
Block a user