177 lines
5.3 KiB
Lua
177 lines
5.3 KiB
Lua
package.path = package.path .. ";./?.lua;./modules/?.lua"
|
|
local originalSearchers = package.searchers or package.loaders
|
|
table.insert(originalSearchers, 2, function(modname)
|
|
if modname:match("^FlexLove%.modules%.") then
|
|
local moduleName = modname:gsub("^FlexLove%.modules%.", "")
|
|
return function()
|
|
return require("modules." .. moduleName)
|
|
end
|
|
end
|
|
end)
|
|
require("testing.loveStub")
|
|
local luaunit = require("testing.luaunit")
|
|
local FlexLove = require("FlexLove")
|
|
|
|
FlexLove.init()
|
|
|
|
TestScrollbarPlacement = {}
|
|
|
|
function TestScrollbarPlacement:setUp()
|
|
FlexLove.setMode("retained")
|
|
end
|
|
|
|
function TestScrollbarPlacement:test_reserve_space_with_percentage_height_children()
|
|
-- Test case from user: horizontal scroll container with 100% height children
|
|
-- Should NOT cause vertical overflow
|
|
local container = FlexLove.new({
|
|
width = 200,
|
|
height = 200,
|
|
positioning = "flex",
|
|
flexDirection = "horizontal",
|
|
overflow = "scroll", -- Always shows scrollbars
|
|
scrollbarPlacement = "reserve-space",
|
|
})
|
|
|
|
local child1 = FlexLove.new({
|
|
width = 100,
|
|
height = "100%",
|
|
parent = container,
|
|
})
|
|
|
|
-- Trigger layout
|
|
container:layoutChildren()
|
|
container._scrollManager:detectOverflow(container)
|
|
|
|
local overflowX, overflowY = container._scrollManager:hasOverflow()
|
|
|
|
-- Child height should be reduced to account for horizontal scrollbar
|
|
-- Default scrollbar is 12px + 2px padding on each side = 16px
|
|
-- So child height should be 200 - 16 = 184px
|
|
luaunit.assertEquals(child1.height, 184)
|
|
|
|
-- Should have horizontal overflow (scroll mode), but NOT vertical
|
|
luaunit.assertFalse(overflowY, "Should not have vertical overflow with 100% height child")
|
|
end
|
|
|
|
function TestScrollbarPlacement:test_reserve_space_with_percentage_width_children()
|
|
-- Vertical scroll container with 100% width children
|
|
local container = FlexLove.new({
|
|
width = 200,
|
|
height = 200,
|
|
positioning = "flex",
|
|
flexDirection = "column",
|
|
overflow = "scroll", -- Always shows scrollbars
|
|
scrollbarPlacement = "reserve-space",
|
|
})
|
|
|
|
local child1 = FlexLove.new({
|
|
width = "100%",
|
|
height = 100,
|
|
parent = container,
|
|
})
|
|
|
|
-- Trigger layout
|
|
container:layoutChildren()
|
|
container._scrollManager:detectOverflow(container)
|
|
|
|
local overflowX, overflowY = container._scrollManager:hasOverflow()
|
|
|
|
-- Child width should be reduced to account for vertical scrollbar
|
|
-- Default scrollbar is 12px + 2px padding on each side = 16px
|
|
-- So child width should be 200 - 16 = 184px
|
|
luaunit.assertEquals(child1.width, 184)
|
|
|
|
-- Should have vertical overflow (scroll mode), but NOT horizontal
|
|
luaunit.assertFalse(overflowX, "Should not have horizontal overflow with 100% width child")
|
|
end
|
|
|
|
function TestScrollbarPlacement:test_overlay_mode_no_size_adjustment()
|
|
-- Overlay mode should NOT adjust child sizes
|
|
local container = FlexLove.new({
|
|
width = 200,
|
|
height = 200,
|
|
positioning = "flex",
|
|
flexDirection = "horizontal",
|
|
overflow = "scroll",
|
|
scrollbarPlacement = "overlay",
|
|
})
|
|
|
|
local child1 = FlexLove.new({
|
|
width = 100,
|
|
height = "100%",
|
|
parent = container,
|
|
})
|
|
|
|
-- Trigger layout
|
|
container:layoutChildren()
|
|
|
|
-- Child height should be full 200px (no reduction for scrollbar)
|
|
luaunit.assertEquals(child1.height, 200)
|
|
end
|
|
|
|
function TestScrollbarPlacement:test_auto_overflow_reserves_space_only_when_needed()
|
|
-- With overflow="auto" and reserve-space mode, space is reserved preemptively
|
|
-- But scrollbars should only be visible when content actually overflows
|
|
local container = FlexLove.new({
|
|
width = 200,
|
|
height = 200,
|
|
positioning = "flex",
|
|
flexDirection = "column",
|
|
overflow = "auto",
|
|
scrollbarPlacement = "reserve-space",
|
|
})
|
|
|
|
-- Child that doesn't cause overflow
|
|
local child1 = FlexLove.new({
|
|
width = "100%",
|
|
height = 100,
|
|
parent = container,
|
|
})
|
|
|
|
-- Trigger layout and overflow detection
|
|
container:layoutChildren()
|
|
container._scrollManager:detectOverflow(container)
|
|
|
|
local overflowX, overflowY = container._scrollManager:hasOverflow()
|
|
|
|
-- No overflow detected since content (100px) < available height (184px after scrollbar reservation)
|
|
luaunit.assertFalse(overflowY, "Should not have overflow")
|
|
-- Space is reserved preemptively with overflow="auto" to avoid layout shifts
|
|
luaunit.assertEquals(child1.width, 184, "Space should be reserved preemptively with auto mode")
|
|
end
|
|
|
|
function TestScrollbarPlacement:test_vertical_overflow_detected_with_reserved_space()
|
|
-- Test that overflow is properly detected when using reserve-space
|
|
local container = FlexLove.new({
|
|
width = 200,
|
|
height = 200,
|
|
positioning = "flex",
|
|
flexDirection = "column",
|
|
overflow = "auto",
|
|
scrollbarPlacement = "reserve-space",
|
|
})
|
|
|
|
-- Child that WILL cause overflow
|
|
local child1 = FlexLove.new({
|
|
width = "100%",
|
|
height = 300,
|
|
parent = container,
|
|
})
|
|
|
|
-- Trigger layout and overflow detection
|
|
container:layoutChildren()
|
|
container._scrollManager:detectOverflow(container)
|
|
|
|
local overflowX, overflowY = container._scrollManager:hasOverflow()
|
|
|
|
-- Should detect vertical overflow
|
|
luaunit.assertTrue(overflowY, "Should detect vertical overflow")
|
|
|
|
-- Child width should be reduced for vertical scrollbar
|
|
luaunit.assertEquals(child1.width, 184, "Child width should be reduced for scrollbar")
|
|
end
|
|
|
|
if not _G.RUNNING_ALL_TESTS then
|
|
os.exit(luaunit.LuaUnit.run())
|
|
end
|