Skip to content

Commit

Permalink
test(w.w.slider): Add integration tests
Browse files Browse the repository at this point in the history
  • Loading branch information
sclu1034 committed Dec 23, 2021
1 parent 2952e76 commit 413ddf9
Showing 1 changed file with 133 additions and 0 deletions.
133 changes: 133 additions & 0 deletions tests/test-wibox-widget-slider.lua
@@ -0,0 +1,133 @@
local runner = require("_runner")
local wibox = require("wibox")
local gears = {
shape = require("gears.shape")
}
assert = require("luassert")
local spy = require("luassert.spy")

local steps = {}

local function step(func)
table.insert(steps, func)
end

local w
local slider

local on_mouse_press = spy(function() end)
local on_drag_start = spy(function() end)
local on_drag = spy(function() end)
local on_drag_end = spy(function() end)
local on_property_value = spy(function() end)

-- Test values gathered through trial and error, since these can't really be calculated
local x_0 = 1
local x_1 = 50
local x_2 = 90

local value_0 = 0
local value_1 = 20
local value_2 = 36

step(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(...) end)
slider:connect_signal("drag_start", function(...) on_drag_start(...) end)
slider:connect_signal("drag", function(...) on_drag(...) end)
slider:connect_signal("drag_end", function(...) on_drag_end(...) end)
slider:connect_signal("property::value", function(...) on_property_value(...) end)

w = wibox {
ontop = true,
x = 0,
y = 0,
width = 250,
height = 50,
visible = true,
widget = slider,
}

return true
end)

step(function()
-- Coordinates to hit the slider's handle
mouse.coords({ x = x_0, y = 24 })

assert.are.equal(slider, mouse.current_widget)
assert.spy(on_drag_start).was_not.called()

root.fake_input("button_press", 1)
awesome.sync()

return true
end)

step(function()
assert.spy(on_mouse_press).was.called()
assert.spy(on_drag_start).was.called_with(slider, value_0)
assert.spy(on_property_value).was.called_with(slider, value_0)
assert.spy(on_drag).was_not.called()
assert.spy(on_drag_end).was_not.called()

return true
end)

step(function()
mouse.coords({ x = x_1, y = 24 })
awesome.sync()
return true
end)

step(function()
assert.spy(on_mouse_press).was.called(1)
assert.spy(on_drag_start).was.called(1)
assert.spy(on_property_value).was.called_with(slider, value_1)
assert.spy(on_drag).was.called_with(slider, value_1)

return true
end)

step(function()
mouse.coords({ x = x_2, y = 24 })
awesome.sync()
return true
end)

step(function()
assert.spy(on_drag).was.called(2)
assert.spy(on_property_value).was.called_with(slider, value_2)
assert.spy(on_drag).was.called_with(slider, value_2)

return true
end)

step(function()
assert.spy(on_drag_end).was_not.called()
root.fake_input("button_release", 1)
awesome.sync()

return true
end)

step(function()
assert.spy(on_drag_end).was.called_with(slider, value_2)

return true
end)

runner.run_steps(steps)

-- vim: filetype=lua:expandtab:shiftwidth=4:tabstop=8:softtabstop=4:textwidth=80

0 comments on commit 413ddf9

Please sign in to comment.