From 4393e715b013c5eb7a049525d7db389c457c0160 Mon Sep 17 00:00:00 2001 From: Juho Heikka Date: Thu, 11 May 2023 16:42:30 +0300 Subject: [PATCH] Fix migration using the array slice wrong Signed-off-by: Juho Heikka --- .../main/welcome-page-migration.injectable.ts | 2 +- .../hotbar/storage/storage-technical.test.ts | 29 +++++++++++-------- 2 files changed, 18 insertions(+), 13 deletions(-) diff --git a/packages/core/src/features/hotbar/storage/main/welcome-page-migration.injectable.ts b/packages/core/src/features/hotbar/storage/main/welcome-page-migration.injectable.ts index 33fbaa1f89..acbcbf1283 100644 --- a/packages/core/src/features/hotbar/storage/main/welcome-page-migration.injectable.ts +++ b/packages/core/src/features/hotbar/storage/main/welcome-page-migration.injectable.ts @@ -37,7 +37,7 @@ const welcomePageMigration = getInjectable({ const newFirstHotbar: HotbarData = { ...firstHotbar, - items: [welcomePageHotbarItem, ...firstHotbar.items.slice(-1)], + items: [welcomePageHotbarItem, ...firstHotbar.items.slice(0, -1)], }; store.set("hotbars", [newFirstHotbar, ...hotbars.slice(1)]); diff --git a/packages/core/src/features/hotbar/storage/storage-technical.test.ts b/packages/core/src/features/hotbar/storage/storage-technical.test.ts index 59119147bc..e7a74d362a 100644 --- a/packages/core/src/features/hotbar/storage/storage-technical.test.ts +++ b/packages/core/src/features/hotbar/storage/storage-technical.test.ts @@ -154,21 +154,26 @@ describe("Hotbars technical tests", () => { expect(activeHotbar.get()?.items?.length).toEqual(defaultHotbarCells); }); - it("initially adds catalog entity as first item", () => { - expect(activeHotbar.get()?.items[0]?.entity.name).toEqual("Catalog"); + it("initially adds welcome page entity as first item", () => { + expect(activeHotbar.get()?.items[0]?.entity.name).toEqual("Welcome Page"); + }); + + it("initially adds catalog entity as second item", () => { + expect(activeHotbar.get()?.items[1]?.entity.name).toEqual("Catalog"); }); it("adds items", () => { activeHotbar.get()?.addEntity(testCluster); const items = activeHotbar.get()?.items.filter(Boolean); - expect(items?.length).toEqual(2); + expect(items?.length).toEqual(3); }); it("removes items", () => { activeHotbar.get()?.addEntity(testCluster); activeHotbar.get()?.removeEntity("some-test-id"); activeHotbar.get()?.removeEntity("catalog-entity"); + activeHotbar.get()?.removeEntity("welcome-page-entity"); const items = activeHotbar.get()?.items.filter(Boolean); expect(items).toStrictEqual([]); @@ -179,7 +184,7 @@ describe("Hotbars technical tests", () => { activeHotbar.get()?.removeEntity("invalid uid"); const items = activeHotbar.get()?.items.filter(Boolean); - expect(items?.length).toEqual(2); + expect(items?.length).toEqual(3); }); it("moves item to empty cell", () => { @@ -189,7 +194,7 @@ describe("Hotbars technical tests", () => { expect(activeHotbar.get()?.items[6]).toBeNull(); - activeHotbar.get()?.restack(1, 5); + activeHotbar.get()?.restack(2, 5); expect(activeHotbar.get()?.items[5]).toBeTruthy(); expect(activeHotbar.get()?.items[5]?.entity.uid).toEqual("some-test-id"); @@ -201,11 +206,11 @@ describe("Hotbars technical tests", () => { activeHotbar.get()?.addEntity(awsCluster); // aws -> catalog - activeHotbar.get()?.restack(3, 0); + activeHotbar.get()?.restack(4, 0); const items = activeHotbar.get()?.items.map(item => item?.entity.uid || null); - expect(items?.slice(0, 4)).toEqual(["some-aws-id", "catalog-entity", "some-test-id", "some-minikube-id"]); + expect(items?.slice(0, 5)).toEqual(["some-aws-id", "welcome-page-entity", "catalog-entity", "some-test-id", "some-minikube-id"]); }); it("moves items up", () => { @@ -214,11 +219,11 @@ describe("Hotbars technical tests", () => { activeHotbar.get()?.addEntity(awsCluster); // test -> aws - activeHotbar.get()?.restack(1, 3); + activeHotbar.get()?.restack(2, 4); const items = activeHotbar.get()?.items.map(item => item?.entity.uid || null); - expect(items?.slice(0, 4)).toEqual(["catalog-entity", "some-minikube-id", "some-aws-id", "some-test-id"]); + expect(items?.slice(0, 5)).toEqual(["welcome-page-entity", "catalog-entity", "some-minikube-id", "some-aws-id", "some-test-id"]); }); it("logs an error if cellIndex is out of bounds", () => { @@ -247,15 +252,15 @@ describe("Hotbars technical tests", () => { it("does nothing when item moved to same cell", () => { activeHotbar.get()?.addEntity(testCluster); - activeHotbar.get()?.restack(1, 1); + activeHotbar.get()?.restack(2, 2); - expect(activeHotbar.get()?.items[1]?.entity.uid).toEqual("some-test-id"); + expect(activeHotbar.get()?.items[2]?.entity.uid).toEqual("some-test-id"); }); it("new items takes first empty cell", () => { activeHotbar.get()?.addEntity(testCluster); activeHotbar.get()?.addEntity(awsCluster); - activeHotbar.get()?.restack(0, 3); + activeHotbar.get()?.restack(0, 4); activeHotbar.get()?.addEntity(minikubeCluster); expect(activeHotbar.get()?.items[0]?.entity.uid).toEqual("some-minikube-id");