diff --git a/src/components/JobsHistory/__tests__/JobsHistoryTable.unit.test.tsx b/src/components/JobsHistory/__tests__/JobsHistoryTable.unit.test.tsx index 63ccaaa01..832f16187 100644 --- a/src/components/JobsHistory/__tests__/JobsHistoryTable.unit.test.tsx +++ b/src/components/JobsHistory/__tests__/JobsHistoryTable.unit.test.tsx @@ -45,14 +45,7 @@ describe("JobsHistoryTable", () => { it("renders the table with the correct column headers", () => { render( - + ); expect( @@ -76,20 +69,13 @@ describe("JobsHistoryTable", () => { it("renders the table with the correct data cells", () => { render( - + ); expect( screen.getByRole("cell", { - name: /Job Name1/i + name: /Job Name 1/i }) ).toBeInTheDocument(); expect(screen.getByRole("cell", { name: "2m3s" })).toBeInTheDocument(); @@ -98,7 +84,7 @@ describe("JobsHistoryTable", () => { ).toBeInTheDocument(); expect( - screen.getByRole("cell", { name: /Job Name2/i }) + screen.getByRole("cell", { name: /Job Name 2/i }) ).toBeInTheDocument(); expect(screen.getByRole("cell", { name: "10m54s" })).toBeInTheDocument(); expect( diff --git a/src/utils/__tests__/common.unit.test.ts b/src/utils/__tests__/common.unit.test.ts new file mode 100644 index 000000000..b710679be --- /dev/null +++ b/src/utils/__tests__/common.unit.test.ts @@ -0,0 +1,13 @@ +import { formatJobName } from "../common"; + +describe("formatJobName", () => { + test.each` + word | expected + ${"CleanupCRDDeletedCanaries"} | ${"Cleanup CRD Deleted Canaries"} + ${"CleanupCRDDeletedCanary"} | ${"Cleanup CRD Deleted Canary"} + ${"CleanupCrd DeletedCanary"} | ${"Cleanup Crd Deleted Canary"} + ${"DeleteCanary"} | ${"Delete Canary"} + `("returns $expected when $word is formatted", ({ word, expected }) => { + expect(formatJobName(word)).toBe(expected); + }); +}); diff --git a/src/utils/common.ts b/src/utils/common.ts index 500b49e63..6543fce80 100644 --- a/src/utils/common.ts +++ b/src/utils/common.ts @@ -85,6 +85,14 @@ export const stringSortHelper = (val1: string, val2: string) => { }; export function formatJobName(word: string | null) { - const wordRe = /($[a-z])|[A-Z][^A-Z]+/g; - return word?.match(wordRe)?.join(" "); + return ( + word + ?.split(/([A-Z][a-z]+)/) + .filter(function (e) { + return e; + }) + .join(" ") + // remove extra spaces + .replace(/\s+/g, " ") + ); }