aboutsummaryrefslogtreecommitdiffstats
path: root/tests/test_threadlistmodel.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'tests/test_threadlistmodel.cpp')
-rw-r--r--tests/test_threadlistmodel.cpp81
1 files changed, 81 insertions, 0 deletions
diff --git a/tests/test_threadlistmodel.cpp b/tests/test_threadlistmodel.cpp
index 593a777..9ca35e3 100644
--- a/tests/test_threadlistmodel.cpp
+++ b/tests/test_threadlistmodel.cpp
@@ -102,6 +102,9 @@ private slots:
void flatModeOffersNoExpanderAndNoReplyCount();
void flatModeIsOffByDefaultAndReversible();
void recipientsReplaceTheSenderWhenPresent();
+ void aRowCarriesItsSenderAndAccountAddress();
+ void aMessageRowCarriesItsOwnSenderAndAddress();
+ void aFlatViewsAvatarFollowsTheRecipient();
};
static ThreadSummary makeThread(const QString &id, const QString &subject)
@@ -510,6 +513,84 @@ void TestThreadListModel::reportsSubjectAndAuthors()
QStringList({ QStringLiteral("inbox"), QStringLiteral("unread") }));
}
+void TestThreadListModel::aRowCarriesItsSenderAndAccountAddress()
+{
+ // Task 8: the avatar needs the row's bare sender address to hash and to
+ // match against the business-senders list, and the display name to take
+ // initials from. Both come from the row itself, not from the load.
+ ThreadListModel model;
+ ThreadSummary summary;
+ summary.threadId = QStringLiteral("t1");
+ summary.subject = QStringLiteral("Subject");
+ summary.authors = QStringLiteral("John Doe");
+ summary.firstMessageId = QStringLiteral("m1");
+ summary.firstMessageSender = QStringLiteral("john@example.org");
+ model.appendBatch({ summary });
+
+ const QModelIndex index = model.index(0, 0);
+ QCOMPARE(index.data(ThreadListModel::SenderAddressRole).toString(),
+ QStringLiteral("john@example.org"));
+ // The display name comes from `authors`, which is all notmuch gives.
+ QCOMPARE(index.data(ThreadListModel::SenderNameRole).toString(),
+ QStringLiteral("John Doe"));
+}
+
+void TestThreadListModel::aMessageRowCarriesItsOwnSenderAndAddress()
+{
+ // Task 8 counterpart of aRowCarriesItsSenderAndAccountAddress: that test
+ // covers the thread-row branch, and a role added to one branch and not the
+ // other is silently absent with nothing to flag it. A selected reply's
+ // avatar reads these, so the row that actually answers must carry them.
+ ThreadListModel model;
+ model.appendBatch({ makeThread(QStringLiteral("t1"),
+ QStringLiteral("A subject")) });
+
+ MessageNode root = makeNode(QStringLiteral("m0@example.org"), 0);
+ MessageNode reply = makeNode(QStringLiteral("m1@example.org"), 1,
+ QStringLiteral("Bob <bob@example.org>"));
+ reply.senderAddress = QStringLiteral("bob@example.org");
+ model.setThreadMessages(QStringLiteral("t1"), { root, reply });
+
+ const QModelIndex replyIndex =
+ model.index(0, 0, model.index(0, 0, QModelIndex()));
+ QVERIFY(model.isMessageRow(replyIndex));
+
+ QCOMPARE(replyIndex.data(ThreadListModel::SenderAddressRole).toString(),
+ QStringLiteral("bob@example.org"));
+ QCOMPARE(replyIndex.data(ThreadListModel::SenderNameRole).toString(),
+ QStringLiteral("Bob <bob@example.org>"));
+}
+
+void TestThreadListModel::aFlatViewsAvatarFollowsTheRecipient()
+{
+ // In a Sent or Drafts view firstMessageSender is the USER on every row, so
+ // hashing it gives one pattern for the whole list. The recipient is what
+ // the row is about, and SendersRole already follows the same rule.
+ ThreadListModel model;
+ ThreadSummary summary;
+ summary.threadId = QStringLiteral("t1");
+ summary.subject = QStringLiteral("Subject");
+ summary.authors = QStringLiteral("Me");
+ summary.firstMessageId = QStringLiteral("m1");
+ summary.firstMessageSender = QStringLiteral("me@example.org");
+ summary.recipients = QStringLiteral("John Doe");
+ summary.firstMessageRecipient = QStringLiteral("john@example.org");
+ model.appendBatch({ summary });
+
+ QCOMPARE(model.index(0, 0).data(ThreadListModel::SenderAddressRole)
+ .toString(),
+ QStringLiteral("john@example.org"));
+
+ // No usable To: the sender is the fallback rather than a blank seed.
+ ThreadListModel bare;
+ summary.recipients.clear();
+ summary.firstMessageRecipient.clear();
+ bare.appendBatch({ summary });
+ QCOMPARE(bare.index(0, 0).data(ThreadListModel::SenderAddressRole)
+ .toString(),
+ QStringLiteral("me@example.org"));
+}
+
void TestThreadListModel::theReplyCountExcludesTheRootMessage()
{
ThreadListModel model;