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.cpp178
1 files changed, 178 insertions, 0 deletions
diff --git a/tests/test_threadlistmodel.cpp b/tests/test_threadlistmodel.cpp
index 811b3e3..9ca35e3 100644
--- a/tests/test_threadlistmodel.cpp
+++ b/tests/test_threadlistmodel.cpp
@@ -27,6 +27,9 @@ class TestThreadListModel : public QObject
{
Q_OBJECT
private slots:
+ void aRowLeavesTheViewWhenItLosesTheViewsTag();
+ void rowsLosingTheTagAreRemovedInOneContiguousRun();
+ void theTrashViewDrawsNoDoomedFill();
void messageNodeHoldsDisplayFacts();
void rootRowsSurviveTheTreeConversion();
void repliesBecomeChildRowsUnderTheirThread();
@@ -99,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)
@@ -507,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;
@@ -2165,5 +2249,99 @@ void TestThreadListModel::recipientsReplaceTheSenderWhenPresent()
QStringLiteral("You"));
}
+void TestThreadListModel::aRowLeavesTheViewWhenItLosesTheViewsTag()
+{
+ ThreadListModel model;
+ ThreadSummary a = makeThread(QStringLiteral("t1"), QStringLiteral("Keep"));
+ a.firstMessageId = QStringLiteral("m1");
+ ThreadSummary b = makeThread(QStringLiteral("t2"), QStringLiteral("Drop"));
+ b.firstMessageId = QStringLiteral("m2");
+ ThreadSummary c = makeThread(QStringLiteral("t3"), QStringLiteral("Keep2"));
+ c.firstMessageId = QStringLiteral("m3");
+ model.appendBatch({ a, b, c });
+ QCOMPARE(model.rowCount(), 3);
+
+ // The middle row loses `inbox`, as Delete strips it. Middle deliberately:
+ // a removal at either end can be right by accident while the index
+ // arithmetic is wrong.
+ model.applyMessageTagChange(QStringLiteral("m2"), {},
+ { QStringLiteral("inbox") });
+ model.removeThreadsWithoutTag(QStringLiteral("inbox"));
+
+ QCOMPARE(model.rowCount(), 2);
+ QCOMPARE(model.index(0, 0, QModelIndex())
+ .data(ThreadListModel::SubjectRole).toString(),
+ QStringLiteral("Keep"));
+ QCOMPARE(model.index(1, 0, QModelIndex())
+ .data(ThreadListModel::SubjectRole).toString(),
+ QStringLiteral("Keep2"));
+}
+
+void TestThreadListModel::rowsLosingTheTagAreRemovedInOneContiguousRun()
+{
+ ThreadListModel model;
+ QList<ThreadSummary> batch;
+ for (int i = 1; i <= 5; ++i) {
+ ThreadSummary t = makeThread(QStringLiteral("t%1").arg(i),
+ QStringLiteral("S%1").arg(i));
+ t.firstMessageId = QStringLiteral("m%1").arg(i);
+ batch.append(t);
+ }
+ model.appendBatch(batch);
+
+ // Three adjacent rows go at once, which is the case a backwards walk in
+ // runs handles and a naive forward loop gets wrong by renumbering.
+ for (const QString &id : { QStringLiteral("m2"), QStringLiteral("m3"),
+ QStringLiteral("m4") }) {
+ model.applyMessageTagChange(id, {}, { QStringLiteral("inbox") });
+ }
+ model.removeThreadsWithoutTag(QStringLiteral("inbox"));
+
+ QCOMPARE(model.rowCount(), 2);
+ QCOMPARE(model.index(0, 0, QModelIndex())
+ .data(ThreadListModel::SubjectRole).toString(),
+ QStringLiteral("S1"));
+ QCOMPARE(model.index(1, 0, QModelIndex())
+ .data(ThreadListModel::SubjectRole).toString(),
+ QStringLiteral("S5"));
+}
+
+void TestThreadListModel::theTrashViewDrawsNoDoomedFill()
+{
+ ThreadListModel model;
+ ThreadSummary deleted = makeThread(QStringLiteral("t1"),
+ QStringLiteral("Thrown away"));
+ deleted.tags = QStringList{ QStringLiteral("deleted") };
+ ThreadSummary spam = makeThread(QStringLiteral("t2"),
+ QStringLiteral("Junk"));
+ spam.tags = QStringList{ QStringLiteral("deleted"), QStringLiteral("spam") };
+ model.appendBatch({ deleted, spam });
+
+ const QModelIndex first = model.index(0, 0, QModelIndex());
+ const QModelIndex second = model.index(1, 0, QModelIndex());
+
+ // Outside the trash both are filled, which is the guard proving the
+ // assertion below can fail.
+ QVERIFY(first.data(Qt::BackgroundRole).isValid());
+ QVERIFY(second.data(Qt::BackgroundRole).isValid());
+
+ model.setTrashView(true);
+
+ // A plainly deleted row loses the fill AND the white text that only reads
+ // against it; the strike-out is what still says deleted, and is asserted
+ // by the font role rather than by colour.
+ QVERIFY(!first.data(Qt::BackgroundRole).isValid());
+ QVERIFY(first.data(Qt::FontRole).value<QFont>().strikeOut());
+
+ // A spam row keeps its tint: the trash promises "thrown away", not
+ // "harmless".
+ QVERIFY(second.data(Qt::BackgroundRole).isValid());
+
+ // And the flag does not stick: leaving the trash restores the fill, which
+ // is the leak the setter's comment warns about.
+ model.setTrashView(false);
+ QVERIFY(first.data(Qt::BackgroundRole).isValid());
+}
+
QTEST_MAIN(TestThreadListModel)
#include "test_threadlistmodel.moc"