-- Interactive task-list actions: add a task from the list, mark done from it. local h = require("e2e.helpers") describe("task list actions", function() local ctx before_each(function() ctx = h.start() end) after_each(function() h.stop(ctx) end) it("adds a task from the list buffer", function() require("heph.view").list() local buf = vim.api.nvim_get_current_buf() vim.g.heph_force_ui_select = true local orig_input, orig_select = vim.ui.input, vim.ui.select vim.ui.input = function(_o, cb) cb("Buy milk") end vim.ui.select = function(_items, _o, cb) cb("orange") end require("heph.view").add_from(buf) vim.ui.input, vim.ui.select, vim.g.heph_force_ui_select = orig_input, orig_select, nil -- The task was created with the chosen attention... local found for _, t in ipairs(ctx.q:call("list", {})) do if t.title == "Buy milk" then found = t end end assert.is_truthy(found, "task not created") assert.are.equal("orange", found.attention) -- ...and the list refreshed to show it. local present = false for _, l in ipairs(vim.api.nvim_buf_get_lines(vim.api.nvim_get_current_buf(), 0, -1, false)) do if l:find("Buy milk", 1, true) then present = true end end assert.is_true(present, "added task missing from the refreshed list") end) it("marks the task under the cursor done from the list buffer", function() local t = ctx.q:call("task.create", { title = "Ship it", attention = "red" }) require("heph.view").list() local buf = vim.api.nvim_get_current_buf() vim.api.nvim_win_set_cursor(0, { 2, 0 }) -- line 1 is the hint header require("heph.view").done_under_cursor(buf) assert.are.equal("done", ctx.q:call("task.get", { id = t.node_id }).state) assert.are.equal(0, #ctx.q:call("list", {})) -- gone from the refreshed list end) end)