mirror of
https://github.com/lensapp/lens.git
synced 2025-05-20 05:10:56 +00:00
Fix migration using the array slice wrong
Signed-off-by: Juho Heikka <juho.heikka@gmail.com>
This commit is contained in:
parent
e97db58eb9
commit
4393e715b0
@ -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)]);
|
||||
|
||||
@ -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");
|
||||
|
||||
Loading…
Reference in New Issue
Block a user