Skip to content

Commit

Permalink
fix: fix incorrect job name
Browse files Browse the repository at this point in the history
Fixes #2356
  • Loading branch information
mainawycliffe authored and moshloop committed Oct 18, 2024
1 parent 868a31f commit 8a1fde2
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 20 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -45,14 +45,7 @@ describe("JobsHistoryTable", () => {
it("renders the table with the correct column headers", () => {
render(
<MemoryRouter>
<JobsHistoryTable
jobs={data}
pageCount={1}
pageIndex={1}
pageSize={1}
sortBy={""}
sortOrder={""}
/>
<JobsHistoryTable jobs={data} pageCount={1} />
</MemoryRouter>
);
expect(
Expand All @@ -76,20 +69,13 @@ describe("JobsHistoryTable", () => {
it("renders the table with the correct data cells", () => {
render(
<MemoryRouter>
<JobsHistoryTable
jobs={data}
pageCount={1}
pageIndex={1}
pageSize={1}
sortBy={""}
sortOrder={""}
/>
<JobsHistoryTable jobs={data} pageCount={1} />
</MemoryRouter>
);

expect(
screen.getByRole("cell", {
name: /Job Name1/i
name: /Job Name 1/i
})
).toBeInTheDocument();
expect(screen.getByRole("cell", { name: "2m3s" })).toBeInTheDocument();
Expand All @@ -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(
Expand Down
13 changes: 13 additions & 0 deletions src/utils/__tests__/common.unit.test.ts
Original file line number Diff line number Diff line change
@@ -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);
});
});
12 changes: 10 additions & 2 deletions src/utils/common.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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, " ")
);
}

0 comments on commit 8a1fde2

Please sign in to comment.