33
28
QSharedPointer<Notification> n(new Notification(42, timeout, Notification::Low, "this is text"));
34
29
NotificationModel m;
36
QCOMPARE(m.numNotifications(), 1);
31
QCOMPARE(m.numNotifications(), 0);
37
32
m.insertNotification(n);
38
QCOMPARE(m.numNotifications(), 2);
33
QCOMPARE(m.numNotifications(), 1);
39
34
m.removeNotification(n->getID());
40
QCOMPARE(m.numNotifications(), 1);
35
QCOMPARE(m.numNotifications(), 0);
43
38
void TestNotifications::testTypeSimple() {
60
55
const int timeout = 1000;
61
56
static NotificationModel *m = new NotificationModel(this);
62
57
static NotificationServer *s = new NotificationServer(QDBusConnection::sessionBus(), *m);
63
QStringList actions = QStringList();
67
62
hints[URGENCY_HINT] = QVariant::fromValue(Notification::Urgency::Low);
68
63
id[0] = s->Notify ("test-name-low", 0, "icon-low", "summary-low", "body-low", actions, hints, timeout);
71
66
hints[URGENCY_HINT] = QVariant::fromValue(Notification::Urgency::Normal);
72
67
id[1] = s->Notify ("test-name-normal", 0, "icon-normal", "summary-normal", "body-normal", actions, hints, timeout);
73
QVERIFY(!m->showingNotification(id[0]));
68
QVERIFY(m->showingNotification(id[0]));
74
69
QVERIFY(m->showingNotification(id[1]));
75
QVERIFY(m->queued() == 1);
70
QVERIFY(m->getNotification(id[1]) == m->getDisplayedNotification(0)); // verify it's ordered by urgency
71
QVERIFY(m->queued() == 0);
77
73
hints[URGENCY_HINT] = QVariant::fromValue(Notification::Urgency::Critical);
78
74
id[2] = s->Notify ("test-name-critical", 0, "icon-critical", "summary-critical", "body-critical", actions, hints, timeout);
79
QVERIFY(!m->showingNotification(id[0]));
80
QVERIFY(!m->showingNotification(id[1]));
81
QVERIFY(m->showingNotification(id[2]));
82
QCOMPARE(m->queued(), 2);
75
QVERIFY(m->showingNotification(id[0]));
76
QVERIFY(m->showingNotification(id[1]));
77
QVERIFY(m->showingNotification(id[2]));
78
QVERIFY(m->getNotification(id[2]) == m->getDisplayedNotification(0)); // verify it's ordered by urgency
79
QCOMPARE(m->queued(), 0);
81
hints[SNAP_HINT] = QStringLiteral("true");
82
hints[URGENCY_HINT] = QVariant::fromValue(Notification::Urgency::Normal);
83
id[3] = s->Notify ("test-name-snap", 0, "icon-snap", "summary-snap", "body-snap", {"snap", "decision", "needs", "actions"}, hints, timeout);
84
QVERIFY(m->showingNotification(id[0]));
85
QVERIFY(m->showingNotification(id[1]));
86
QVERIFY(m->showingNotification(id[2]));
87
QVERIFY(m->showingNotification(id[3]));
88
QVERIFY(m->getNotification(id[3]) == m->getDisplayedNotification(0)); // verify it's ordered by urgency and type, snap comes first
89
QCOMPARE(m->queued(), 0);
91
m->removeNotification(id[3]);
92
QVERIFY(m->showingNotification(id[0]));
93
QVERIFY(m->showingNotification(id[1]));
94
QVERIFY(m->showingNotification(id[2]));
95
QVERIFY(!m->showingNotification(id[3]));
96
QCOMPARE(m->queued(), 0);
84
98
m->removeNotification(id[2]);
85
QVERIFY(!m->showingNotification(id[0]));
99
QVERIFY(m->showingNotification(id[0]));
86
100
QVERIFY(m->showingNotification(id[1]));
87
101
QVERIFY(!m->showingNotification(id[2]));
88
QCOMPARE(m->queued(), 1);
102
QCOMPARE(m->queued(), 0);
90
104
m->removeNotification(id[1]);
91
105
QVERIFY(m->showingNotification(id[0]));
190
204
m.insertNotification(n3);
191
205
m.insertNotification(n4);
193
QCOMPARE(m.getDisplayedNotification(4)->getBody(), QString("snap-decision-1"));
194
QCOMPARE(m.getDisplayedNotification(3)->getBody(), QString("snap-decision-2"));
195
QCOMPARE(m.getDisplayedNotification(2)->getBody(), QString("snap-decision-3"));
196
QCOMPARE(m.getDisplayedNotification(1)->getBody(), QString("snap-decision-4"));
207
QCOMPARE(m.getDisplayedNotification(3)->getBody(), QString("snap-decision-1"));
208
QCOMPARE(m.getDisplayedNotification(2)->getBody(), QString("snap-decision-2"));
209
QCOMPARE(m.getDisplayedNotification(1)->getBody(), QString("snap-decision-3"));
210
QCOMPARE(m.getDisplayedNotification(0)->getBody(), QString("snap-decision-4"));
199
213
void TestNotifications::testConfirmationValue() {
213
227
m.insertNotification(ephemeral);
214
228
m.insertNotification(confirmation);
216
QCOMPARE(m.getDisplayedNotification(2)->getBody(), QString("ephemeral"));
217
QCOMPARE(m.getDisplayedNotification(1)->getBody(), QString(""));
230
QCOMPARE(m.getDisplayedNotification(1)->getBody(), QString("ephemeral"));
231
QCOMPARE(m.getDisplayedNotification(0)->getBody(), QString(""));
220
234
void TestNotifications::testTextFilter_data() {
291
QCOMPARE(m->numNotifications(), max+1);
305
QCOMPARE(m->numNotifications(), max);
293
307
for (int i = max; i >= 1; i--) {
294
308
m->getNotification(i)->close();
295
QCOMPARE(m->numNotifications(), i);
309
QCOMPARE(m->numNotifications(), i-1);
298
312
QCOMPARE(m->numNotifications(), before);