From 41ef719b3e3c15ecbaf069b9852ba304101d5881 Mon Sep 17 00:00:00 2001 From: Shin'ya Ueoka Date: Tue, 20 Feb 2024 14:27:17 +0000 Subject: [PATCH] fix: validate keymap props --- src/background/settings/Validator.ts | 2 +- test/background/settings/Validator.test.ts | 10 ++++---- test/shared/Keymaps.test.ts | 30 +++++++++++----------- 3 files changed, 21 insertions(+), 21 deletions(-) diff --git a/src/background/settings/Validator.ts b/src/background/settings/Validator.ts index 7e237cd1..663a5219 100644 --- a/src/background/settings/Validator.ts +++ b/src/background/settings/Validator.ts @@ -27,7 +27,7 @@ export default class Validator { }); const keymapEntries = settings.keymaps?.entries() || []; - keymapEntries.forEach(([key, { type, ...props }]) => { + keymapEntries.forEach(([key, { type, props }]) => { const op = this.operatorRegistory.getOperator(type); if (typeof op === "undefined") { throw new Error("Unknown keymap: " + type); diff --git a/test/background/settings/Validator.test.ts b/test/background/settings/Validator.test.ts index 764134bf..1ae15a30 100644 --- a/test/background/settings/Validator.test.ts +++ b/test/background/settings/Validator.test.ts @@ -20,9 +20,9 @@ describe("Validator", () => { sut.validate({}); sut.validate({ keymaps: new Keymaps({ - d: { type: "tabs.close" }, - D: { type: "tabs.close", select: "left" }, - zd: { type: "tabs.duplicate" }, + d: { type: "tabs.close", props: {} }, + D: { type: "tabs.close", props: { select: "left" } }, + zd: { type: "tabs.duplicate", props: {} }, }), search: new Search("google", { google: "https://google.com/search?q={}", @@ -65,7 +65,7 @@ describe("Validator", () => { expect(() => { sut.validate({ keymaps: new Keymaps({ - d: { type: "harakiri" }, + d: { type: "harakiri", props: {} }, }), }); }).toThrowError("Unknown keymap: harakiri"); @@ -73,7 +73,7 @@ describe("Validator", () => { expect(() => { sut.validate({ keymaps: new Keymaps({ - D: { type: "tabs.close", force: "1" }, + D: { type: "tabs.close", props: { force: "1" }} , }), }); }).toThrowError( diff --git a/test/shared/Keymaps.test.ts b/test/shared/Keymaps.test.ts index 5f7243f9..69c9fab7 100644 --- a/test/shared/Keymaps.test.ts +++ b/test/shared/Keymaps.test.ts @@ -4,12 +4,12 @@ describe("Keymaps", () => { describe("#combine", () => { it("returns combined keymaps", () => { const keymaps1 = new Keymaps({ - k: { type: "scroll.vertically", count: -1 }, - j: { type: "scroll.vertically", count: 1 }, + k: { type: "scroll.vertically", props: { count: -1 } }, + j: { type: "scroll.vertically", props: { count: 1 } }, }); const keymap2 = new Keymaps({ - n: { type: "find.next" }, - N: { type: "find.prev" }, + n: { type: "find.next", props: {} }, + N: { type: "find.prev", props: {} }, }); const combined = keymaps1.combine(keymap2); @@ -17,21 +17,21 @@ describe("Keymaps", () => { .entries() .sort(([name1], [name2]) => name1.localeCompare(name2)); expect(entries).toEqual([ - ["j", { type: "scroll.vertically", count: 1 }], - ["k", { type: "scroll.vertically", count: -1 }], - ["n", { type: "find.next" }], - ["N", { type: "find.prev" }], + ["j", { type: "scroll.vertically", props: { count: 1 } }], + ["k", { type: "scroll.vertically", props: { count: -1 } }], + ["n", { type: "find.next", props: {} }], + ["N", { type: "find.prev", props: {} }], ]); }); it("overrides current keymaps", () => { const keymaps1 = new Keymaps({ - k: { type: "scroll.vertically", count: -1 }, - j: { type: "scroll.vertically", count: 1 }, + k: { type: "scroll.vertically", props: { count: -1 } }, + j: { type: "scroll.vertically", props: { count: 1 } }, }); const keymap2 = new Keymaps({ - n: { type: "find.next" }, - j: { type: "find.prev" }, + n: { type: "find.next", props: {} }, + j: { type: "find.prev", props: {} }, }); const combined = keymaps1.combine(keymap2); @@ -39,9 +39,9 @@ describe("Keymaps", () => { .entries() .sort(([name1], [name2]) => name1.localeCompare(name2)); expect(entries).toEqual([ - ["j", { type: "find.prev" }], - ["k", { type: "scroll.vertically", count: -1 }], - ["n", { type: "find.next" }], + ["j", { type: "find.prev", props: {} }], + ["k", { type: "scroll.vertically", props: { count: -1 } }], + ["n", { type: "find.next", props: {} }], ]); }); });