From 3cc613fa2059255b6f41967b9cd9b329963c6dde Mon Sep 17 00:00:00 2001 From: actionless Date: Tue, 24 Jan 2017 11:28:54 +0100 Subject: [PATCH] test(awful: hotkeys_popup): add a minimal test --- lib/awful/hotkeys_popup/widget.lua | 12 ++++---- tests/test-awesomerc.lua | 46 +++++++++++++++++++++++++++++- tests/test-awful-widget-button.lua | 4 +-- 3 files changed, 53 insertions(+), 9 deletions(-) diff --git a/lib/awful/hotkeys_popup/widget.lua b/lib/awful/hotkeys_popup/widget.lua index 4953b3624..f333a2a69 100644 --- a/lib/awful/hotkeys_popup/widget.lua +++ b/lib/awful/hotkeys_popup/widget.lua @@ -100,9 +100,9 @@ function widget.new() ['#21']="=", Control="Ctrl" }, + _cached_wiboxes = {} } - local cached_wiboxes = {} local cached_awful_keys = nil local colors_counter = {} local colors = beautiful.xresources.get_current_theme() @@ -408,13 +408,13 @@ function widget.new() end local joined_groups = join_plus_sort(available_groups) - if not cached_wiboxes[s] then - cached_wiboxes[s] = {} + if not widget_instance._cached_wiboxes[s] then + widget_instance._cached_wiboxes[s] = {} end - if not cached_wiboxes[s][joined_groups] then - cached_wiboxes[s][joined_groups] = create_wibox(s, available_groups) + if not widget_instance._cached_wiboxes[s][joined_groups] then + widget_instance._cached_wiboxes[s][joined_groups] = create_wibox(s, available_groups) end - local help_wibox = cached_wiboxes[s][joined_groups] + local help_wibox = widget_instance._cached_wiboxes[s][joined_groups] help_wibox:show() return capi.keygrabber.run(function(_, key, event) diff --git a/tests/test-awesomerc.lua b/tests/test-awesomerc.lua index c3f38c034..a7a091c66 100644 --- a/tests/test-awesomerc.lua +++ b/tests/test-awesomerc.lua @@ -1,4 +1,5 @@ local awful = require("awful") +local hotkeys_widget = require("awful.hotkeys_popup").widget -- luacheck: globals modkey @@ -15,6 +16,15 @@ local function get_c_and_t() return c, t end +local function num_pairs(container_table) + local number_of_items = 0 + for _, _ in pairs(container_table) do + number_of_items = number_of_items + 1 + end + return number_of_items +end + + -- display deprecated warnings --awful.util.deprecate = function() end @@ -219,7 +229,41 @@ local steps = { assert(#tags[1]:clients() == 4) return true - end + end, + + -- Hotkeys popup should be displayed and hidden + function(count) + local s = awful.screen.focused() + local cached_wiboxes = hotkeys_widget.default_widget._cached_wiboxes + + if count == 1 then + assert(num_pairs(cached_wiboxes) == 0) + awful.key.execute({modkey}, "s") + return nil + + elseif count == 2 then + assert(num_pairs(cached_wiboxes) > 0) + assert(num_pairs(cached_wiboxes[s]) == 1) + end + + local hotkeys_wibox + for _, widget in pairs(cached_wiboxes[s]) do + hotkeys_wibox = widget.wibox + end + + if count == 2 then + assert(hotkeys_wibox ~= nil) + assert(hotkeys_wibox.visible) + -- Should disappear on anykey + root.fake_input("key_press", "Super_L") + + elseif count == 3 then + assert(not hotkeys_wibox.visible) + root.fake_input("key_release", "Super_L") + return true + end + end, + } require("_runner").run_steps(steps) diff --git a/tests/test-awful-widget-button.lua b/tests/test-awful-widget-button.lua index f6cd2c5a6..e9b1a9279 100644 --- a/tests/test-awful-widget-button.lua +++ b/tests/test-awful-widget-button.lua @@ -88,9 +88,9 @@ table.insert(steps, function() end) table.insert(steps, function() -assert(button._private.image ~= img) + assert(button._private.image ~= img) -return true + return true end) -- Test a button release