Fix hotbar migration of workspaces (#3178)

This commit is contained in:
Sebastian Malton authored and GitHub committed 2021-06-25 09:55:25 -04:00
1 parent b9dfd20a93
commit 51655884c7
39 files changed
+333 -446

No files matched your search

+8 -8
View File
@@ -95,7 +95,7 @@ describe("empty config", () => {
mockFs(mockOpts);
await ClusterStore.createInstance().load();
ClusterStore.createInstance();
});
afterEach(() => {
@@ -203,7 +203,7 @@ describe("config with existing clusters", () => {
mockFs(mockOpts);
return ClusterStore.createInstance().load();
return ClusterStore.createInstance();
});
afterEach(() => {
@@ -285,7 +285,7 @@ users:
mockFs(mockOpts);
return ClusterStore.createInstance().load();
return ClusterStore.createInstance();
});
afterEach(() => {
@@ -344,7 +344,7 @@ describe("pre 2.0 config with an existing cluster", () => {
mockFs(mockOpts);
return ClusterStore.createInstance().load();
return ClusterStore.createInstance();
});
afterEach(() => {
@@ -414,7 +414,7 @@ describe("pre 2.6.0 config with a cluster that has arrays in auth config", () =>
mockFs(mockOpts);
return ClusterStore.createInstance().load();
return ClusterStore.createInstance();
});
afterEach(() => {
@@ -456,7 +456,7 @@ describe("pre 2.6.0 config with a cluster icon", () => {
mockFs(mockOpts);
return ClusterStore.createInstance().load();
return ClusterStore.createInstance();
});
afterEach(() => {
@@ -495,7 +495,7 @@ describe("for a pre 2.7.0-beta.0 config without a workspace", () => {
mockFs(mockOpts);
return ClusterStore.createInstance().load();
return ClusterStore.createInstance();
});
afterEach(() => {
@@ -531,7 +531,7 @@ describe("pre 3.6.0-beta.1 config with an existing cluster", () => {
mockFs(mockOpts);
return ClusterStore.createInstance().load();
return ClusterStore.createInstance();
});
afterEach(() => {
+34 -34
View File
@@ -23,7 +23,7 @@ import mockFs from "mock-fs";
import { ClusterStore } from "../cluster-store";
import { HotbarStore } from "../hotbar-store";
jest.mock("../../renderer/api/catalog-entity-registry", () => ({
jest.mock("../../main/catalog/catalog-entity-registry", () => ({
catalogEntityRegistry: {
items: [
{
@@ -39,7 +39,14 @@ jest.mock("../../renderer/api/catalog-entity-registry", () => ({
name: "my_shiny_cluster",
source: "remote"
}
}
},
{
metadata: {
uid: "catalog-entity",
name: "Catalog",
source: "app"
},
},
]
}
}));
@@ -120,29 +127,31 @@ jest.mock("electron", () => {
describe("HotbarStore", () => {
beforeEach(() => {
ClusterStore.resetInstance();
mockFs({
"tmp": {
"lens-hotbar-store.json": JSON.stringify({})
}
});
ClusterStore.createInstance();
HotbarStore.resetInstance();
mockFs({ tmp: { "lens-hotbar-store.json": "{}" } });
HotbarStore.createInstance();
});
afterEach(() => {
ClusterStore.resetInstance();
HotbarStore.resetInstance();
mockFs.restore();
});
describe("load", () => {
it("loads one hotbar by default", () => {
HotbarStore.createInstance().load();
expect(HotbarStore.getInstance().hotbars.length).toEqual(1);
});
});
describe("add", () => {
it("adds a hotbar", () => {
const hotbarStore = HotbarStore.createInstance();
const hotbarStore = HotbarStore.getInstance();
hotbarStore.load();
hotbarStore.add({ name: "hottest" });
expect(hotbarStore.hotbars.length).toEqual(2);
});
@@ -150,23 +159,20 @@ describe("HotbarStore", () => {
describe("hotbar items", () => {
it("initially creates 12 empty cells", () => {
const hotbarStore = HotbarStore.createInstance();
const hotbarStore = HotbarStore.getInstance();
hotbarStore.load();
expect(hotbarStore.getActive().items.length).toEqual(12);
});
it("initially adds catalog entity as first item", () => {
const hotbarStore = HotbarStore.createInstance();
const hotbarStore = HotbarStore.getInstance();
hotbarStore.load();
expect(hotbarStore.getActive().items[0].entity.name).toEqual("Catalog");
});
it("adds items", () => {
const hotbarStore = HotbarStore.createInstance();
const hotbarStore = HotbarStore.getInstance();
hotbarStore.load();
hotbarStore.addToHotbar(testCluster);
const items = hotbarStore.getActive().items.filter(Boolean);
@@ -174,9 +180,8 @@ describe("HotbarStore", () => {
});
it("removes items", () => {
const hotbarStore = HotbarStore.createInstance();
const hotbarStore = HotbarStore.getInstance();
hotbarStore.load();
hotbarStore.addToHotbar(testCluster);
hotbarStore.removeFromHotbar("test");
hotbarStore.removeFromHotbar("catalog-entity");
@@ -186,9 +191,8 @@ describe("HotbarStore", () => {
});
it("does nothing if removing with invalid uid", () => {
const hotbarStore = HotbarStore.createInstance();
const hotbarStore = HotbarStore.getInstance();
hotbarStore.load();
hotbarStore.addToHotbar(testCluster);
hotbarStore.removeFromHotbar("invalid uid");
const items = hotbarStore.getActive().items.filter(Boolean);
@@ -197,9 +201,8 @@ describe("HotbarStore", () => {
});
it("moves item to empty cell", () => {
const hotbarStore = HotbarStore.createInstance();
const hotbarStore = HotbarStore.getInstance();
hotbarStore.load();
hotbarStore.addToHotbar(testCluster);
hotbarStore.addToHotbar(minikubeCluster);
hotbarStore.addToHotbar(awsCluster);
@@ -213,9 +216,8 @@ describe("HotbarStore", () => {
});
it("moves items down", () => {
const hotbarStore = HotbarStore.createInstance();
const hotbarStore = HotbarStore.getInstance();
hotbarStore.load();
hotbarStore.addToHotbar(testCluster);
hotbarStore.addToHotbar(minikubeCluster);
hotbarStore.addToHotbar(awsCluster);
@@ -229,9 +231,8 @@ describe("HotbarStore", () => {
});
it("moves items up", () => {
const hotbarStore = HotbarStore.createInstance();
const hotbarStore = HotbarStore.getInstance();
hotbarStore.load();
hotbarStore.addToHotbar(testCluster);
hotbarStore.addToHotbar(minikubeCluster);
hotbarStore.addToHotbar(awsCluster);
@@ -245,9 +246,8 @@ describe("HotbarStore", () => {
});
it("does nothing when item moved to same cell", () => {
const hotbarStore = HotbarStore.createInstance();
const hotbarStore = HotbarStore.getInstance();
hotbarStore.load();
hotbarStore.addToHotbar(testCluster);
hotbarStore.restackItems(1, 1);
@@ -255,9 +255,8 @@ describe("HotbarStore", () => {
});
it("new items takes first empty cell", () => {
const hotbarStore = HotbarStore.createInstance();
const hotbarStore = HotbarStore.getInstance();
hotbarStore.load();
hotbarStore.addToHotbar(testCluster);
hotbarStore.addToHotbar(awsCluster);
hotbarStore.restackItems(0, 3);
@@ -268,13 +267,13 @@ describe("HotbarStore", () => {
it("throws if invalid arguments provided", () => {
// Prevent writing to stderr during this render.
const err = console.error;
const { error, warn } = console;
console.error = jest.fn();
console.warn = jest.fn();
const hotbarStore = HotbarStore.createInstance();
const hotbarStore = HotbarStore.getInstance();
hotbarStore.load();
hotbarStore.addToHotbar(testCluster);
expect(() => hotbarStore.restackItems(-5, 0)).toThrow();
@@ -283,7 +282,8 @@ describe("HotbarStore", () => {
expect(() => hotbarStore.restackItems(11, 112)).toThrow();
// Restore writing to stderr.
console.error = err;
console.error = error;
console.warn = warn;
});
});
@@ -354,7 +354,7 @@ describe("HotbarStore", () => {
mockFs(mockOpts);
return HotbarStore.createInstance().load();
HotbarStore.createInstance();
});
afterEach(() => {
+3 -5
View File
@@ -52,7 +52,7 @@ describe("user store tests", () => {
(UserStore.createInstance() as any).refreshNewContexts = jest.fn(() => Promise.resolve());
return UserStore.getInstance().load();
UserStore.getInstance();
});
afterEach(() => {
@@ -81,10 +81,8 @@ describe("user store tests", () => {
it("correctly resets theme to default value", async () => {
const us = UserStore.getInstance();
us.isLoaded = true;
us.colorTheme = "some other theme";
await us.resetTheme();
us.resetTheme();
expect(us.colorTheme).toBe(UserStore.defaultTheme);
});
@@ -111,7 +109,7 @@ describe("user store tests", () => {
}
});
return UserStore.createInstance().load();
UserStore.createInstance();
});
afterEach(() => {