From 205864f66c670653e1d6f26897672f0598306a11 Mon Sep 17 00:00:00 2001 From: Jari Kolehmainen Date: Thu, 29 Oct 2020 18:01:56 +0200 Subject: [PATCH] fixes Signed-off-by: Jari Kolehmainen --- src/common/__tests__/workspace-store.test.ts | 44 ++++++++++---------- src/common/cluster-store.ts | 7 ++-- 2 files changed, 25 insertions(+), 26 deletions(-) diff --git a/src/common/__tests__/workspace-store.test.ts b/src/common/__tests__/workspace-store.test.ts index 8ac3ac599d..97edfa77cf 100644 --- a/src/common/__tests__/workspace-store.test.ts +++ b/src/common/__tests__/workspace-store.test.ts @@ -10,7 +10,7 @@ jest.mock("electron", () => { } }) -import { WorkspaceStore } from "../workspace-store" +import { Workspace, WorkspaceStore } from "../workspace-store" describe("workspace store tests", () => { describe("for an empty config", () => { @@ -35,16 +35,16 @@ describe("workspace store tests", () => { it("cannot remove the default workspace", () => { const ws = WorkspaceStore.getInstance(); - expect(() => ws.removeWorkspace(WorkspaceStore.defaultId)).toThrowError("Cannot remove"); + expect(() => ws.removeWorkspaceById(WorkspaceStore.defaultId)).toThrowError("Cannot remove"); }) it("can update default workspace name", () => { const ws = WorkspaceStore.getInstance(); - ws.saveWorkspace({ + ws.addWorkspace(new Workspace({ id: WorkspaceStore.defaultId, name: "foobar", - }); + })); expect(ws.currentWorkspace.name).toBe("foobar"); }) @@ -52,10 +52,10 @@ describe("workspace store tests", () => { it("can add workspaces", () => { const ws = WorkspaceStore.getInstance(); - ws.saveWorkspace({ + ws.addWorkspace(new Workspace({ id: "123", name: "foobar", - }); + })); expect(ws.getById("123").name).toBe("foobar"); }) @@ -69,10 +69,10 @@ describe("workspace store tests", () => { it("can set a existent workspace to be active", () => { const ws = WorkspaceStore.getInstance(); - ws.saveWorkspace({ + ws.addWorkspace(new Workspace({ id: "abc", name: "foobar", - }); + })); expect(() => ws.setActive("abc")).not.toThrowError(); }) @@ -80,15 +80,15 @@ describe("workspace store tests", () => { it("can remove a workspace", () => { const ws = WorkspaceStore.getInstance(); - ws.saveWorkspace({ + ws.addWorkspace(new Workspace({ id: "123", name: "foobar", - }); - ws.saveWorkspace({ + })); + ws.addWorkspace(new Workspace({ id: "1234", name: "foobar 1", - }); - ws.removeWorkspace("123"); + })); + ws.removeWorkspaceById("123"); expect(ws.workspaces.size).toBe(2); }) @@ -96,10 +96,10 @@ describe("workspace store tests", () => { it("cannot create workspace with existent name", () => { const ws = WorkspaceStore.getInstance(); - ws.saveWorkspace({ + ws.addWorkspace(new Workspace({ id: "someid", name: "default", - }); + })); expect(ws.workspacesList.length).toBe(1); // default workspace only }) @@ -107,10 +107,10 @@ describe("workspace store tests", () => { it("cannot create workspace with empty name", () => { const ws = WorkspaceStore.getInstance(); - ws.saveWorkspace({ + ws.addWorkspace(new Workspace({ id: "random", name: "", - }); + })); expect(ws.workspacesList.length).toBe(1); // default workspace only }) @@ -118,10 +118,10 @@ describe("workspace store tests", () => { it("cannot create workspace with ' ' name", () => { const ws = WorkspaceStore.getInstance(); - ws.saveWorkspace({ + ws.addWorkspace(new Workspace({ id: "random", name: " ", - }); + })); expect(ws.workspacesList.length).toBe(1); // default workspace only }) @@ -129,10 +129,10 @@ describe("workspace store tests", () => { it("trim workspace name", () => { const ws = WorkspaceStore.getInstance(); - ws.saveWorkspace({ + ws.addWorkspace(new Workspace({ id: "random", name: "default ", - }); + })); expect(ws.workspacesList.length).toBe(1); // default workspace only }) @@ -169,4 +169,4 @@ describe("workspace store tests", () => { expect(ws.currentWorkspaceId).toBe("abc"); }) }) -}) \ No newline at end of file +}) diff --git a/src/common/cluster-store.ts b/src/common/cluster-store.ts index 4b3914e404..066bb8f851 100644 --- a/src/common/cluster-store.ts +++ b/src/common/cluster-store.ts @@ -170,14 +170,13 @@ export class ClusterStore extends BaseStore { } @action - addCluster(model: ClusterModel): Cluster { + addCluster(model: ClusterModel | Cluster ): Cluster { appEventBus.emit({name: "cluster", action: "add"}) - let cluster: Cluster = null - if (model instanceof Cluster === false) { + let cluster = model as Cluster; + if (!(model instanceof Cluster)) { cluster = new Cluster(model) } this.clusters.set(model.id, cluster); - return cluster }