aboutsummaryrefslogtreecommitdiffstats
path: root/tests/test_carddelegate.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'tests/test_carddelegate.cpp')
-rw-r--r--tests/test_carddelegate.cpp75
1 files changed, 75 insertions, 0 deletions
diff --git a/tests/test_carddelegate.cpp b/tests/test_carddelegate.cpp
index a14671d..bb21ae1 100644
--- a/tests/test_carddelegate.cpp
+++ b/tests/test_carddelegate.cpp
@@ -36,6 +36,10 @@ private slots:
void aSiblingChipIsMutedButStaysLegibleAndRecognisable();
void aSiblingChipFontIsSmallerThanItsOwnTier();
void aSiblingChipsPaddingShrinksWithItsFont();
+ void theFadeEndsAtSixtyPercentOfTheCard();
+ void aReplyFadeStartsAtItsOwnSpine();
+ void theDelegateAsksForAScaledSquircle();
+ void aRowWithNoSenderFallsBackToTheAccount();
};
namespace {
@@ -259,5 +263,76 @@ void TestCardDelegate::aSiblingChipsPaddingShrinksWithItsFont()
"on the chip's rounded end");
}
+void TestCardDelegate::theFadeEndsAtSixtyPercentOfTheCard()
+{
+ const QRect card(0, 0, 500, 60);
+ const QRect root = CardDelegate::fadeRectFor(card, QRect());
+ // Anchored at the card's RIGHT edge: the hard stop belongs where the card
+ // ends, not 60% across it, which read as a slab.
+ QCOMPARE(root.right(), card.right());
+ QCOMPARE(root.width(), 300);
+}
+
+void TestCardDelegate::aReplyFadeStartsAtItsOwnSpine()
+{
+ const QRect card(0, 0, 500, 60);
+ // The innermost spine of a nested reply, which is its own coloured border.
+ const QRect spine(80, 0, 2, 60);
+ // A spine deep enough to cut into the wash, which starts at 40% here.
+ const QRect deep(300, 0, 2, 60);
+ const QRect reply = CardDelegate::fadeRectFor(card, deep);
+
+ // Clamped at the spine, so the wash never runs under a reply's own border.
+ QCOMPARE(reply.left(), deep.left());
+ // Still anchored at the card's right edge, so a deeper reply's wash is
+ // shorter rather than displaced.
+ QCOMPARE(reply.right(), CardDelegate::fadeRectFor(card, QRect()).right());
+ QVERIFY(reply.width() < CardDelegate::fadeRectFor(card, QRect()).width());
+
+ // A shallow spine sits left of where the wash begins and changes nothing.
+ const QRect shallow(80, 0, 2, 60);
+ QCOMPARE(CardDelegate::fadeRectFor(card, shallow),
+ CardDelegate::fadeRectFor(card, QRect()));
+}
+
+void TestCardDelegate::theDelegateAsksForAScaledSquircle()
+{
+ // Asserted through the function the PRODUCTION path calls, not through
+ // Avatar::pixmapFor() directly: a test pointed at the function being
+ // called into proves what that function does and nothing about whether the
+ // delegate asks it for the right thing. CLAUDE.md records a mutation that
+ // survived exactly that mistake.
+ const QRect card(0, 0, 500, 60);
+ const QFont font;
+ const CardLayout layout =
+ CardLayout::compute(CardLayout::Input(), card, font);
+
+ const QPixmap pixmap = CardDelegate::avatarFor(
+ QStringLiteral("john@example.org"), QStringLiteral("John Doe"),
+ QStringLiteral("me@example.org"), QStringLiteral("Work"), false,
+ layout.avatarRect.width(), font);
+
+ QCOMPARE(pixmap.size(),
+ QSize(layout.avatarRect.width(), layout.avatarRect.width()));
+}
+
+void TestCardDelegate::aRowWithNoSenderFallsBackToTheAccount()
+{
+ const QFont font;
+ // No sender address at all: the squircle is still drawn, seeded from the
+ // account, so a card never shows a hole.
+ const QPixmap fallback = CardDelegate::avatarFor(
+ QString(), QString(), QStringLiteral("me@example.org"),
+ QStringLiteral("Work"), false, 44, font);
+ QVERIFY(!fallback.isNull());
+
+ // And it is the ACCOUNT's identity, not an arbitrary one: seeding from the
+ // same account twice agrees.
+ const QPixmap again = CardDelegate::avatarFor(
+ QString(), QString(), QStringLiteral("me@example.org"),
+ QStringLiteral("Work"), false, 44, font);
+ QCOMPARE(fallback.toImage(), again.toImage());
+}
+
QTEST_MAIN(TestCardDelegate)
#include "test_carddelegate.moc"