// Copyright (C) 2026 Danilo M. // // This program is free software; you can redistribute it and/or modify // it under the terms of the GNU General Public License version 2 as // published by the Free Software Foundation. // // This program is distributed in the hope that it will be useful, // but WITHOUT ANY WARRANTY; without even the implied warranty of // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the // GNU General Public License for more details. package notify import ( "testing" "github.com/godbus/dbus/v5" ) func TestUrgencyFromHints(t *testing.T) { cases := []struct { name string hints map[string]dbus.Variant want Urgency }{ {"missing is normal", map[string]dbus.Variant{}, Normal}, {"low byte", map[string]dbus.Variant{"urgency": dbus.MakeVariant(byte(0))}, Low}, {"normal byte", map[string]dbus.Variant{"urgency": dbus.MakeVariant(byte(1))}, Normal}, {"critical byte", map[string]dbus.Variant{"urgency": dbus.MakeVariant(byte(2))}, Critical}, {"critical int32", map[string]dbus.Variant{"urgency": dbus.MakeVariant(int32(2))}, Critical}, {"wrong type is normal", map[string]dbus.Variant{"urgency": dbus.MakeVariant("2")}, Normal}, } for _, c := range cases { t.Run(c.name, func(t *testing.T) { if got := UrgencyFromHints(c.hints); got != c.want { t.Errorf("UrgencyFromHints = %q, want %q", got, c.want) } }) } } func TestEffectiveTimeoutMS(t *testing.T) { cases := []struct { name string expire int32 u Urgency want int64 }{ {"minus one uses low default", -1, Low, 10_000}, {"minus one uses normal default", -1, Normal, 10_000}, {"minus one critical never", -1, Critical, 0}, {"zero never", 0, Normal, 0}, {"explicit wins", 3_000, Normal, 3_000}, {"sub second exact", 1, Normal, 1}, } for _, c := range cases { t.Run(c.name, func(t *testing.T) { if got := EffectiveTimeoutMS(c.expire, c.u); got != c.want { t.Errorf("EffectiveTimeoutMS(%d, %q) = %d, want %d", c.expire, c.u, got, c.want) } }) } } func TestStackTagFromHints(t *testing.T) { dunst := map[string]dbus.Variant{"x-dunst-stack-tag": dbus.MakeVariant("mail-a")} danix := map[string]dbus.Variant{"x-danix-stack-tag": dbus.MakeVariant("mail-b")} both := map[string]dbus.Variant{ "x-dunst-stack-tag": dbus.MakeVariant("mail-a"), "x-danix-stack-tag": dbus.MakeVariant("mail-b"), } if got := StackTagFromHints(dunst); got != "mail-a" { t.Errorf("dunst tag = %q, want mail-a", got) } if got := StackTagFromHints(danix); got != "mail-b" { t.Errorf("danix tag = %q, want mail-b", got) } if got := StackTagFromHints(both); got != "mail-a" { t.Errorf("dunst wins when both present = %q, want mail-a", got) } if got := StackTagFromHints(map[string]dbus.Variant{}); got != "" { t.Errorf("empty = %q, want empty", got) } } func TestParseActions(t *testing.T) { got := ParseActions([]string{"default", "open", "other", "do the thing"}) want := [][2]string{{"default", "open"}, {"other", "do the thing"}} if len(got) != len(want) { t.Fatalf("len = %d, want %d", len(got), len(want)) } for i := range want { if got[i] != want[i] { t.Errorf("action %d = %v, want %v", i, got[i], want[i]) } } if got := ParseActions(nil); len(got) != 0 { t.Errorf("nil actions = %v, want empty", got) } }