diff options
| author | Danilo M. <danix@danix.xyz> | 2026-08-15 11:46:58 +0200 |
|---|---|---|
| committer | Danilo M. <danix@danix.xyz> | 2026-08-15 11:46:58 +0200 |
| commit | d4e4cebbefdce5f575954594461dc707492b2dd8 (patch) | |
| tree | b71ae3b6f66bf661b60dfc565eb9949f5f778f95 /tests/test_config.cpp | |
| parent | aecb22de0c6644380ea3b1e909c864fd24501dc7 (diff) | |
| download | qtmaildir-d4e4cebbefdce5f575954594461dc707492b2dd8.tar.gz qtmaildir-d4e4cebbefdce5f575954594461dc707492b2dd8.zip | |
feat(startup): add startup_account, the account the dropdown opens on
Answers "start me in work - Inbox rather than All accounts - Inbox". The key
names an account by its [account.<key>] suffix and the dropdown is set to it
before the startup query runs; because a built-in filter composes with the
dropdown, that is the whole mechanism and the key never reaches a query
builder. Validated on load: a name matching no account is reported and cleared,
since the dropdown has no entry for it and would sit on All accounts without
saying why.
Which side applies the scope depends on what the startup entry is, and getting
it wrong is silent in both directions. A generated filter comes back from
resolvedQuery() already scoped, so letting runQuery() apply the dropdown again
gives path:"work/**" and (path:"work/**" and (tag:inbox)). A saved query does
not, because resolvedQuery() ignores the account key for one, so claiming it
was already scoped leaves it unscoped with the dropdown pointing at Work.
The first of those shipped in this session's working tree and passed its test,
because the assertion used contains() and the double-scoped string contains the
scope too. It asserts the exact query now. The second was found by writing the
test for the case rather than by reading, and is covered by
aStartupAccountAlsoScopesASavedStartupQuery.
The README's startup_query documentation was wrong on two counts after the
previous commit: the fallback is the Unread filter rather than the first query
in the file, and the name can now match a built-in filter.
Diffstat (limited to 'tests/test_config.cpp')
| -rw-r--r-- | tests/test_config.cpp | 45 |
1 files changed, 45 insertions, 0 deletions
diff --git a/tests/test_config.cpp b/tests/test_config.cpp index 0cacb04..62913d7 100644 --- a/tests/test_config.cpp +++ b/tests/test_config.cpp @@ -96,6 +96,7 @@ private slots: void allSentQuerySkipsAccountsWithoutTheKey(); void allSentQueryJoinsEveryConfiguredAccount(); void aStoredGeneratedQueryIsUnpinnedNotDropped(); + void theStartupAccountIsReadAndValidated(); void theStartupQueryCanNameABuiltinFilter(); void theStartupQueryPrefersASavedQueryOverAFilterOfTheSameName(); void anUnmatchedStartupQueryFallsBackToAFilterNotAStrayQuery(); @@ -1057,6 +1058,50 @@ static QString writeTwoAccounts(const QTemporaryDir &dir) "maildir=personal\n")); } +void TestConfig::theStartupAccountIsReadAndValidated() +{ + QTemporaryDir dir; + Config config; + config.load(writeIni(dir, QStringLiteral( + "[general]\n" + "startup_account=work\n" + "\n" + "[account.work]\n" + "maildir=work\n" + "\n" + "[account.personal]\n" + "maildir=personal\n"))); + + QCOMPARE(config.startupAccount(), QStringLiteral("work")); + QVERIFY(config.problems().isEmpty()); + + // Unset is "All accounts", which is what an empty key means everywhere the + // account is carried, so no separate sentinel. + QTemporaryDir plain; + Config unset; + unset.load(writeIni(plain, QStringLiteral( + "[account.work]\n" + "maildir=work\n"))); + QVERIFY(unset.startupAccount().isEmpty()); + + // A name that matches no account is a problem: the user asked for + // something and is not getting it, exactly as for startup_query. Reported + // and IGNORED rather than passed on, since setting the dropdown to a key + // that is not in it would silently leave it on All accounts anyway. + QTemporaryDir bad; + Config wrong; + wrong.load(writeIni(bad, QStringLiteral( + "[general]\n" + "startup_account=nosuchaccount\n" + "\n" + "[account.work]\n" + "maildir=work\n"))); + QVERIFY2(wrong.startupAccount().isEmpty(), + "an unknown startup account was passed through rather than " + "falling back to All accounts"); + QCOMPARE(wrong.problems().size(), 1); +} + void TestConfig::theStartupQueryCanNameABuiltinFilter() { // The defect: startup_query searched the SAVED queries only. A user whose |
