Skip to content

Commit

Permalink
tests(handlers/keys): add integration test draft
Browse files Browse the repository at this point in the history
  • Loading branch information
mrcjkb committed Jun 6, 2024
1 parent 2ae43ce commit 23986eb
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 1 deletion.
3 changes: 2 additions & 1 deletion lua/lz/n/handler/keys.lua
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
19 changes: 19 additions & 0 deletions spec/keys_spec.lua
Original file line number Diff line number Diff line change
@@ -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()
Expand All @@ -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)

0 comments on commit 23986eb

Please sign in to comment.