tests(handlers/keys): add integration test draft

This commit is contained in:
Marc Jakobi
2024-06-06 13:33:23 +02:00
parent 2ae43ce880
commit 23986eb7d7
2 changed files with 21 additions and 1 deletions
+2 -1
View File
@@ -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
+19
View File
@@ -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 = "<C-h>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("<Ignore>" .. 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)