Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Cluter list test #503

Merged
merged 4 commits into from
Jan 23, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
69 changes: 69 additions & 0 deletions frontend/src/components/ClustersList.cy.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,69 @@
import { AppContextProvider } from "../context/AppContext";
import ClustersList from "./ClustersList";
import { BrowserRouter } from "react-router-dom";
import { QueryClient, QueryClientProvider } from "@tanstack/react-query";
import { Release } from "../data/types";

type ClustersListProps = {
onClusterChange: (clusterName: string) => void;
selectedCluster: string;
filteredNamespaces: string[];
installedReleases?: Release[];
};

const generateTestReleaseData = (): Release => ({
id: "id",
name: "helm-dashboard",
namespace: "default",
revision: 1,
updated: "2024-01-23T15:37:35.0992836+02:00",
status: "deployed",
chart: "helm-dashboard-0.1.10",
chart_name: "helm-dashboard",
chart_ver: "0.1.10",
app_version: "1.3.3",
icon: "https://raw.githubusercontent.com/komodorio/helm-dashboard/main/pkg/dashboard/static/logo.svg",
description: "A GUI Dashboard for Helm by Komodor",
has_tests: true,
chartName: "helm-dashboard",
chartVersion: "0.1.10",
});

const renderClustersList = (props: ClustersListProps) => {
const queryClient = new QueryClient();
cy.mount(
<AppContextProvider>
<BrowserRouter>
<QueryClientProvider client={queryClient}>
<ClustersList {...props} />
</QueryClientProvider>
</BrowserRouter>
</AppContextProvider>
);
};

describe("ClustersList", () => {
it("Got one cluster information", () => {
renderClustersList({
selectedCluster: "minikube",
filteredNamespaces: ["default"],
onClusterChange: () => {},
installedReleases: [generateTestReleaseData()],
});

cy.get(".data-cy-clusterName").contains("minikube");
cy.get(".data-cy-clusterList-namespace").contains("default");
cy.get(".data-cy-clustersInput").should("be.checked");
});

it("Dont have a cluster chekced", () => {
renderClustersList({
selectedCluster: "",
filteredNamespaces: [""],
onClusterChange: () => {},
installedReleases: [generateTestReleaseData()],
});

cy.get(".data-cy-clustersInput").should("not.be.checked");
});
});
6 changes: 3 additions & 3 deletions frontend/src/components/ClustersList.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -112,10 +112,10 @@ function ClustersList({
return (
<span
key={cluster.Name}
className="flex items-center mt-2 text-xs"
className="data-cy-clusterName flex items-center mt-2 text-xs"
>
<input
className="cursor-pointer"
className="cursor-pointer data-cy-clustersInput"
onChange={(e) => {
onClusterChange(e.target.value);
}}
Expand Down Expand Up @@ -154,7 +154,7 @@ function ClustersList({
/>
<label
htmlFor={namespace.name}
className="ml-1"
className="data-cy-clusterList-namespace ml-1"
>{`${namespace.name} [${namespace.amount}]`}</label>
</span>
))}
Expand Down
Loading