diff options
| author | Danilo M. <danix@danix.xyz> | 2026-08-24 20:15:17 +0200 |
|---|---|---|
| committer | Danilo M. <danix@danix.xyz> | 2026-08-24 20:15:17 +0200 |
| commit | 160c9121ec39d934330cf626978d02d0fa6d0610 (patch) | |
| tree | a01e1aeb59e1ae0436785d9328ff939829465e99 /tests | |
| parent | afeacd7cb99db7fcf4d677dbe8dd52b10e1284e0 (diff) | |
| download | qtmaildir-160c9121ec39d934330cf626978d02d0fa6d0610.tar.gz qtmaildir-160c9121ec39d934330cf626978d02d0fa6d0610.zip | |
feat(config): read the three signature keys
[compose] signature and signature_position, and a per-account signature
that OVERRIDES the former. The account seeds the choice rather than owning
it: the composer's switch keeps every signature reachable whichever account
is selected, which is what keeps the note's "not tied to an account"
constraint intact.
The fallback is deliberately NOT resolved here. An account with no key of
its own carries an empty string, so the composer can tell "says nothing"
from "says none" and fall through itself.
signature_position follows quote_position's shape exactly, reporting a
present-but-malformed value rather than accepting it silently.
Part of item 152.
Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01KEcn3u19xPqv6ggD15PG4c
Diffstat (limited to 'tests')
| -rw-r--r-- | tests/test_config.cpp | 73 |
1 files changed, 73 insertions, 0 deletions
diff --git a/tests/test_config.cpp b/tests/test_config.cpp index a5dce9a..17b8e1d 100644 --- a/tests/test_config.cpp +++ b/tests/test_config.cpp @@ -25,6 +25,7 @@ #include <QJsonObject> #include "config.h" #include "mailsync.h" +#include "signatures.h" class TestConfig : public QObject { @@ -134,6 +135,9 @@ private slots: void garbageAttachmentWarnBytesIsRejectedNotZero(); void zeroOrNegativeAutosaveIntervalIsClamped(); void unrecognisedQuotePositionWarnsAndFallsBackToBelow(); + void theSignatureKeysAreRead(); + void anAccountSignatureOverridesTheComposeDefault(); + void aMalformedSignaturePositionIsReportedAndFallsBack(); }; static QString writeIni(const QTemporaryDir &dir, const QString &body) @@ -2577,5 +2581,74 @@ void TestConfig::unrecognisedQuotePositionWarnsAndFallsBackToBelow() "an unrecognised quote_position was accepted silently"); } +void TestConfig::theSignatureKeysAreRead() +{ + QTemporaryDir dir; + Config config; + config.load(writeIni(dir, QStringLiteral( + "[compose]\n" + "signature=work\n" + "signature_position=above_quote\n"))); + + QCOMPARE(config.compose().signature, QStringLiteral("work")); + QVERIFY2(config.compose().signaturePosition + == Signatures::Position::AboveQuote, + "signature_position=above_quote was not read"); +} + +void TestConfig::anAccountSignatureOverridesTheComposeDefault() +{ + QTemporaryDir dir; + Config config; + config.load(writeIni(dir, QStringLiteral( + "[compose]\n" + "signature=work\n" + "\n" + "[account.personal]\n" + "name=Test User\n" + "address=user@example.org\n" + "maildir=personal-mail\n" + "trash=Trash\n" + "signature=brief\n" + "\n" + "[account.other]\n" + "name=Test User\n" + "address=other@example.org\n" + "maildir=other-mail\n" + "trash=Trash\n"))); + + // The account SEEDS the choice; it does not own the signature. The key is + // a starting value and the switch keeps every signature reachable. + QCOMPARE(config.account(QStringLiteral("personal")).signature, + QStringLiteral("brief")); + // An account with no key of its own carries none, and the caller falls + // through to the [compose] default rather than this being resolved here. + QVERIFY2(config.account(QStringLiteral("other")).signature.isEmpty(), + "an account with no signature key must not inherit the " + "[compose] one: the composer resolves the fallback, not Config"); + QCOMPARE(config.compose().signature, QStringLiteral("work")); +} + +void TestConfig::aMalformedSignaturePositionIsReportedAndFallsBack() +{ + // Present and malformed is REPORTED, matching quote_position. A silent + // value(key, default) would accept "abov" as above_quote. + QTemporaryDir dir; + Config config; + config.load(writeIni(dir, QStringLiteral( + "[compose]\n" + "signature_position=abov\n"))); + + QVERIFY2(config.compose().signaturePosition == Signatures::Position::End, + "an unrecognised signature_position must still fall back to End"); + bool reported = false; + for (const QString &problem : config.problems()) { + if (problem.contains(QStringLiteral("signature_position"))) + reported = true; + } + QVERIFY2(reported, + "an unrecognised signature_position was accepted silently"); +} + QTEST_MAIN(TestConfig) #include "test_config.moc" |
