1
0
mirror of https://github.com/lensapp/lens.git synced 2025-05-20 05:10:56 +00:00

Updating the tests

Signed-off-by: Alex Andreev <alex.andreev.email@gmail.com>
This commit is contained in:
Alex Andreev 2021-09-06 11:00:27 +03:00
parent fe1921bfbe
commit 6b188a2c1e

View File

@ -65,9 +65,30 @@ users:
token: kubeconfig-user-q4lm4:xxxyyyy token: kubeconfig-user-q4lm4:xxxyyyy
`; `;
const singleClusterConfig = `
apiVersion: v1
clusters:
- cluster:
server: http://localhost
name: other-cluster
contexts:
- context:
cluster: other-cluster
user: test
name: other-context
current-context: other-context
kind: Config
preferences: {}
users:
- name: test
user:
token: kubeconfig-user-q4lm4:xxxyyyy
`;
let config: KubeConfig; let config: KubeConfig;
describe("<DeleteClusterDialog />", () => { describe("<DeleteClusterDialog />", () => {
describe("Kubeconfig with different clusters", () => {
beforeEach(async () => { beforeEach(async () => {
const mockOpts = { const mockOpts = {
"temp-kube-config": kubeconfig, "temp-kube-config": kubeconfig,
@ -121,7 +142,7 @@ describe("<DeleteClusterDialog />", () => {
const { getByTestId } = render(<DeleteClusterDialog />); const { getByTestId } = render(<DeleteClusterDialog />);
expect(getByTestId("context-warning")).toBeInstanceOf(HTMLElement); expect(getByTestId("current-context-warning")).toBeInstanceOf(HTMLElement);
}); });
it("shows context switcher when deleting current cluster", async () => { it("shows context switcher when deleting current cluster", async () => {
@ -169,4 +190,60 @@ describe("<DeleteClusterDialog />", () => {
expect(getByText("test")).toBeInTheDocument(); expect(getByText("test")).toBeInTheDocument();
expect(getByText("test2")).toBeInTheDocument(); expect(getByText("test2")).toBeInTheDocument();
}); });
it("shows warning for internal kubeconfig cluster", () => {
const cluster = new Cluster({
id: "some-cluster",
contextName: "test",
preferences: {
clusterName: "test"
},
kubeConfigPath: "./temp-kube-config",
});
const spy = jest.spyOn(cluster, "isInLocalKubeconfig").mockImplementation(() => true);
DeleteClusterDialog.open({ cluster, config });
const { getByTestId } = render(<DeleteClusterDialog />);
expect(getByTestId("internal-kubeconfig-warning")).toBeInstanceOf(HTMLElement);
spy.mockRestore();
});
});
describe("Kubeconfig with single cluster", () => {
beforeEach(async () => {
const mockOpts = {
"temp-kube-config": singleClusterConfig,
};
mockFs(mockOpts);
config = new KubeConfig();
config.loadFromString(singleClusterConfig);
});
afterEach(() => {
mockFs.restore();
});
it("shows warning if no other contexts left", () => {
const cluster = new Cluster({
id: "other-cluster",
contextName: "other-context",
preferences: {
clusterName: "other-cluster"
},
kubeConfigPath: "./temp-kube-config",
});
DeleteClusterDialog.open({ cluster, config });
const { getByTestId } = render(<DeleteClusterDialog />);
expect(getByTestId("no-more-contexts-warning")).toBeInstanceOf(HTMLElement);
});
});
}); });