From bf1054bab89e98f19efde7bf19ec1fed2c1e5570 Mon Sep 17 00:00:00 2001 From: Alex Andreev Date: Fri, 7 May 2021 15:46:34 +0300 Subject: [PATCH] Testing migration Signed-off-by: Alex Andreev --- src/common/__tests__/hotbar-store.test.ts | 139 ++++++++++++++++++++++ src/common/hotbar-store.ts | 4 +- src/migrations/hotbar-store/index.ts | 4 +- 3 files changed, 144 insertions(+), 3 deletions(-) diff --git a/src/common/__tests__/hotbar-store.test.ts b/src/common/__tests__/hotbar-store.test.ts index 9a15e9eb67..ab4c41c6bd 100644 --- a/src/common/__tests__/hotbar-store.test.ts +++ b/src/common/__tests__/hotbar-store.test.ts @@ -3,6 +3,27 @@ import { CatalogEntityItem } from "../../renderer/components/+catalog/catalog-en import { ClusterStore } from "../cluster-store"; import { HotbarStore } from "../hotbar-store"; +jest.mock("../../renderer/api/catalog-entity-registry", () => ({ + catalogEntityRegistry: { + items: [ + { + metadata: { + uid: "1dfa26e2ebab15780a3547e9c7fa785c", + name: "mycluster", + source: "local" + } + }, + { + metadata: { + uid: "55b42c3c7ba3b04193416cda405269a5", + name: "my_shiny_cluster", + source: "remote" + } + } + ] + } +})); + const testCluster = { uid: "test", name: "test", @@ -66,6 +87,17 @@ const awsCluster = { } }; +jest.mock("electron", () => { + return { + app: { + getVersion: () => "99.99.99", + getPath: () => "tmp", + getLocale: () => "en", + setLoginItemSettings: (): void => void 0, + } + }; +}); + describe("HotbarStore", () => { beforeEach(() => { ClusterStore.resetInstance(); @@ -243,4 +275,111 @@ describe("HotbarStore", () => { console.error = err; }); }); + + describe("pre beta-4 migrations", () => { + beforeEach(() => { + HotbarStore.resetInstance(); + const mockOpts = { + "tmp": { + "lens-hotbar-store.json": JSON.stringify({ + __internal__: { + migrations: { + version: "5.0.0-beta.3" + } + }, + "hotbars": [ + { + "id": "3caac17f-aec2-4723-9694-ad204465d935", + "name": "myhotbar", + "items": [ + { + "entity": { + "uid": "1dfa26e2ebab15780a3547e9c7fa785c" + } + }, + { + "entity": { + "uid": "55b42c3c7ba3b04193416cda405269a5" + } + }, + { + "entity": { + "uid": "176fd331968660832f62283219d7eb6e" + } + }, + { + "entity": { + "uid": "61c4fb45528840ebad1badc25da41d14", + "name": "user1-context", + "source": "local" + } + }, + { + "entity": { + "uid": "27d6f99fe9e7548a6e306760bfe19969", + "name": "foo2", + "source": "local" + } + }, + null, + { + "entity": { + "uid": "c0b20040646849bb4dcf773e43a0bf27", + "name": "multinode-demo", + "source": "local" + } + }, + null, + null, + null, + null, + null + ] + } + ], + }) + } + }; + + mockFs(mockOpts); + + return HotbarStore.createInstance().load(); + }); + + afterEach(() => { + mockFs.restore(); + }); + + it("allows to retrieve a hotbar", () => { + const hotbar = HotbarStore.getInstance().getById("3caac17f-aec2-4723-9694-ad204465d935"); + + expect(hotbar.id).toBe("3caac17f-aec2-4723-9694-ad204465d935"); + }); + + it("clears cells without entity", () => { + const items = HotbarStore.getInstance().hotbars[0].items; + + expect(items[2]).toBeNull(); + }); + + it("adds extra data to cells with according entity", () => { + const items = HotbarStore.getInstance().hotbars[0].items; + + expect(items[0]).toEqual({ + entity: { + name: "mycluster", + source: "local", + uid: "1dfa26e2ebab15780a3547e9c7fa785c" + } + }); + + expect(items[1]).toEqual({ + entity: { + name: "my_shiny_cluster", + source: "remote", + uid: "55b42c3c7ba3b04193416cda405269a5" + } + }); + }); + }); }); diff --git a/src/common/hotbar-store.ts b/src/common/hotbar-store.ts index 216c363088..b291440a53 100644 --- a/src/common/hotbar-store.ts +++ b/src/common/hotbar-store.ts @@ -8,8 +8,8 @@ import isNull from "lodash/isNull"; export interface HotbarItem { entity: { uid: string; - name: string; - source: string; + name?: string; + source?: string; }; params?: { [key: string]: string; diff --git a/src/migrations/hotbar-store/index.ts b/src/migrations/hotbar-store/index.ts index 842f144a18..57f0c2a67a 100644 --- a/src/migrations/hotbar-store/index.ts +++ b/src/migrations/hotbar-store/index.ts @@ -2,8 +2,10 @@ import version500alpha0 from "./5.0.0-alpha.0"; import version500alpha2 from "./5.0.0-alpha.2"; +import version500beta4 from "./5.0.0-beta.4"; export default { ...version500alpha0, - ...version500alpha2 + ...version500alpha2, + ...version500beta4 };