test(w.w.slider): Add integration tests

Signed-off-by: Lucas Schwiderski <lucas@lschwiderski.de>
This commit is contained in:
Lucas Schwiderski 2021-12-23 18:50:38 +01:00
parent dc5013dfb9
commit 741764a5b7
No known key found for this signature in database
GPG Key ID: AA12679AAA6DF4D8
1 changed files with 108 additions and 0 deletions

View File

@ -0,0 +1,108 @@
local runner = require("_runner")
local wibox = require("wibox")
local gears = {
shape = require("gears.shape")
}
local steps = {}
-- The test runner doesn't support it (yet), but it would be nice to have named
-- steps.
local function step(_, func)
table.insert(steps, func)
end
-- Apparently in CI the wibox won't always be at the coordinates we specify.
-- So we'll have to click around blindly until we find our widget,
-- then use those coordinates as offset for the actual test.
local offset_x = nil
local offset_y = nil
-- Reference to keep the wibox alive throughout the test steps.
local w -- luacheck: ignore
local slider
local on_mouse_press = nil
local on_drag_start = nil
local on_drag = nil
local on_drag_end = nil
local on_property_value = nil
step("create slider widget", function()
slider = wibox.widget.slider {
minimum = 0,
maximum = 100,
bar_shape = gears.shape.rounded_rect,
bar_height = 3,
bar_color = "#ffffff",
handle_color = "#0000ff",
handle_shape = gears.shape.circle,
handle_border_color = "#ffffff",
handle_border_width = 1,
}
slider:connect_signal("button::press", function()
on_mouse_press = true
if offset_x ~= nil then
return
end
local coords = mouse.coords()
offset_x = coords.x
offset_y = coords.y
end)
slider:connect_signal("drag_start", function() on_drag_start = true end)
slider:connect_signal("drag", function() on_drag = true end)
slider:connect_signal("drag_end", function() on_drag_end = true end)
slider:connect_signal("property::value", function() on_property_value = true end)
w = wibox {
ontop = true,
x = 0,
y = 0,
width = 250,
height = 50,
visible = true,
widget = slider,
}
return true
end)
for x = 0, 2000, 5 do
for y = 0, 2000, 5 do
step("find widget", function()
if offset_x ~= nil then
return true
end
mouse.coords({ x = x, y = y })
root.fake_input("button_press", 1)
root.fake_input("button_release", 1)
return true
end)
end
end
step("test dragging", function()
mouse.coords({ x = offset_x, y = offset_y })
root.fake_input("button_press", 1)
mouse.coords({ x = offset_x + 100, offset_y })
root.fake_input("button_release", 1)
return true
end)
step("check signals", function()
assert(on_mouse_press, "Signal `button::press` was not called")
assert(on_drag_start, "Signal `drag_start` was not called")
assert(on_property_value, "Signal `property::value` was not called")
assert(on_drag, "Signal `drag` was not called")
assert(on_drag_end, "Signal `drag_end` was not called")
return true
end)
runner.run_steps(steps)
-- vim: filetype=lua:expandtab:shiftwidth=4:tabstop=8:softtabstop=4:textwidth=80