Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
172 changes: 170 additions & 2 deletions tests/test_integrations.lua
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,44 @@ T["left integration"]["opening closes zen side buffer, closing reopens it"] = fu
})
end

T["left integration"]["opening a left integration preserves an existing top integration"] = function()
child.cmd("Git")
child.lua("vim.cmd('Fyler kind=split_left_most')")

Helpers.expect.layout(child, {
type = "col",
children = {
{ type = "leaf", filetype = "fugitive", buftype = "nowrite", width = 240, height = 25 },
{
type = "row",
children = {
{ type = "leaf", filetype = "fyler_finder", buftype = "acwrite", width = 46, height = 24 },
{ type = "leaf", filetype = "", buftype = "", width = 146, height = 24 },
{ type = "leaf", filetype = "zen-right", buftype = "nofile", width = 46, height = 24 },
},
},
},
})

child.cmd("close")
child.lua("vim.cmd('Fyler kind=split_left_most')")
child.cmd("close")

Helpers.expect.layout(child, {
type = "col",
children = {
{ type = "leaf", filetype = "fugitive", buftype = "nowrite", width = 240, height = 25 },
{
type = "row",
children = {
{ type = "leaf", filetype = "zen-left", buftype = "nofile", width = 46, height = 24 },
{ type = "leaf", filetype = "", buftype = "", width = 146, height = 24 },
{ type = "leaf", filetype = "zen-right", buftype = "nofile", width = 46, height = 24 },
},
},
},
})
end

T["left integration"]["opening an integration should close the existing integration on the same side"] = function()
child.cmd("Fyler kind=split_left_most")
Expand All @@ -61,6 +99,45 @@ T["left integration"]["opening an integration should close the existing integrat
})
end

T["left integration"]["opening a left integration preserves an existing bottom integration"] = function()
child.cmd("Trouble diagnostics")
child.cmd("Fyler kind=split_left_most")

Helpers.expect.layout(child, {
type = "col",
children = {
{
type = "row",
children = {
{ type = "leaf", filetype = "fyler_finder", buftype = "acwrite", width = 46, height = 39 },
{ type = "leaf", filetype = "", buftype = "", width = 146, height = 39 },
{ type = "leaf", filetype = "zen-right", buftype = "nofile", width = 46, height = 39 },
},
},
{ type = "leaf", filetype = "trouble", buftype = "nofile", width = 240, height = 10 },
},
})

child.cmd("close")
child.cmd("Fyler kind=split_left_most")
child.cmd("close")

Helpers.expect.layout(child, {
type = "col",
children = {
{
type = "row",
children = {
{ type = "leaf", filetype = "zen-left", buftype = "nofile", width = 46, height = 39 },
{ type = "leaf", filetype = "", buftype = "", width = 146, height = 39 },
{ type = "leaf", filetype = "zen-right", buftype = "nofile", width = 46, height = 39 },
},
},
{ type = "leaf", filetype = "trouble", buftype = "nofile", width = 240, height = 10 },
},
})
end

T["top integration"] = MiniTest.new_set({})

T["top integration"]["opening"] = function()
Expand Down Expand Up @@ -257,9 +334,70 @@ T["right integration"]["opening an integration with table filetype"] = function(
})
end

T["combined"] = MiniTest.new_set({})

T["combined"]["opening a side integration preserves existing top and bottom integrations"] = function()
child.cmd("Git")
child.cmd("Trouble diagnostics")
child.cmd("Fyler kind=split_left_most")

Helpers.expect.layout(child, {
type = "col",
children = {
{ type = "leaf", filetype = "fugitive", buftype = "nowrite", width = 240, height = 25 },
{
type = "row",
children = {
{ type = "leaf", filetype = "fyler_finder", buftype = "acwrite", width = 46, height = 13 },
{ type = "leaf", filetype = "", buftype = "", width = 146, height = 13 },
{ type = "leaf", filetype = "zen-right", buftype = "nofile", width = 46, height = 13 },
},
},
{ type = "leaf", filetype = "trouble", buftype = "nofile", width = 240, height = 10 },
},
})

child.cmd("close")
child.cmd("Fyler kind=split_left_most")
child.cmd("close")

Helpers.expect.layout(child, {
type = "col",
children = {
{ type = "leaf", filetype = "fugitive", buftype = "nowrite", width = 240, height = 25 },
{
type = "row",
children = {
{ type = "leaf", filetype = "zen-left", buftype = "nofile", width = 46, height = 13 },
{ type = "leaf", filetype = "", buftype = "", width = 146, height = 13 },
{ type = "leaf", filetype = "zen-right", buftype = "nofile", width = 46, height = 13 },
},
},
{ type = "leaf", filetype = "trouble", buftype = "nofile", width = 240, height = 10 },
},
})

child.cmd("Trouble close")

Helpers.expect.layout(child, {
type = "col",
children = {
{ type = "leaf", filetype = "fugitive", buftype = "nowrite", width = 240, height = 25 },
{
type = "row",
children = {
{ type = "leaf", filetype = "zen-left", buftype = "nofile", width = 46, height = 24 },
{ type = "leaf", filetype = "", buftype = "", width = 146, height = 24 },
{ type = "leaf", filetype = "zen-right", buftype = "nofile", width = 46, height = 24 },
},
},
},
})
end

local min_width_child = MiniTest.new_child_neovim()

T["min_width"] = MiniTest.new_set({
T["min width"] = MiniTest.new_set({
hooks = {
pre_case = function()
min_width_child.restart({ "-u", "tests/scripts/init_with_zen_min_width.lua" })
Expand All @@ -268,7 +406,7 @@ T["min_width"] = MiniTest.new_set({
},
})

T["min_width"]["integration with a larger min_width should override the wildcard default"] = function()
T["min width"]["integration with a larger min_width should override the wildcard default"] = function()
min_width_child.lua([[vim.o.splitright = true; require("CopilotChat").open()]])

Helpers.expect.layout(min_width_child, {
Expand All @@ -281,4 +419,34 @@ T["min_width"]["integration with a larger min_width should override the wildcard
})
end

T["small window integration"] = MiniTest.new_set()

T["small window integration"]["left integration should keep its natural width"] = function()
child.restart({ "-u", "tests/scripts/init_with_zen_small.lua" })
child.cmd("Fyler kind=split_left_most")

-- Fyler opens at 30% of 140 = 42 cols. Zen must not force it to 0.
Helpers.expect.layout(child, {
type = "row",
children = {
{ type = "leaf", filetype = "fyler_finder", buftype = "acwrite", width = 42, height = 50 },
{ type = "leaf", filetype = "", buftype = "", width = 97, height = 50 },
},
})
end

T["small window integration"]["right integration should keep its natural width"] = function()
child.restart({ "-u", "tests/scripts/init_with_zen_small.lua" })
child.cmd("Neotest summary open")

-- Neotest opens at vertical resize 50. Zen must not force it to 0.
Helpers.expect.layout(child, {
type = "row",
children = {
{ type = "leaf", filetype = "", buftype = "", width = 89, height = 50 },
{ type = "leaf", filetype = "neotest-summary", buftype = "nofile", width = 50, height = 50 },
},
})
end

return T
111 changes: 111 additions & 0 deletions tests/test_wincmd.lua
Original file line number Diff line number Diff line change
@@ -0,0 +1,111 @@
local Helpers = dofile("tests/scripts/helpers.lua")
local child = MiniTest.new_child_neovim()

local T = MiniTest.new_set({
hooks = {
pre_case = function()
child.restart({ "-u", "tests/scripts/init_with_zen.lua" })
end,
post_once = child.stop,
},
})

T["moving a window to the side does not go past zen buffers"] = function()
child.cmd("wincmd H")

Helpers.expect.layout(child, {
type = "row",
children = {
{ type = "leaf", filetype = "zen-left", buftype = "nofile", width = 46, height = 50 },
{ type = "leaf", filetype = "", buftype = "", width = 146, height = 50 },
{ type = "leaf", filetype = "zen-right", buftype = "nofile", width = 46, height = 50 },
},
})

child.cmd("wincmd L")

Helpers.expect.layout(child, {
type = "row",
children = {
{ type = "leaf", filetype = "zen-left", buftype = "nofile", width = 46, height = 50 },
{ type = "leaf", filetype = "", buftype = "", width = 146, height = 50 },
{ type = "leaf", filetype = "zen-right", buftype = "nofile", width = 46, height = 50 },
},
})
end

T["moving a window to the side does not go past integrations"] = function()
child.cmd("Fyler kind=split_left_most")
child.cmd("Neotest summary open")

child.cmd("wincmd H")

Helpers.expect.layout(child, {
type = "row",
children = {
{ type = "leaf", filetype = "fyler_finder", buftype = "acwrite", width = 46, height = 50 },
{ type = "leaf", filetype = "", buftype = "", width = 146, height = 50 },
{ type = "leaf", filetype = "neotest-summary", buftype = "nofile", width = 46, height = 50 },
},
})

child.cmd("wincmd L")

Helpers.expect.layout(child, {
type = "row",
children = {
{ type = "leaf", filetype = "fyler_finder", buftype = "acwrite", width = 46, height = 50 },
{ type = "leaf", filetype = "", buftype = "", width = 146, height = 50 },
{ type = "leaf", filetype = "neotest-summary", buftype = "nofile", width = 46, height = 50 },
},
})
end

T["hsplit"] = MiniTest.new_set({})

T["hsplit"]["moving a window below keeps it between zen buffers"] = function()
child.cmd("edit test.lua")
child.cmd("split test.rs")

child.cmd("wincmd J")

Helpers.expect.layout(child, {
type = "row",
children = {
{ type = "leaf", filetype = "zen-left", buftype = "nofile", width = 46, height = 50 },
{
type = "col",
children = {
{ type = "leaf", filetype = "lua", buftype = "", width = 146, height = 24 },
{ type = "leaf", filetype = "rust", buftype = "", width = 146, height = 25 },
},
},
{ type = "leaf", filetype = "zen-right", buftype = "nofile", width = 46, height = 50 },
},
})
end

T["hsplit"]["moving a window above keeps it between zen buffers"] = function()
child.cmd("edit test.lua")
child.cmd("split test.rs")

child.cmd("wincmd j")
child.cmd("wincmd K")

Helpers.expect.layout(child, {
type = "row",
children = {
{ type = "leaf", filetype = "zen-left", buftype = "nofile", width = 46, height = 50 },
{
type = "col",
children = {
{ type = "leaf", filetype = "rust", buftype = "", width = 146, height = 24 },
{ type = "leaf", filetype = "lua", buftype = "", width = 146, height = 25 },
},
},
{ type = "leaf", filetype = "zen-right", buftype = "nofile", width = 46, height = 50 },
},
})
end

return T
Loading