Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions .github/workflows/test-neovim.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ on:
paths:
- 'nvim/.config/nvim/init.lua'
- 'nvim/.config/nvim/lua/config/**'
- 'nvim/.config/nvim/lua/plugins/aesthetics.lua'
- 'nvim/.config/nvim/lazy-lock.json'
- 'tests/daily-note.lua'
- '.github/workflows/test-neovim.yml'
Expand All @@ -14,6 +15,7 @@ on:
paths:
- 'nvim/.config/nvim/init.lua'
- 'nvim/.config/nvim/lua/config/**'
- 'nvim/.config/nvim/lua/plugins/aesthetics.lua'
- 'nvim/.config/nvim/lazy-lock.json'
- 'tests/daily-note.lua'
- '.github/workflows/test-neovim.yml'
Expand Down
7 changes: 7 additions & 0 deletions nvim/.config/nvim/lua/plugins/aesthetics.lua
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,13 @@ return {
},
{
"folke/snacks.nvim",
keys = function(_, keys)
for _, key in ipairs(keys) do
if key[1] == "<leader>n" then
key[1] = "<leader>nh"
end
end
end,
opts = {
dashboard = {
sections = {
Expand Down
28 changes: 28 additions & 0 deletions tests/daily-note.lua
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,24 @@ vim.opt.rtp:prepend(vim.env.SNACKS_TEST_DIR or vim.fn.stdpath("data") .. "/lazy/
require("snacks").setup({})
vim.o.hidden = true
vim.o.columns = 140
vim.g.mapleader = " "

local history_opened = false
local keys = {
{ "<leader>n", function() history_opened = true end, desc = "Notification History" },
}
for _, plugin in ipairs(require("plugins.aesthetics")) do
if plugin[1] == "folke/snacks.nvim" then
plugin.keys(plugin, keys)
end
end
for _, key in ipairs(keys) do
vim.keymap.set("n", key[1], key[2], { desc = key.desc })
end

local directory = vim.fn.tempname()
vim.fn.mkdir(directory, "p")
directory = vim.uv.fs_realpath(directory)

-- Keep repository discovery outside these editor-state regression tests.
vim.system = function()
Expand All @@ -24,6 +39,11 @@ for _, map in ipairs(vim.api.nvim_get_keymap("n")) do
end
end
assert(daily, "daily note mapping was not registered")
assert(vim.fn.maparg("<leader>n", "n") == "", "notification history still consumes the daily note prefix")

local function press(keys)
vim.api.nvim_feedkeys(vim.api.nvim_replace_termcodes(keys, true, false, true), "xt", false)
end

local function assert_prose()
assert(Snacks.zen.win and Snacks.zen.win:valid(), "prose window is missing")
Expand All @@ -33,6 +53,14 @@ local function assert_prose()
end

local function run()
press("<leader>nh")
assert(history_opened, "notification history shortcut did not run")
history_opened = false
press("<leader>nd")
assert(not history_opened, "daily note shortcut opened notification history")
assert(vim.api.nvim_buf_get_name(0) == directory .. "/" .. os.date("%Y-%m-%d.md"), "daily note shortcut did not open today's note")
assert_prose()
Snacks.zen.win:close()
vim.api.nvim_cmd({ cmd = "edit", args = { directory .. "/" .. os.date("%Y-%m-%d.md") } }, {})
local note = vim.api.nvim_get_current_buf()
vim.api.nvim_buf_set_lines(note, 0, -1, false, { "unsaved daily note" })
Expand Down