Skip to content

Commit

Permalink
add tests
Browse files Browse the repository at this point in the history
  • Loading branch information
joshri committed Sep 14, 2022
1 parent 4c62e03 commit 429dc7b
Show file tree
Hide file tree
Showing 2 changed files with 48 additions and 16 deletions.
29 changes: 13 additions & 16 deletions ui/components/AlertsTable.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -66,22 +66,19 @@ function AlertsTable({ className, rows = [] }: Props) {
return (
<ul className="event-sources">
{a?.eventSources?.map((obj: CrossNamespaceObjectRef, index) => {
if (obj.name && obj.namespace && obj.kind)
return (
<Link
className="event-sources"
key={index}
to={makeEventSourceLink(obj)}
>
{obj.kind}: {obj.namespace}/{obj.name}
</Link>
);
else
return (
<li className="event-sources" key={index}>
{obj.kind}: {obj.namespace}/{obj.name}
</li>
);
obj.name && obj.namespace && obj.kind ? (
<Link
className="event-sources"
key={index}
to={makeEventSourceLink(obj)}
>
{obj.kind}: {obj.namespace}/{obj.name}
</Link>
) : (
<li className="event-sources" key={index}>
{obj.kind}: {obj.namespace}/{obj.name}
</li>
);
})}
</ul>
);
Expand Down
35 changes: 35 additions & 0 deletions ui/components/__tests__/AlertsTable.test.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
import { makeEventSourceLink } from "../AlertsTable";

describe("AlertsTable", () => {
describe("makeEventSourceLink", () => {
it("should convert CrossNamespaceRef objects to urls with filters", () => {
const allNames = {
apiVersion: "v1",
name: "*",
namespace: "space",
kind: "GitRepository",
matchLabels: [],
};
const sourceLink = makeEventSourceLink(allNames);
expect(sourceLink.includes("/sources")).toEqual(true);
expect(
sourceLink.includes("type") && sourceLink.includes("GitRepository")
).toEqual(true);
console.log(sourceLink);
expect(sourceLink.includes("*")).toEqual(false);
const allNamespaces = {
apiVersion: "v1",
name: "goose",
namespace: "*",
kind: "HelmRelease",
matchLabels: [],
};
const automationLink = makeEventSourceLink(allNamespaces);
expect(automationLink.includes("/applications")).toEqual(true);
expect(
automationLink.includes("name") && automationLink.includes("goose")
).toEqual(true);
expect(automationLink.includes("namespace")).toEqual(false);
});
});
});

0 comments on commit 429dc7b

Please sign in to comment.