mirror of
https://github.com/lensapp/lens.git
synced 2025-05-20 05:10:56 +00:00
Add behaviours for clsuter status screen
Signed-off-by: Sebastian Malton <sebastian@malton.name>
This commit is contained in:
parent
6b09ee4937
commit
eb3b260cf5
@ -8,6 +8,7 @@ import type { ClusterStore } from "../../common/cluster-store/cluster-store";
|
|||||||
import clusterStoreInjectable from "../../common/cluster-store/cluster-store.injectable";
|
import clusterStoreInjectable from "../../common/cluster-store/cluster-store.injectable";
|
||||||
import type { ClusterId } from "../../common/cluster-types";
|
import type { ClusterId } from "../../common/cluster-types";
|
||||||
import type { Cluster } from "../../common/cluster/cluster";
|
import type { Cluster } from "../../common/cluster/cluster";
|
||||||
|
import type { NavigateToClusterView } from "../../common/front-end-routing/routes/cluster-view/navigate-to-cluster-view.injectable";
|
||||||
import navigateToClusterViewInjectable from "../../common/front-end-routing/routes/cluster-view/navigate-to-cluster-view.injectable";
|
import navigateToClusterViewInjectable from "../../common/front-end-routing/routes/cluster-view/navigate-to-cluster-view.injectable";
|
||||||
import type { ReadFileSync } from "../../common/fs/read-file-sync.injectable";
|
import type { ReadFileSync } from "../../common/fs/read-file-sync.injectable";
|
||||||
import readFileSyncInjectable from "../../common/fs/read-file-sync.injectable";
|
import readFileSyncInjectable from "../../common/fs/read-file-sync.injectable";
|
||||||
@ -19,8 +20,10 @@ describe("cluster connection status", () => {
|
|||||||
let clusterStore: ClusterStore;
|
let clusterStore: ClusterStore;
|
||||||
let clusters: Map<ClusterId, Cluster>;
|
let clusters: Map<ClusterId, Cluster>;
|
||||||
let cluster: Cluster;
|
let cluster: Cluster;
|
||||||
|
let cluster2: Cluster;
|
||||||
let applicationBuilder: ApplicationBuilder;
|
let applicationBuilder: ApplicationBuilder;
|
||||||
let result: RenderResult;
|
let result: RenderResult;
|
||||||
|
let navigateToClusterView: NavigateToClusterView;
|
||||||
|
|
||||||
beforeEach(async () => {
|
beforeEach(async () => {
|
||||||
applicationBuilder = getApplicationBuilder();
|
applicationBuilder = getApplicationBuilder();
|
||||||
@ -36,13 +39,22 @@ describe("cluster connection status", () => {
|
|||||||
server: "https://192.168.64.3:8443",
|
server: "https://192.168.64.3:8443",
|
||||||
},
|
},
|
||||||
}],
|
}],
|
||||||
contexts: [{
|
contexts: [
|
||||||
context: {
|
{
|
||||||
cluster: "minikube",
|
context: {
|
||||||
user: "minikube",
|
cluster: "minikube",
|
||||||
|
user: "minikube",
|
||||||
|
},
|
||||||
|
name: "minikube",
|
||||||
},
|
},
|
||||||
name: "minikube",
|
{
|
||||||
}],
|
context: {
|
||||||
|
cluster: "minikube",
|
||||||
|
user: "minikube",
|
||||||
|
},
|
||||||
|
name: "minikube-2",
|
||||||
|
},
|
||||||
|
],
|
||||||
users: [{
|
users: [{
|
||||||
name: "minikube",
|
name: "minikube",
|
||||||
}],
|
}],
|
||||||
@ -53,32 +65,47 @@ describe("cluster connection status", () => {
|
|||||||
|
|
||||||
applicationBuilder.dis.rendererDi.override(readFileSyncInjectable, () => readFileSyncMock);
|
applicationBuilder.dis.rendererDi.override(readFileSyncInjectable, () => readFileSyncMock);
|
||||||
|
|
||||||
clusterStore = ({
|
applicationBuilder.beforeRender(() => {
|
||||||
clusters,
|
clusterStore = ({
|
||||||
get clustersList() {
|
clusters,
|
||||||
return [...clusters.values()];
|
get clustersList() {
|
||||||
},
|
return [...clusters.values()];
|
||||||
getById: (id) => clusters.get(id),
|
},
|
||||||
}) as ClusterStore;
|
getById: (id) => clusters.get(id),
|
||||||
|
}) as ClusterStore;
|
||||||
|
|
||||||
applicationBuilder.dis.mainDi.override(clusterStoreInjectable, () => clusterStore);
|
applicationBuilder.dis.mainDi.override(clusterStoreInjectable, () => clusterStore);
|
||||||
applicationBuilder.dis.rendererDi.override(clusterStoreInjectable, () => clusterStore);
|
applicationBuilder.dis.rendererDi.override(clusterStoreInjectable, () => clusterStore);
|
||||||
|
|
||||||
result = await applicationBuilder.render();
|
navigateToClusterView = applicationBuilder.dis.rendererDi.inject(navigateToClusterViewInjectable);
|
||||||
|
|
||||||
const createCluster = applicationBuilder.dis.rendererDi.inject(createClusterInjectable);
|
const createCluster = applicationBuilder.dis.rendererDi.inject(createClusterInjectable);
|
||||||
|
|
||||||
cluster = createCluster({
|
cluster = createCluster({
|
||||||
contextName: "minikube",
|
contextName: "minikube",
|
||||||
id: "some-cluster-id",
|
id: "some-cluster-id",
|
||||||
kubeConfigPath: "/some/file/path",
|
kubeConfigPath: "/some/file/path",
|
||||||
}, {
|
}, {
|
||||||
clusterServerUrl: "https://localhost:1234",
|
clusterServerUrl: "https://localhost:1234",
|
||||||
|
});
|
||||||
|
cluster.activate = jest.fn(); // override for test
|
||||||
|
|
||||||
|
cluster2 = createCluster({
|
||||||
|
contextName: "minikube-2",
|
||||||
|
id: "some-cluster-id",
|
||||||
|
kubeConfigPath: "/some/file/path",
|
||||||
|
}, {
|
||||||
|
clusterServerUrl: "https://localhost:1234",
|
||||||
|
});
|
||||||
|
cluster2.activate = jest.fn(); // override for test
|
||||||
|
|
||||||
|
clusters = new Map([
|
||||||
|
[cluster.id, cluster],
|
||||||
|
[cluster2.id, cluster2],
|
||||||
|
]);
|
||||||
});
|
});
|
||||||
|
|
||||||
clusters = new Map();
|
result = await applicationBuilder.render();
|
||||||
|
|
||||||
clusters.set(cluster.id, cluster);
|
|
||||||
});
|
});
|
||||||
|
|
||||||
it("renders", () => {
|
it("renders", () => {
|
||||||
@ -87,8 +114,6 @@ describe("cluster connection status", () => {
|
|||||||
|
|
||||||
describe("when navigating to cluster connection", () => {
|
describe("when navigating to cluster connection", () => {
|
||||||
beforeEach(() => {
|
beforeEach(() => {
|
||||||
const navigateToClusterView = applicationBuilder.dis.rendererDi.inject(navigateToClusterViewInjectable);
|
|
||||||
|
|
||||||
navigateToClusterView(cluster.id);
|
navigateToClusterView(cluster.id);
|
||||||
});
|
});
|
||||||
|
|
||||||
@ -99,5 +124,73 @@ describe("cluster connection status", () => {
|
|||||||
it("shows cluster status screen", () => {
|
it("shows cluster status screen", () => {
|
||||||
expect(result.queryByTestId("cluster-status")).not.toBeNull();
|
expect(result.queryByTestId("cluster-status")).not.toBeNull();
|
||||||
});
|
});
|
||||||
|
|
||||||
|
describe("when a connection update has been broadcast for first cluster", () => {
|
||||||
|
beforeEach(() => {
|
||||||
|
cluster.broadcastConnectUpdate("some-connection-update");
|
||||||
|
});
|
||||||
|
|
||||||
|
it("shows connection update", async () => {
|
||||||
|
await result.findByText("some-connection-update");
|
||||||
|
});
|
||||||
|
|
||||||
|
describe("when navigating to a different cluster", () => {
|
||||||
|
beforeEach(() => {
|
||||||
|
navigateToClusterView(cluster2.id);
|
||||||
|
});
|
||||||
|
|
||||||
|
it("renders", () => {
|
||||||
|
expect(result.baseElement).toMatchSnapshot();
|
||||||
|
});
|
||||||
|
|
||||||
|
it("shows cluster status screen", () => {
|
||||||
|
expect(result.queryByTestId("cluster-status")).not.toBeNull();
|
||||||
|
});
|
||||||
|
|
||||||
|
it("does not show connection update for first cluster", () => {
|
||||||
|
expect(result.queryByText("some-connection-update")).toBeNull();
|
||||||
|
});
|
||||||
|
|
||||||
|
describe("when connection update has been broadcast for second cluster", () => {
|
||||||
|
beforeEach(() => {
|
||||||
|
cluster2.broadcastConnectUpdate("some-different-connection-update");
|
||||||
|
});
|
||||||
|
|
||||||
|
it("shows connection update", async () => {
|
||||||
|
await result.findByText("some-different-connection-update");
|
||||||
|
});
|
||||||
|
|
||||||
|
describe("when navigating back to first cluster", () => {
|
||||||
|
beforeEach(() => {
|
||||||
|
navigateToClusterView(cluster.id);
|
||||||
|
});
|
||||||
|
|
||||||
|
it("shows conncection update for first cluster", async () => {
|
||||||
|
await result.findByText("some-connection-update");
|
||||||
|
});
|
||||||
|
|
||||||
|
describe("when second cluster connects", () => {
|
||||||
|
beforeEach(() => {
|
||||||
|
cluster2.disconnected = false;
|
||||||
|
});
|
||||||
|
|
||||||
|
it("shows conncection update for first cluster", async () => {
|
||||||
|
await result.findByText("some-connection-update");
|
||||||
|
});
|
||||||
|
|
||||||
|
describe("when second cluster disconnects", () => {
|
||||||
|
beforeEach(() => {
|
||||||
|
cluster2.disconnected = false;
|
||||||
|
});
|
||||||
|
|
||||||
|
it("shows conncection update for first cluster", async () => {
|
||||||
|
await result.findByText("some-connection-update");
|
||||||
|
});
|
||||||
|
});
|
||||||
|
});
|
||||||
|
});
|
||||||
|
});
|
||||||
|
});
|
||||||
|
});
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user