Files
dotfiles/quickshell/tests/tst_notifications.qml
T
2026-11-17 18:15:16 +07:00

35 lines
1.5 KiB
QML

import QtQuick
import QtTest
import "../services/NotificationPolicy.js" as Policy
TestCase {
name: "NotificationPolicy"
function test_timeout() {
compare(Policy.timeoutMs(-1, 0), 3000);
compare(Policy.timeoutMs(-1, 1), 6000);
compare(Policy.timeoutMs(250, 1), 250);
compare(Policy.timeoutMs(0, 1), 0);
compare(Policy.timeoutMs(1, 2), 0);
compare(Policy.timeoutMs(1e20, 1), 2147483647);
}
function entry(key) { return {key: key, appName: "Test", summary: "Summary", body: "Body", state: "received", urgency: 1, time: 100}; }
function test_history_limit_and_replace() {
let history = [];
for (let i = 0; i < 110; i++) history = Policy.upsert(history, entry(String(i)));
compare(history.length, 100);
compare(history[0].key, "109");
const replacement = entry("109"); replacement.summary = "Updated";
history = Policy.upsert(history, replacement);
compare(history.length, 100);
compare(history[0].summary, "Updated");
}
function test_validation() {
compare(Policy.validate({version: 1, entries: [entry("a")]}).length, 1);
for (const invalid of [{version: 2, entries: []}, {version: 1, entries: [entry("a"), entry("a")]}, {version: 1, entries: [{key: "bad"}]}, {version: 1, entries: [Object.assign(entry("a"), {deadline: "soon"})]}]) {
let rejected = false;
try { Policy.validate(invalid); } catch(e) { rejected = true; }
verify(rejected);
}
}
}