zettelkasten.nvim/lua/zettelkasten/action_spec.lua
Marty Oehme aef7d29997
Add action module
Action module contains the interactions the user can take directly with
the zettelkasten, and which in turn act on the editor.

First action to be taken is the opening of zettel links.
`action.open(mytext)` allows the user to pass in a md/wikilink-formatted
string from which the function will open the first found in the current
buffer.

`action.open_selected()` does the same, but looks at the cursor context
to get its string (the link under current cursor position as of now; in
the future probably also the next link on current line, and the first
link in visual selection)
2020-10-31 14:17:26 +01:00

32 lines
1.1 KiB
Lua

action = require 'zettelkasten.action'
before_each(function() _G.vim = {g = {}, b = {}} end)
after_each(function() _G.vim = nil end)
describe("open", function()
it("should open file in editor if it is a valid link", function()
vim.api = {nvim_command = mock(function() end)}
action.open("[some text](1910271456_link-to-my-file.md)")
assert.spy(vim.api.nvim_command).was_called_with(
"edit 1910271456_link-to-my-file.md")
end)
it("should not fail when no input is available", function()
vim.fn = {expand = function() end}
assert.is_not_error(action.open)
end)
end)
describe("open_selected", function()
it("should open the next link found if no argument passed in", function()
vim.api = {nvim_command = mock(function() end)}
vim.fn = {
expand = function(sure)
return "[" .. sure .. "](1910271456_link-to-my-file.md)"
end
}
action.open_selected()
assert.spy(vim.api.nvim_command).was_called_with(
"edit 1910271456_link-to-my-file.md")
end)
end)