hephaestus/heph.nvim/tests/e2e/view_spec.lua

57 lines
2.4 KiB
Lua
Raw Normal View History

-- Filter views (tech-spec §8.2): `:Heph view <name>` renders a built-in slice.
local h = require("e2e.helpers")
describe("filter views", function()
local ctx
before_each(function()
ctx = h.start()
end)
after_each(function()
h.stop(ctx)
end)
it("renders the Top of Mind view (red|orange, not blue)", function()
ctx.q:call("task.create", { title = "urgent thing", attention = "red" })
ctx.q:call("task.create", { title = "warm thing", attention = "orange" })
ctx.q:call("task.create", { title = "cool thing", attention = "blue" })
-- The backend view returns just the red + orange tasks.
local rows = ctx.q:call("view", { name = "tom" })
assert.are.equal(2, #rows)
-- The plugin renders them into a dedicated view buffer.
require("heph.view").view("tom")
local buf = vim.api.nvim_get_current_buf()
assert.is_truthy(
vim.api.nvim_buf_get_name(buf):find("heph://view/tom", 1, true),
"view buffer not named heph://view/tom"
)
local text = table.concat(vim.api.nvim_buf_get_lines(buf, 0, -1, false), "\n")
assert.is_truthy(text:find("urgent thing", 1, true), "red task missing from ToM")
assert.is_truthy(text:find("warm thing", 1, true), "orange task missing from ToM")
assert.is_falsy(text:find("cool thing", 1, true), "blue task should not be in ToM")
end)
it("shows a do-date chip on a dated task row", function()
-- A past do-date keeps the task actionable (so it appears in ToM) and, with
-- no late_on, renders as a `do:` chip rather than a `late:` one.
ctx.q:call("task.create", { title = "dated thing", attention = "red", do_date = 1704067200000 })
require("heph.view").view("tom")
local buf = vim.api.nvim_get_current_buf()
local text = table.concat(vim.api.nvim_buf_get_lines(buf, 0, -1, false), "\n")
assert.is_truthy(text:find("dated thing", 1, true), "dated task missing")
assert.is_truthy(text:find("do:", 1, true), "do-date chip missing from the row")
end)
it("scopes the chores view to chore projects via the daemon", function()
local chores = ctx.q:call("node.create", { kind = "project", title = "Chores" })
ctx.q:call("task.create", { title = "take out trash", attention = "white", project_id = chores.id })
ctx.q:call("task.create", { title = "unrelated", attention = "white" })
local rows = ctx.q:call("view", { name = "chores" })
assert.are.equal(1, #rows)
assert.are.equal("take out trash", rows[1].title)
end)
end)