Skip to content

Commit

Permalink
tests: Test wibox.template :set_property().
Browse files Browse the repository at this point in the history
  • Loading branch information
Elv13 committed Oct 24, 2022
1 parent 623c7d5 commit f64c3e2
Show file tree
Hide file tree
Showing 17 changed files with 66 additions and 15 deletions.
2 changes: 1 addition & 1 deletion lib/awful/widget/common.lua
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
2 changes: 1 addition & 1 deletion lib/awful/widget/tasklist.lua
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
2 changes: 1 addition & 1 deletion lib/naughty/layout/box.lua
Original file line number Diff line number Diff line change
Expand Up @@ -176,7 +176,7 @@ end)
--
-- The default template is (less or more):
--
-- {
-- wibox.template {
-- {
-- {
-- {
Expand Down
49 changes: 49 additions & 0 deletions spec/wibox/widget/template_spec.lua
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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].foo, 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)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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,
{
Expand Down
2 changes: 1 addition & 1 deletion tests/examples/awful/popup/alttab.lua
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ local tasklist_buttons = nil --DOC_HIDE
layout = wibox.layout.grid.horizontal
},

widget_template = {
widget_template = wibox.template {
{
{
id = "clienticon",
Expand Down
2 changes: 1 addition & 1 deletion tests/examples/awful/popup/wiboxtypes.lua
Original file line number Diff line number Diff line change
Expand Up @@ -111,7 +111,7 @@ awful.popup {
forced_num_cols = 5,
layout = wibox.layout.grid.vertical,
},
widget_template = {
widget_template = wibox.template {
{
{
id = 'icon_role',
Expand Down
2 changes: 1 addition & 1 deletion tests/examples/awful/widget/layoutlist/bar.lua
Original file line number Diff line number Diff line change
Expand Up @@ -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',
Expand Down
2 changes: 1 addition & 1 deletion tests/examples/awful/widget/layoutlist/popup.lua
Original file line number Diff line number Diff line change
Expand Up @@ -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',
Expand Down
1 change: 1 addition & 0 deletions tests/examples/sequences/client/swap_byidx1.lua
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
{
{
{
Expand Down
3 changes: 2 additions & 1 deletion tests/examples/wibox/awidget/taglist/indexed.lua
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ c2:tags(tags[1]) --DOC_HIDE
},
layout = wibox.layout.fixed.horizontal
},
widget_template = {
widget_template = wibox.template {
{
{
{
Expand Down Expand Up @@ -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 = "<b> "..c3.index.." </b>"
assert(self:get_children_by_id("index_role")[1]) --DOC_HIDE

self:connect_signal("mouse::enter", function()
if self.bg ~= "#ff0000" then
Expand Down
2 changes: 1 addition & 1 deletion tests/examples/wibox/awidget/tasklist/rounded.lua
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
{
{
{
Expand Down
2 changes: 1 addition & 1 deletion tests/examples/wibox/awidget/tasklist/windows10.lua
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
2 changes: 1 addition & 1 deletion tests/examples/wibox/nwidget/actionlist/fancy.lua
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ parent:add( wibox.container.background(--DOC_HIDE
},
layout = wibox.layout.fixed.vertical
},
widget_template = {
widget_template = wibox.template {
{
{
{
Expand Down
2 changes: 1 addition & 1 deletion tests/examples/wibox/nwidget/actionlist/fancy_icons.lua
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ parent:add( wibox.container.background(--DOC_HIDE
},
layout = wibox.layout.flex.horizontal
},
widget_template = {
widget_template = wibox.template {
{
{
{
Expand Down
2 changes: 1 addition & 1 deletion tests/examples/wibox/nwidget/rules/widget_template.lua
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
{
{
{
Expand Down

0 comments on commit f64c3e2

Please # to comment.