From 0e7ae1cb25f19415688e5712faf09ddf36894911 Mon Sep 17 00:00:00 2001 From: Uli Schlachter Date: Sun, 21 Jun 2015 14:53:16 +0200 Subject: [PATCH] align layout: Test signal emission Signed-off-by: Uli Schlachter --- lib/wibox/layout/align.lua | 9 +++++++ spec/wibox/layout/align_spec.lua | 44 ++++++++++++++++++++++++++++++++ 2 files changed, 53 insertions(+) diff --git a/lib/wibox/layout/align.lua b/lib/wibox/layout/align.lua index eb88cfffc..e31fb7242 100644 --- a/lib/wibox/layout/align.lua +++ b/lib/wibox/layout/align.lua @@ -139,18 +139,27 @@ end --- Set the layout's first widget. This is the widget that is at the left/top function align:set_first(widget) + if self.first == widget then + return + end self.first = widget self:emit_signal("widget::layout_changed") end --- Set the layout's second widget. This is the centered one. function align:set_second(widget) + if self.second == widget then + return + end self.second = widget self:emit_signal("widget::layout_changed") end --- Set the layout's third widget. This is the widget that is at the right/bottom function align:set_third(widget) + if self.third == widget then + return + end self.third = widget self:emit_signal("widget::layout_changed") end diff --git a/spec/wibox/layout/align_spec.lua b/spec/wibox/layout/align_spec.lua index 1c0434cd7..81ad7a40b 100644 --- a/spec/wibox/layout/align_spec.lua +++ b/spec/wibox/layout/align_spec.lua @@ -222,6 +222,50 @@ describe("wibox.layout.align", function() end) end) end) + + describe("emitting signals", function() + local layout, layout_changed + before_each(function() + layout = align.vertical() + layout:connect_signal("widget::layout_changed", function() + layout_changed = layout_changed + 1 + end) + layout_changed = 0 + end) + + it("set first", function() + local w1, w2 = {}, {} + assert.is.equal(layout_changed, 0) + layout:set_first(w1) + assert.is.equal(layout_changed, 1) + layout:set_first(w2) + assert.is.equal(layout_changed, 2) + layout:set_first(w2) + assert.is.equal(layout_changed, 2) + end) + + it("set second", function() + local w1, w2 = {}, {} + assert.is.equal(layout_changed, 0) + layout:set_second(w1) + assert.is.equal(layout_changed, 1) + layout:set_second(w2) + assert.is.equal(layout_changed, 2) + layout:set_second(w2) + assert.is.equal(layout_changed, 2) + end) + + it("set third", function() + local w1, w2 = {}, {} + assert.is.equal(layout_changed, 0) + layout:set_third(w1) + assert.is.equal(layout_changed, 1) + layout:set_third(w2) + assert.is.equal(layout_changed, 2) + layout:set_third(w2) + assert.is.equal(layout_changed, 2) + end) + end) end) -- vim: filetype=lua:expandtab:shiftwidth=4:tabstop=8:softtabstop=4:textwidth=80