-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtoggle_visibility_spec.lua
More file actions
154 lines (125 loc) · 3.91 KB
/
toggle_visibility_spec.lua
File metadata and controls
154 lines (125 loc) · 3.91 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
local stack = require("peekstack.core.stack")
local config = require("peekstack.config")
local events = require("peekstack.core.events")
local helpers = require("tests.helpers")
describe("stack.toggle_visibility", function()
before_each(function()
stack._reset()
config.setup({})
events.setup()
end)
after_each(function()
local s = stack.current_stack()
-- Restore visibility so windows can be closed normally
if s.hidden then
stack.toggle_visibility()
end
for i = #s.popups, 1, -1 do
stack.close(s.popups[i].id)
end
stack._reset()
end)
it("returns false on empty stack", function()
assert.is_false(stack.toggle_visibility())
assert.is_false(stack.is_hidden())
end)
it("hides all popup windows", function()
local loc = helpers.make_location()
local m1 = stack.push(loc)
local m2 = stack.push(loc)
assert.is_not_nil(m1)
assert.is_not_nil(m2)
assert.is_true(stack.toggle_visibility())
assert.is_true(stack.is_hidden())
-- Windows should be gone but popups remain in the stack
local s = stack.current_stack()
assert.equals(2, #s.popups)
for _, item in ipairs(s.popups) do
assert.is_nil(item.winid)
end
end)
it("restores popup windows on second toggle", function()
local loc = helpers.make_location()
local m1 = stack.push(loc)
local m2 = stack.push(loc)
assert.is_not_nil(m1)
assert.is_not_nil(m2)
-- Hide
stack.toggle_visibility()
assert.is_true(stack.is_hidden())
-- Show
assert.is_true(stack.toggle_visibility())
assert.is_false(stack.is_hidden())
local s = stack.current_stack()
assert.equals(2, #s.popups)
for _, item in ipairs(s.popups) do
assert.is_not_nil(item.winid)
assert.is_true(vim.api.nvim_win_is_valid(item.winid))
end
end)
it("preserves popup ids across hide/show cycle", function()
local loc = helpers.make_location()
local m1 = stack.push(loc)
local m2 = stack.push(loc)
local id1 = m1.id
local id2 = m2.id
stack.toggle_visibility()
stack.toggle_visibility()
local s = stack.current_stack()
assert.equals(id1, s.popups[1].id)
assert.equals(id2, s.popups[2].id)
end)
it("auto-shows when push is called while hidden", function()
local loc = helpers.make_location()
stack.push(loc)
stack.toggle_visibility()
assert.is_true(stack.is_hidden())
-- Pushing should auto-show
local m2 = stack.push(loc)
assert.is_not_nil(m2)
assert.is_false(stack.is_hidden())
local s = stack.current_stack()
assert.equals(2, #s.popups)
for _, item in ipairs(s.popups) do
assert.is_not_nil(item.winid)
assert.is_true(vim.api.nvim_win_is_valid(item.winid))
end
end)
it("close_all works while hidden", function()
local loc = helpers.make_location()
stack.push(loc)
stack.push(loc)
stack.toggle_visibility()
assert.is_true(stack.is_hidden())
stack.close_all()
assert.is_false(stack.is_hidden())
local s = stack.current_stack()
assert.equals(0, #s.popups)
end)
it("reflow_all skips hidden stack without error", function()
local loc = helpers.make_location()
stack.push(loc)
stack.push(loc)
stack.toggle_visibility()
assert.is_true(stack.is_hidden())
-- reflow_all should skip hidden popups (winid=nil) safely
assert.has_no.errors(function()
stack.reflow_all()
end)
-- Popups should still be in the stack
local s = stack.current_stack()
assert.equals(2, #s.popups)
for _, item in ipairs(s.popups) do
assert.is_nil(item.winid)
end
end)
it("does not leak popups to history when hiding", function()
local loc = helpers.make_location()
stack.push(loc)
stack.push(loc)
local history_before = #stack.history_list()
stack.toggle_visibility()
local history_after = #stack.history_list()
assert.equals(history_before, history_after)
end)
end)