|
1 | 1 | describe("peekstack.commands", function() |
2 | 2 | local commands = require("peekstack.commands") |
| 3 | + local config = require("peekstack.config") |
3 | 4 | local persist = require("peekstack.persist") |
4 | 5 | local original_list_sessions = nil |
5 | 6 | local original_select = nil |
| 7 | + local original_notify = nil |
| 8 | + local original_strftime = nil |
6 | 9 |
|
7 | 10 | before_each(function() |
| 11 | + config.setup({}) |
8 | 12 | commands._reset() |
9 | 13 | original_list_sessions = persist.list_sessions |
10 | 14 | original_select = vim.ui.select |
| 15 | + original_notify = vim.notify |
| 16 | + original_strftime = vim.fn.strftime |
11 | 17 | end) |
12 | 18 |
|
13 | 19 | after_each(function() |
| 20 | + config.setup({}) |
14 | 21 | if original_list_sessions then |
15 | 22 | persist.list_sessions = original_list_sessions |
16 | 23 | end |
17 | 24 | if original_select then |
18 | 25 | vim.ui.select = original_select |
19 | 26 | end |
| 27 | + if original_notify then |
| 28 | + vim.notify = original_notify |
| 29 | + end |
| 30 | + if original_strftime then |
| 31 | + vim.fn.strftime = original_strftime |
| 32 | + end |
20 | 33 | commands._reset() |
21 | 34 | end) |
22 | 35 |
|
@@ -69,6 +82,59 @@ describe("peekstack.commands", function() |
69 | 82 | assert.equals("broken: 1 items (updated: unknown)", prompts[2]) |
70 | 83 | end) |
71 | 84 |
|
| 85 | + it("notifies when list sessions is invoked while persist is disabled", function() |
| 86 | + config.setup({ persist = { enabled = false } }) |
| 87 | + |
| 88 | + local messages = {} |
| 89 | + vim.notify = function(msg) |
| 90 | + table.insert(messages, msg) |
| 91 | + end |
| 92 | + |
| 93 | + commands.setup() |
| 94 | + vim.api.nvim_cmd({ cmd = "PeekstackListSessions" }, {}) |
| 95 | + |
| 96 | + assert.is_true(vim.list_contains(messages, "peekstack.persist is disabled")) |
| 97 | + end) |
| 98 | + |
| 99 | + it("formats session updated_at with vim.fn.strftime", function() |
| 100 | + local prompts = {} |
| 101 | + local strftime_calls = {} |
| 102 | + |
| 103 | + persist.list_sessions = function(opts) |
| 104 | + assert.is_truthy(opts) |
| 105 | + assert.is_truthy(opts.on_done) |
| 106 | + opts.on_done({ |
| 107 | + alpha = { |
| 108 | + items = {}, |
| 109 | + meta = { updated_at = 123 }, |
| 110 | + }, |
| 111 | + }) |
| 112 | + return {} |
| 113 | + end |
| 114 | + |
| 115 | + vim.fn.strftime = function(fmt, ts) |
| 116 | + table.insert(strftime_calls, { fmt = fmt, ts = ts }) |
| 117 | + return "formatted-time" |
| 118 | + end |
| 119 | + |
| 120 | + vim.ui.select = function(_items, opts, on_choice) |
| 121 | + table.insert(prompts, opts.prompt) |
| 122 | + if opts.prompt == "Select a session" then |
| 123 | + on_choice("alpha") |
| 124 | + return |
| 125 | + end |
| 126 | + on_choice("Info only") |
| 127 | + end |
| 128 | + |
| 129 | + commands.setup() |
| 130 | + vim.api.nvim_cmd({ cmd = "PeekstackListSessions" }, {}) |
| 131 | + |
| 132 | + assert.equals(1, #strftime_calls) |
| 133 | + assert.equals("%Y-%m-%d %H:%M:%S", strftime_calls[1].fmt) |
| 134 | + assert.equals(123, strftime_calls[1].ts) |
| 135 | + assert.equals("alpha: 0 items (updated: formatted-time)", prompts[2]) |
| 136 | + end) |
| 137 | + |
72 | 138 | it("includes extended providers in quick peek completion", function() |
73 | 139 | commands.setup() |
74 | 140 | local names = vim.fn.getcompletion("PeekstackQuickPeek ", "cmdline") |
|
0 commit comments