1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
|
// SPDX-License-Identifier: GPL-2.0-only
/*
* Copyright (C) 2026 Danilo M. <danix@danix.xyz>
*/
#include <QtTest>
#include "threaddashboard.h"
#include "threaddigest.h"
class TestThreadDashboard : public QObject
{
Q_OBJECT
private slots:
void itNamesTheUnreadCountItWasGiven();
void itSaysAllCaughtUpWhenNothingIsUnread();
void itOffersMoreWhenTheListIsCapped();
void itOffersNoMoreLinkWhenTheListIsComplete();
};
static ThreadDigest digestWith(int unreadTotal, int shown)
{
ThreadDigest d;
d.threadId = QStringLiteral("t1");
d.totalCount = 44;
d.unreadTotal = unreadTotal;
for (int i = 0; i < shown; ++i) {
MessageNode ref;
ref.messageId = QStringLiteral("m%1@example.org").arg(i);
ref.subject = QStringLiteral("Re: something");
// The avatar hashes the bare address, so a node without one exercises
// only the no-sender fallback.
ref.senderAddress = QStringLiteral("someone@example.org");
d.unread.append(ref);
}
d.buckets = QVector<int>(ThreadDigest::kBuckets, 1);
return d;
}
void TestThreadDashboard::itNamesTheUnreadCountItWasGiven()
{
ThreadDashboard dashboard;
dashboard.setDigest(digestWith(3, 3));
QCOMPARE(dashboard.unreadCountShown(), 3);
QVERIFY(!dashboard.showingAllCaughtUp());
}
void TestThreadDashboard::itSaysAllCaughtUpWhenNothingIsUnread()
{
ThreadDashboard dashboard;
dashboard.setDigest(digestWith(0, 0));
QVERIFY2(dashboard.showingAllCaughtUp(),
"a fully read thread shows an empty Waiting for you block rather "
"than saying so");
}
void TestThreadDashboard::itOffersMoreWhenTheListIsCapped()
{
// 20 unread, 5 shown: the link has to name the 15 the pane cannot list, or
// the dashboard under-reports exactly when the number matters most.
ThreadDashboard dashboard;
dashboard.setDigest(digestWith(20, ThreadDigest::kUnreadShown));
QCOMPARE(dashboard.hiddenUnreadCount(), 15);
}
void TestThreadDashboard::itOffersNoMoreLinkWhenTheListIsComplete()
{
ThreadDashboard dashboard;
dashboard.setDigest(digestWith(4, 4));
QCOMPARE(dashboard.hiddenUnreadCount(), 0);
}
QTEST_MAIN(TestThreadDashboard)
#include "test_threaddashboard.moc"
|