Skip to content
This repository has been archived by the owner on Jul 1, 2022. It is now read-only.

Commit

Permalink
Add page-level snapshot
Browse files Browse the repository at this point in the history
Signed-off-by: Jordan Pellizzari <jordan@weave.works>
  • Loading branch information
jpellizzari committed May 19, 2021
1 parent 70f9a61 commit 825f272
Show file tree
Hide file tree
Showing 4 changed files with 685 additions and 3 deletions.
4 changes: 2 additions & 2 deletions ui/lib/hooks/kustomizations.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import _ from "lodash";
import { useContext, useEffect, useState } from "react";
import { AppContext } from "../../components/AppStateProvider";
import { Kustomization, SyncKustomizationRes } from "../rpc/clusters";
import { clustersClient, notifyError, notifySuccess } from "../util";
import { notifyError, notifySuccess } from "../util";
import { formatAPINamespace } from "./app";

type KustomizationList = { [name: string]: Kustomization };
Expand All @@ -12,7 +12,7 @@ export function useKustomizations(
currentNamespace: string
) {
const [loading, setLoading] = useState(true);
const { doAsyncError } = useContext(AppContext);
const { doAsyncError, clustersClient } = useContext(AppContext);
const [kustomizations, setKustomizations] = useState({} as KustomizationList);

useEffect(() => {
Expand Down
7 changes: 6 additions & 1 deletion ui/lib/test-utils.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,17 @@ import * as React from "react";
import { MemoryRouter } from "react-router";
import { ThemeProvider } from "styled-components";
import AppStateProvider from "../components/AppStateProvider";
import { ListContextsRes, ListNamespacesForContextRes } from "./rpc/clusters";
import {
ListContextsRes,
ListKustomizationsRes,
ListNamespacesForContextRes,
} from "./rpc/clusters";
import theme from "./theme";

type ClientOverrides = {
listContexts: ListContextsRes;
listNamespacesForContext: ListNamespacesForContextRes;
listKustomizations?: ListKustomizationsRes;
};

export function withContext(
Expand Down
50 changes: 50 additions & 0 deletions ui/pages/__tests__/KustomizationDetail.test.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
import { render, screen } from "@testing-library/react";
import { Kustomization } from "../../lib/rpc/clusters";
import { withContext } from "../../lib/test-utils";
import KustomizationDetail from "../KustomizationDetail";

describe("KustomizationDetail", () => {
let container;
beforeEach(() => {
container = document.createElement("div");
document.body.appendChild(container);
});
afterEach(() => {
document.body.removeChild(container);
container = null;
});
it("renders", async () => {
const k: Kustomization = {
name: "my-kustomization",
namespace: "default",
path: "/k8s",
sourceref: "my-source",
conditions: [],
interval: "1m",
prune: false,
reconcilerequestat: "",
reconcileat: "",
sourcerefkind: "Git",
};
const url =
"/?context=my-context&namespace=default&kustomizationId=my-kustomization";
const tree = render(
withContext(KustomizationDetail, url, {
listContexts: {
contexts: [{ name: "my-context" }, { name: "other-context" }],
currentcontext: "other-context",
},
listNamespacesForContext: { namespaces: ["default"] },
listKustomizations: {
kustomizations: [k],
},
}),
container
);

expect(
(await screen.findByText("my-kustomization")).textContent
).toBeTruthy();
expect(tree).toMatchSnapshot();
});
});

0 comments on commit 825f272

Please sign in to comment.