From 23986eb7d76113329baf956cde8317cd1217b662 Mon Sep 17 00:00:00 2001 From: Marc Jakobi Date: Thu, 6 Jun 2024 13:33:23 +0200 Subject: [PATCH] tests(handlers/keys): add integration test draft --- lua/lz/n/handler/keys.lua | 3 ++- spec/keys_spec.lua | 19 +++++++++++++++++++ 2 files changed, 21 insertions(+), 1 deletion(-) diff --git a/lua/lz/n/handler/keys.lua b/lua/lz/n/handler/keys.lua index 8d51e96..5b55afb 100644 --- a/lua/lz/n/handler/keys.lua +++ b/lua/lz/n/handler/keys.lua @@ -126,8 +126,9 @@ end ---@param plugin LzPlugin function M.add(plugin) - -- TODO add plugin to M.pending for _, key in pairs(plugin.keys or {}) do + M.pending[key.id] = M.pending[key.id] or {} + M.pending[key.id][plugin.name] = plugin.name add_keys(key) end end diff --git a/spec/keys_spec.lua b/spec/keys_spec.lua index 5c049aa..3aaf824 100644 --- a/spec/keys_spec.lua +++ b/spec/keys_spec.lua @@ -1,4 +1,7 @@ local keys = require("lz.n.handler.keys") +local state = require("lz.n.state") +local loader = require("lz.n.loader") +local spy = require("luassert.spy") describe("keys", function() it("parses ids correctly", function() @@ -15,4 +18,20 @@ describe("keys", function() end end end) + it("Key only loads plugin once", function() + local lhs = "k" + ---@type LzPlugin + local plugin = { + name = "foo", + keys = { keys.parse(lhs) }, + } + local spy_load = spy.on(loader, "_load") + state.plugins[plugin.name] = plugin + keys.add(plugin) + local feed = vim.api.nvim_replace_termcodes("" .. lhs, true, true, true) + vim.api.nvim_feedkeys(feed, "i", false) + vim.api.nvim_feedkeys(feed, "i", false) + assert.spy(spy_load).called(1) + -- + end) end)