From 452d21a634cc3e272f75f06bd4eb2acee821ba20 Mon Sep 17 00:00:00 2001 From: Emmanuel Lepage Vallee Date: Sun, 23 Oct 2022 00:20:25 -0700 Subject: [PATCH] tests: Test `wibox.template` `:set_property()`. --- lib/awful/widget/common.lua | 2 +- lib/awful/widget/tasklist.lua | 2 +- lib/naughty/layout/box.lua | 2 +- spec/wibox/widget/template_spec.lua | 49 +++++++++++++++++++ .../notificationlist/bottombar.lua | 2 +- tests/examples/awful/popup/alttab.lua | 2 +- tests/examples/awful/popup/wiboxtypes.lua | 2 +- .../examples/awful/widget/layoutlist/bar.lua | 2 +- .../awful/widget/layoutlist/popup.lua | 2 +- .../examples/sequences/client/swap_byidx1.lua | 1 + .../client/tasklist_widget_template1.lua | 2 +- .../wibox/awidget/taglist/indexed.lua | 3 +- .../wibox/awidget/tasklist/rounded.lua | 2 +- .../wibox/awidget/tasklist/windows10.lua | 2 +- .../wibox/nwidget/actionlist/fancy.lua | 2 +- .../wibox/nwidget/actionlist/fancy_icons.lua | 2 +- .../wibox/nwidget/rules/widget_template.lua | 2 +- 17 files changed, 66 insertions(+), 15 deletions(-) diff --git a/lib/awful/widget/common.lua b/lib/awful/widget/common.lua index 85830ec24..3e9a34ff5 100644 --- a/lib/awful/widget/common.lua +++ b/lib/awful/widget/common.lua @@ -71,7 +71,7 @@ end local function default_template() return custom_template { - widget_template = { + widget_template = wibox.template { id = 'background_role', border_strategy = 'inner', widget = wibox.container.background, diff --git a/lib/awful/widget/tasklist.lua b/lib/awful/widget/tasklist.lua index c96b68c55..7b4f6db23 100644 --- a/lib/awful/widget/tasklist.lua +++ b/lib/awful/widget/tasklist.lua @@ -392,7 +392,7 @@ local function default_template(self) or self._private.style.tasklist_disable_icon or beautiful.tasklist_disable_icon - return { + return wtemplate { { (not has_no_icon) and { clienticon, diff --git a/lib/naughty/layout/box.lua b/lib/naughty/layout/box.lua index 9385616d9..e055974d4 100644 --- a/lib/naughty/layout/box.lua +++ b/lib/naughty/layout/box.lua @@ -176,7 +176,7 @@ end) -- -- The default template is (less or more): -- --- { +-- wibox.template { -- { -- { -- { diff --git a/spec/wibox/widget/template_spec.lua b/spec/wibox/widget/template_spec.lua index 6444fd435..f513a3822 100644 --- a/spec/wibox/widget/template_spec.lua +++ b/spec/wibox/widget/template_spec.lua @@ -7,6 +7,7 @@ _G.awesome.connect_signal = function() end local gtimer = require("gears.timer") local template = require("wibox.template") +local base = require("wibox.widget.base").make_widget describe("wibox.template", function() local widget @@ -80,6 +81,54 @@ describe("wibox.template", function() match.is_same { foo = "bar", bar = 10 } ) end) + + it("set_property", function() + local called + + widget = template { + { + id = "one", + foo = "bar", + widget = base + }, + { + id = "two", + everything = 42, + widget = base + }, + { + id = "three", + set_prop = function(_, val) + called = val + end, + widget = base + }, + id = "main", + widget = base, + } + + assert.is.equal(widget:get_children_by_id("main")[1], widget.children[1]) + assert.is.equal(widget:get_children_by_id("one")[1].foo, "bar") + assert.is.equal(widget:get_children_by_id("two")[1].everything, 42) + assert.is.equal(called, nil) + + widget:set_property("prop", 1337, "three") + assert.is.equal(called, 1337) + + widget:set_property("foo", "baz", "one") + assert.is.equal(widget:get_children_by_id("one")[1].foo, "baz") + + widget:set_property("everything", -42, "two") + assert.is.equal(widget:get_children_by_id("two")[1].everything, -42) + + widget:set_property("foobar", true, {"one", "two"}) + assert.is_true(widget:get_children_by_id("one")[1].foobar) + assert.is_true(widget:get_children_by_id("two")[1].foobar) + assert.is_nil(widget:get_children_by_id("three")[1].foobar) + + widget:set_property("test", 1337) + assert.is.equal(widget:get_children_by_id("main")[1].test, 1337) + end) end) end) diff --git a/tests/examples/awful/notification/notificationlist/bottombar.lua b/tests/examples/awful/notification/notificationlist/bottombar.lua index 6429abf72..fd2b87579 100644 --- a/tests/examples/awful/notification/notificationlist/bottombar.lua +++ b/tests/examples/awful/notification/notificationlist/bottombar.lua @@ -44,7 +44,7 @@ beautiful.notification_action_label_only = true --DOC_HIDE spacing = 3, layout = wibox.layout.flex.horizontal }, - widget_template = { + widget_template = wibox.template { { naughty.widget.icon, { diff --git a/tests/examples/awful/popup/alttab.lua b/tests/examples/awful/popup/alttab.lua index d56c17418..7529b0b7d 100644 --- a/tests/examples/awful/popup/alttab.lua +++ b/tests/examples/awful/popup/alttab.lua @@ -31,7 +31,7 @@ local tasklist_buttons = nil --DOC_HIDE layout = wibox.layout.grid.horizontal }, - widget_template = { + widget_template = wibox.template { { { id = "clienticon", diff --git a/tests/examples/awful/popup/wiboxtypes.lua b/tests/examples/awful/popup/wiboxtypes.lua index 4c0777b5f..9f224eedb 100644 --- a/tests/examples/awful/popup/wiboxtypes.lua +++ b/tests/examples/awful/popup/wiboxtypes.lua @@ -111,7 +111,7 @@ awful.popup { forced_num_cols = 5, layout = wibox.layout.grid.vertical, }, - widget_template = { + widget_template = wibox.template { { { id = 'icon_role', diff --git a/tests/examples/awful/widget/layoutlist/bar.lua b/tests/examples/awful/widget/layoutlist/bar.lua index a3bb6ffcd..7e03fb829 100644 --- a/tests/examples/awful/widget/layoutlist/bar.lua +++ b/tests/examples/awful/widget/layoutlist/bar.lua @@ -28,7 +28,7 @@ local beautiful = require("beautiful") --DOC_HIDE forced_num_cols = 3, layout = wibox.layout.grid.vertical, }, - widget_template = { + widget_template = wibox.template { { { id = 'icon_role', diff --git a/tests/examples/awful/widget/layoutlist/popup.lua b/tests/examples/awful/widget/layoutlist/popup.lua index 8eddca029..5645d5675 100644 --- a/tests/examples/awful/widget/layoutlist/popup.lua +++ b/tests/examples/awful/widget/layoutlist/popup.lua @@ -16,7 +16,7 @@ local modkey = "mod4" --DOC_HIDE forced_num_cols = 5, layout = wibox.layout.grid.vertical, }, - widget_template = { + widget_template = wibox.template { { { id = 'icon_role', diff --git a/tests/examples/sequences/client/swap_byidx1.lua b/tests/examples/sequences/client/swap_byidx1.lua index f1066735a..27674e72b 100644 --- a/tests/examples/sequences/client/swap_byidx1.lua +++ b/tests/examples/sequences/client/swap_byidx1.lua @@ -16,6 +16,7 @@ end local output = "" --DOC_NEWLINE for idx, c in ipairs(client.get()) do + assert(c.name ~= "Example Client") --DOC_HIDE output = output .. c.name .. ":" .. idx .. ", " end diff --git a/tests/examples/sequences/client/tasklist_widget_template1.lua b/tests/examples/sequences/client/tasklist_widget_template1.lua index 08e373cba..87cef35ec 100644 --- a/tests/examples/sequences/client/tasklist_widget_template1.lua +++ b/tests/examples/sequences/client/tasklist_widget_template1.lua @@ -53,7 +53,7 @@ module.display_widget(_tl, nil, 22) module.add_event("Change the widget template.", function() --DOC_HIDE_END -- Change the widget template. - tasklist.widget_template = { + tasklist.widget_template = wibox.template { { { { diff --git a/tests/examples/wibox/awidget/taglist/indexed.lua b/tests/examples/wibox/awidget/taglist/indexed.lua index 9be1d7a33..9a4fb9098 100644 --- a/tests/examples/wibox/awidget/taglist/indexed.lua +++ b/tests/examples/wibox/awidget/taglist/indexed.lua @@ -40,7 +40,7 @@ c2:tags(tags[1]) --DOC_HIDE }, layout = wibox.layout.fixed.horizontal }, - widget_template = { + widget_template = wibox.template { { { { @@ -80,6 +80,7 @@ c2:tags(tags[1]) --DOC_HIDE -- Add support for hover colors and an index label create_callback = function(self, c3, index, objects) --luacheck: no unused args self:get_children_by_id("index_role")[1].markup = " "..c3.index.." " + assert(self:get_children_by_id("index_role")[1]) --DOC_HIDE self:connect_signal("mouse::enter", function() if self.bg ~= "#ff0000" then diff --git a/tests/examples/wibox/awidget/tasklist/rounded.lua b/tests/examples/wibox/awidget/tasklist/rounded.lua index 348c76f98..6ad259d05 100644 --- a/tests/examples/wibox/awidget/tasklist/rounded.lua +++ b/tests/examples/wibox/awidget/tasklist/rounded.lua @@ -47,7 +47,7 @@ end --DOC_HIDE }, -- Notice that there is *NO* `wibox.wibox` prefix, it is a template, -- not a widget instance. - widget_template = { + widget_template = wibox.template { { { { diff --git a/tests/examples/wibox/awidget/tasklist/windows10.lua b/tests/examples/wibox/awidget/tasklist/windows10.lua index 8bf59c19b..dd6daf5c4 100644 --- a/tests/examples/wibox/awidget/tasklist/windows10.lua +++ b/tests/examples/wibox/awidget/tasklist/windows10.lua @@ -44,7 +44,7 @@ end --DOC_HIDE }, -- Notice that there is *NO* `wibox.wibox` prefix, it is a template, -- not a widget instance. - widget_template = { + widget_template = wibox.template { { wibox.widget.base.make_widget(), forced_height = 5, diff --git a/tests/examples/wibox/nwidget/actionlist/fancy.lua b/tests/examples/wibox/nwidget/actionlist/fancy.lua index e607b5e65..4e2d0f255 100644 --- a/tests/examples/wibox/nwidget/actionlist/fancy.lua +++ b/tests/examples/wibox/nwidget/actionlist/fancy.lua @@ -38,7 +38,7 @@ parent:add( wibox.container.background(--DOC_HIDE }, layout = wibox.layout.fixed.vertical }, - widget_template = { + widget_template = wibox.template { { { { diff --git a/tests/examples/wibox/nwidget/actionlist/fancy_icons.lua b/tests/examples/wibox/nwidget/actionlist/fancy_icons.lua index d341a3cdf..033e75917 100644 --- a/tests/examples/wibox/nwidget/actionlist/fancy_icons.lua +++ b/tests/examples/wibox/nwidget/actionlist/fancy_icons.lua @@ -41,7 +41,7 @@ parent:add( wibox.container.background(--DOC_HIDE }, layout = wibox.layout.flex.horizontal }, - widget_template = { + widget_template = wibox.template { { { { diff --git a/tests/examples/wibox/nwidget/rules/widget_template.lua b/tests/examples/wibox/nwidget/rules/widget_template.lua index d2d00d1f5..71b567220 100644 --- a/tests/examples/wibox/nwidget/rules/widget_template.lua +++ b/tests/examples/wibox/nwidget/rules/widget_template.lua @@ -13,7 +13,7 @@ beautiful.notification_bg = beautiful.bg_normal --DOC_HIDE ruled.notification.append_rule { rule = { app_name = "mdp" }, properties = { - widget_template = { + widget_template = wibox.template { { { {