Skip to content

Commit

Permalink
fix: more tests
Browse files Browse the repository at this point in the history
  • Loading branch information
shortcuts committed Jun 29, 2024
1 parent 375a5bc commit 7e4e767
Show file tree
Hide file tree
Showing 5 changed files with 32 additions and 105 deletions.
4 changes: 1 addition & 3 deletions lua/no-neck-pain/main.lua
Original file line number Diff line number Diff line change
Expand Up @@ -163,9 +163,7 @@ function N.enable(scope)
vim.api.nvim_create_autocmd({ "TabLeave" }, {
callback = function(p)
vim.schedule(function()
if
S.isActiveTabRegistered(S) and not vim.api.nvim_tabpage_is_valid(S.activeTab)
then
if not vim.api.nvim_tabpage_is_valid(S.activeTab) then
S.refreshTabs(S, S.activeTab)
D.log(p.event, "tab %d is now inactive", S.activeTab)
else
Expand Down
14 changes: 4 additions & 10 deletions lua/no-neck-pain/state.lua
Original file line number Diff line number Diff line change
Expand Up @@ -182,6 +182,8 @@ end
---@return table: the wins that are not in `tab`.
---@private
function State:getUnregisteredWins(withCurr)


return vim.tbl_filter(function(win)
if A.isRelativeWindow(win) then
return false
Expand Down Expand Up @@ -272,20 +274,12 @@ function State:scanIntegrations(scope)
return unregisteredIntegrations
end

---Whether the `activeTab` is valid or not.
---
---@return boolean
---@private
function State:isActiveTabValid()
return self.isActiveTabRegistered(self) and vim.api.nvim_tabpage_is_valid(self.activeTab)
end

---Whether the `activeTab` is registered in the state or not.
---Whether the `activeTab` is registered in the state and valid.
---
---@return boolean
---@private
function State:isActiveTabRegistered()
return self.hasTabs(self) and self.tabs[self.activeTab] ~= nil
return self.hasTabs(self) and self.tabs[self.activeTab] ~= nil and vim.api.nvim_tabpage_is_valid(self.activeTab)
end

---Whether the side window is registered and enabled in the config or not.
Expand Down
6 changes: 3 additions & 3 deletions tests/test_API.lua
Original file line number Diff line number Diff line change
Expand Up @@ -244,7 +244,7 @@ T["enable"]["(single tab) sets state"] = function()
right = 1002,
})

Helpers.expect.state(child, "tabs[1].wins.splits", vim.NIL)
Helpers.expect.state(child, "tabs[1].wins.vsplits", 1)

Helpers.expect.state_type(child, "tabs[1].wins.integrations", "table")

Expand Down Expand Up @@ -272,7 +272,7 @@ T["enable"]["(multiple tab) sets state"] = function()
left = 1001,
right = 1002,
})
Helpers.expect.state(child, "tabs[1].wins.splits", vim.NIL)
Helpers.expect.state(child, "tabs[1].wins.vsplits", 1)

Helpers.expect.state_type(child, "tabs[1].wins.integrations", "table")

Expand All @@ -296,7 +296,7 @@ T["enable"]["(multiple tab) sets state"] = function()
left = 1004,
right = 1005,
})
Helpers.expect.state(child, "tabs[2].wins.splits", vim.NIL)
Helpers.expect.state(child, "tabs[2].wins.vsplits", 3)

Helpers.expect.state_type(child, "tabs[2].wins.integrations", "table")

Expand Down
18 changes: 9 additions & 9 deletions tests/test_integrations.lua
Original file line number Diff line number Diff line change
Expand Up @@ -149,7 +149,7 @@ T["nvimdapui"]["keeps sides open"] = function()
right = 1002,
})

Helpers.expect.state(child, "tabs[1].wins.splits", vim.NIL)
Helpers.expect.state(child, "tabs[1].wins.vsplits", 5)

Helpers.expect.state(child, "tabs[1].wins.integrations.NvimDAPUI", {
close = "lua require('dapui').close()",
Expand Down Expand Up @@ -178,7 +178,7 @@ T["neotest"]["keeps sides open"] = function()
child.lua([[require('neotest').summary.open()]])
vim.loop.sleep(50)

Helpers.expect.state(child, "tabs[1].wins.splits", vim.NIL)
Helpers.expect.state(child, "tabs[1].wins.vsplits", 3)

Helpers.expect.state(child, "tabs[1].wins.integrations.neotest", {
close = "lua require('neotest').summary.close()",
Expand Down Expand Up @@ -207,7 +207,7 @@ T["outline"]["keeps sides open"] = function()
child.cmd("Outline")
vim.loop.sleep(50)

Helpers.expect.state(child, "tabs[1].wins.splits", vim.NIL)
Helpers.expect.state(child, "tabs[1].wins.vsplits", 1)

Helpers.expect.state(child, "tabs[1].wins.integrations.outline", {
close = "Outline",
Expand Down Expand Up @@ -251,7 +251,7 @@ T["NvimTree"]["keeps sides open"] = function()
right = 1002,
})

Helpers.expect.state(child, "tabs[1].wins.splits", vim.NIL)
Helpers.expect.state(child, "tabs[1].wins.vsplits", 1)

Helpers.expect.state(child, "tabs[1].wins.integrations.NvimTree", {
close = "NvimTreeClose",
Expand Down Expand Up @@ -290,7 +290,7 @@ T["neo-tree"]["keeps sides open"] = function()
right = 1002,
})

Helpers.expect.state(child, "tabs[1].wins.splits", vim.NIL)
Helpers.expect.state(child, "tabs[1].wins.vsplits", 1)

Helpers.expect.state(child, "tabs[1].wins.integrations.NeoTree", {
close = "Neotree close",
Expand Down Expand Up @@ -321,7 +321,7 @@ T["TSPlayground"]["keeps sides open"] = function()
child.cmd("TSPlaygroundToggle")
vim.loop.sleep(50)

Helpers.expect.state(child, "tabs[1].wins.splits", vim.NIL)
Helpers.expect.state(child, "tabs[1].wins.vsplits", 3)

Helpers.expect.equality(child.lua_get("vim.api.nvim_win_get_width(1004)"), 159)
Helpers.expect.state(child, "tabs[1].wins.integrations.TSPlayground", {
Expand Down Expand Up @@ -381,7 +381,7 @@ T["TSPlayground"]["reduces `left` side if only active when integration is on `ri
child.cmd("TSPlaygroundToggle")
vim.loop.sleep(50)

Helpers.expect.state(child, "tabs[1].wins.splits", vim.NIL)
Helpers.expect.state(child, "tabs[1].wins.vsplits", 1)

Helpers.expect.equality(child.lua_get("vim.api.nvim_win_get_width(1003)"), 142)
Helpers.expect.equality(child.lua_get("vim.api.nvim_win_get_width(1001)"), 15)
Expand All @@ -401,7 +401,7 @@ T["TSPlayground"]["reduces `left` side if only active when integration is on `ri
child.cmd("TSPlaygroundToggle")
vim.loop.sleep(50)

Helpers.expect.state(child, "tabs[1].wins.splits", vim.NIL)
Helpers.expect.state(child, "tabs[1].wins.vsplits", 2)

Helpers.expect.state(child, "tabs[1].wins.integrations.TSPlayground", {
close = "TSPlaygroundToggle",
Expand Down Expand Up @@ -441,7 +441,7 @@ T["aerial"]["keeps sides open"] = function()

child.cmd("AerialToggle")

Helpers.expect.state(child, "tabs[1].wins.splits", vim.NIL)
Helpers.expect.state(child, "tabs[1].wins.vsplits", 1)

Helpers.expect.equality(child.lua_get("vim.api.nvim_win_get_width(1004)"), 25)
Helpers.expect.state(child, "tabs[1].wins.integrations.aerial.id", 1004)
Expand Down
Loading

0 comments on commit 7e4e767

Please sign in to comment.