tests: Test the notification presets.

Make sure they behave the same in legacy and ruled modes.
This commit is contained in:
Emmanuel Lepage Vallee 2021-09-16 16:40:15 -07:00
parent 9336b62f80
commit 552b2a22d1
2 changed files with 166 additions and 74 deletions

View File

@ -0,0 +1,85 @@
local naughty = require("naughty")
local notification = require("naughty.notification")
require("ruled.notification"):_clear()
local steps = {}
local BAD_IDEA = "never do this in practice, compat only"
local notif = setmetatable({}, {__mode="v"})
screen[1]:split()
for _, legacy_preset in ipairs {true, false} do
table.insert(steps, function()
-- This will either take the legacy preset path
-- or the ruled preset path.
function naughty.get__has_preset_handler()
return legacy_preset
end
local custom_preset = {
bg = "#00ff00",
fg = "#ff0000",
text = BAD_IDEA
}
notif[1] = notification {
preset = custom_preset,
}
assert(notif[1].bg == "#00ff00")
assert(notif[1].message == BAD_IDEA)
return true
end)
table.insert(steps, function()
notif[1]:destroy()
return true
end)
for s in screen do
-- Make sure the screen doesn't cause a memory leak.
table.insert(steps, function()
collectgarbage("collect")
if notif[1] then return end
local custom_preset = {
bg = "#0000ff",
fg = "#ff0000",
screen = s
}
notif[1] = notification {
preset = custom_preset,
title = "test",
}
assert(notif[1].bg == "#0000ff")
assert(notif[1].screen == s)
return true
end)
table.insert(steps, function()
assert(notif[1].screen == s)
notif[1]:destroy()
return true
end)
table.insert(steps, function()
collectgarbage("collect")
if notif[1] then return end
return true
end)
end
end
require("_runner").run_steps(steps)

View File

@ -71,16 +71,22 @@ local function check_screen(s)
end
end
-- Create notifications in each position.
table.insert(steps, function()
for _, legacy_preset in ipairs {true, false} do
-- Create notifications in each position.
table.insert(steps, function()
function naughty.get__has_preset_handler()
return legacy_preset
end
rnotif._clear()
add_many(s1)
return true
end)
end)
-- Make sure removing notification works.
table.insert(steps, function()
-- Make sure removing notification works.
table.insert(steps, function()
remove_at(s1, 2)
@ -91,10 +97,10 @@ table.insert(steps, function()
assert(s1 ~= s2)
return true
end)
end)
-- Make sure the notification moved as the screen shrunk.
table.insert(steps, function()
-- Make sure the notification moved as the screen shrunk.
table.insert(steps, function()
check_screen(s1)
-- Make sure we can still remove them without errors.
@ -109,10 +115,10 @@ table.insert(steps, function()
check_screen(s2)
return true
end)
end)
-- Remove everything and see what happens.
table.insert(steps, function()
-- Remove everything and see what happens.
table.insert(steps, function()
for _=1, 3 do
for _, s in ipairs {s1,s2} do
@ -129,12 +135,12 @@ table.insert(steps, function()
add_many(s2)
return true
end)
end)
--local weak = nil --FIXME
local weak = nil
-- Delete a screen and make sure it gets GCed.
table.insert(steps, function()
-- Delete a screen and make sure it gets GCed.
table.insert(steps, function()
s2:fake_remove()
-- Help the weak tables a little.
@ -143,18 +149,19 @@ table.insert(steps, function()
end
-- Drop our string reference to s2.
--weak, s2 = setmetatable({s2}, {__mode="v"}), nil --FIXME
weak, s2 = setmetatable({s2}, {__mode="v"}), nil
return true
end)
end)
--FIXME
--table.insert(steps, function()
-- if weak[1] == nil then return true end
--
-- for _=1, 10 do
-- collectgarbage("collect")
-- end
--end)
table.insert(steps, function()
if weak[1] == nil then return true end
for _=1, 10 do
collectgarbage("collect")
end
end)
end
require("_runner").run_steps(steps)