From 504bf53b8cb6706c18f7aa1ffae138d73d35dcd7 Mon Sep 17 00:00:00 2001 From: Lucas Schwiderski Date: Wed, 10 Mar 2021 20:36:26 +0100 Subject: [PATCH] Add unit test for wrapping a margin container This adds a test case where a `wibox.container.margin` with a `wibox.widget.imagebox` as child is wrapped by a simple function call. Check against regression in #3213. Signed-off-by: Lucas Schwiderski --- spec/wibox/container/margin_spec.lua | 47 ++++++++++++++++++++++++++++ 1 file changed, 47 insertions(+) diff --git a/spec/wibox/container/margin_spec.lua b/spec/wibox/container/margin_spec.lua index ad668ad6f..7e9a0af47 100644 --- a/spec/wibox/container/margin_spec.lua +++ b/spec/wibox/container/margin_spec.lua @@ -3,13 +3,60 @@ -- @copyright 2017 Uli Schlachter --------------------------------------------------------------------------- +local base = require('wibox.widget.base') local margin = require("wibox.container.margin") +local imagebox = require("wibox.widget.imagebox") local utils = require("wibox.test_utils") describe("wibox.container.margin", function() it("common interfaces", function() utils.test_container(margin()) end) + + describe("composite widgets", function() + it("can be wrapped with child", function() + local widget_name = "test_widget" + local new = function() + local ret = base.make_widget_declarative { + { + id = "img", + widget = imagebox, + }, + widget = margin, + } + + ret.widget_name = widget_name + + return ret + end + + local widget = base.make_widget_declarative { + widget = new, + } + + assert.is.equal( + widget_name, + widget.widget_name, + "Widget name doesn't match" + ) + local children = widget:get_children() + assert.is_not.Nil(children, "Widget doesn't have children") + assert.is.equal( + 1, + #children, + "Widget should have exactly one child" + ) + assert.is.True( + children[1].is_widget, + "Child widget should be a valid widget" + ) + assert.is.equal( + widget.img, + children[1], + "Child widget should match the id accessor" + ) + end) + end) end) -- vim: filetype=lua:expandtab:shiftwidth=4:tabstop=8:softtabstop=4:textwidth=80