-
Notifications
You must be signed in to change notification settings - Fork 586
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
test(w.w.slider): Add integration tests
- Loading branch information
Showing
1 changed file
with
133 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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 |