tests: Test `wibox.template` `:set_property()`.

This commit is contained in:
Emmanuel Lepage Vallee 2022-10-23 00:20:25 -07:00
parent 8fc30ae693
commit 452d21a634
17 changed files with 66 additions and 15 deletions

View File

@ -71,7 +71,7 @@ end
local function default_template() local function default_template()
return custom_template { return custom_template {
widget_template = { widget_template = wibox.template {
id = 'background_role', id = 'background_role',
border_strategy = 'inner', border_strategy = 'inner',
widget = wibox.container.background, widget = wibox.container.background,

View File

@ -392,7 +392,7 @@ local function default_template(self)
or self._private.style.tasklist_disable_icon or self._private.style.tasklist_disable_icon
or beautiful.tasklist_disable_icon or beautiful.tasklist_disable_icon
return { return wtemplate {
{ {
(not has_no_icon) and { (not has_no_icon) and {
clienticon, clienticon,

View File

@ -176,7 +176,7 @@ end)
-- --
-- The default template is (less or more): -- The default template is (less or more):
-- --
-- { -- wibox.template {
-- { -- {
-- { -- {
-- { -- {

View File

@ -7,6 +7,7 @@ _G.awesome.connect_signal = function() end
local gtimer = require("gears.timer") local gtimer = require("gears.timer")
local template = require("wibox.template") local template = require("wibox.template")
local base = require("wibox.widget.base").make_widget
describe("wibox.template", function() describe("wibox.template", function()
local widget local widget
@ -80,6 +81,54 @@ describe("wibox.template", function()
match.is_same { foo = "bar", bar = 10 } match.is_same { foo = "bar", bar = 10 }
) )
end) 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)
end) end)

View File

@ -44,7 +44,7 @@ beautiful.notification_action_label_only = true --DOC_HIDE
spacing = 3, spacing = 3,
layout = wibox.layout.flex.horizontal layout = wibox.layout.flex.horizontal
}, },
widget_template = { widget_template = wibox.template {
{ {
naughty.widget.icon, naughty.widget.icon,
{ {

View File

@ -31,7 +31,7 @@ local tasklist_buttons = nil --DOC_HIDE
layout = wibox.layout.grid.horizontal layout = wibox.layout.grid.horizontal
}, },
widget_template = { widget_template = wibox.template {
{ {
{ {
id = "clienticon", id = "clienticon",

View File

@ -111,7 +111,7 @@ awful.popup {
forced_num_cols = 5, forced_num_cols = 5,
layout = wibox.layout.grid.vertical, layout = wibox.layout.grid.vertical,
}, },
widget_template = { widget_template = wibox.template {
{ {
{ {
id = 'icon_role', id = 'icon_role',

View File

@ -28,7 +28,7 @@ local beautiful = require("beautiful") --DOC_HIDE
forced_num_cols = 3, forced_num_cols = 3,
layout = wibox.layout.grid.vertical, layout = wibox.layout.grid.vertical,
}, },
widget_template = { widget_template = wibox.template {
{ {
{ {
id = 'icon_role', id = 'icon_role',

View File

@ -16,7 +16,7 @@ local modkey = "mod4" --DOC_HIDE
forced_num_cols = 5, forced_num_cols = 5,
layout = wibox.layout.grid.vertical, layout = wibox.layout.grid.vertical,
}, },
widget_template = { widget_template = wibox.template {
{ {
{ {
id = 'icon_role', id = 'icon_role',

View File

@ -16,6 +16,7 @@ end
local output = "" local output = ""
--DOC_NEWLINE --DOC_NEWLINE
for idx, c in ipairs(client.get()) do for idx, c in ipairs(client.get()) do
assert(c.name ~= "Example Client") --DOC_HIDE
output = output .. c.name .. ":" .. idx .. ", " output = output .. c.name .. ":" .. idx .. ", "
end end

View File

@ -53,7 +53,7 @@ module.display_widget(_tl, nil, 22)
module.add_event("Change the widget template.", function() module.add_event("Change the widget template.", function()
--DOC_HIDE_END --DOC_HIDE_END
-- Change the widget template. -- Change the widget template.
tasklist.widget_template = { tasklist.widget_template = wibox.template {
{ {
{ {
{ {

View File

@ -40,7 +40,7 @@ c2:tags(tags[1]) --DOC_HIDE
}, },
layout = wibox.layout.fixed.horizontal 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 -- Add support for hover colors and an index label
create_callback = function(self, c3, index, objects) --luacheck: no unused args create_callback = function(self, c3, index, objects) --luacheck: no unused args
self:get_children_by_id("index_role")[1].markup = "<b> "..c3.index.." </b>" self:get_children_by_id("index_role")[1].markup = "<b> "..c3.index.." </b>"
assert(self:get_children_by_id("index_role")[1]) --DOC_HIDE
self:connect_signal("mouse::enter", function() self:connect_signal("mouse::enter", function()
if self.bg ~= "#ff0000" then if self.bg ~= "#ff0000" then

View File

@ -47,7 +47,7 @@ end --DOC_HIDE
}, },
-- Notice that there is *NO* `wibox.wibox` prefix, it is a template, -- Notice that there is *NO* `wibox.wibox` prefix, it is a template,
-- not a widget instance. -- not a widget instance.
widget_template = { widget_template = wibox.template {
{ {
{ {
{ {

View File

@ -44,7 +44,7 @@ end --DOC_HIDE
}, },
-- Notice that there is *NO* `wibox.wibox` prefix, it is a template, -- Notice that there is *NO* `wibox.wibox` prefix, it is a template,
-- not a widget instance. -- not a widget instance.
widget_template = { widget_template = wibox.template {
{ {
wibox.widget.base.make_widget(), wibox.widget.base.make_widget(),
forced_height = 5, forced_height = 5,

View File

@ -38,7 +38,7 @@ parent:add( wibox.container.background(--DOC_HIDE
}, },
layout = wibox.layout.fixed.vertical layout = wibox.layout.fixed.vertical
}, },
widget_template = { widget_template = wibox.template {
{ {
{ {
{ {

View File

@ -41,7 +41,7 @@ parent:add( wibox.container.background(--DOC_HIDE
}, },
layout = wibox.layout.flex.horizontal layout = wibox.layout.flex.horizontal
}, },
widget_template = { widget_template = wibox.template {
{ {
{ {
{ {

View File

@ -13,7 +13,7 @@ beautiful.notification_bg = beautiful.bg_normal --DOC_HIDE
ruled.notification.append_rule { ruled.notification.append_rule {
rule = { app_name = "mdp" }, rule = { app_name = "mdp" },
properties = { properties = {
widget_template = { widget_template = wibox.template {
{ {
{ {
{ {