aboutsummaryrefslogtreecommitdiffstats
path: root/tests/test_config.cpp
diff options
context:
space:
mode:
authorDanilo M. <danix@danix.xyz>2026-08-13 19:52:13 +0200
committerDanilo M. <danix@danix.xyz>2026-08-13 19:52:13 +0200
commit97c81f8cad571ce9ce724ddab8269e911df05a7c (patch)
tree980f2c801f9723e74c949897de9f8a8a3241d8a3 /tests/test_config.cpp
parent8268bb478dbdf9f23b35c5114c5d13bc98254659 (diff)
downloadqtmaildir-97c81f8cad571ce9ce724ddab8269e911df05a7c.tar.gz
qtmaildir-97c81f8cad571ce9ce724ddab8269e911df05a7c.zip
feat(queries): make Sent a saved query rather than a fixed button
The user asked whether the default queries could be unified with Sent. The answer runs the other way: Sent joins the saved queries rather than the saved queries becoming hardcoded. Inbox, Unread and Important are complete strings that depend on nothing and can never go stale, so generating them would buy nothing and would cost the four things the file just gained: reordering, unpinning, renaming and deleting. Hardcoding them would also make them undeletable, which is a regression for anyone who does not want one of them. Sent is different only in that its query CANNOT be stored: it is composed from every account's `sent` key, so a stored copy goes stale the moment a folder is renamed. That is a property of Sent, not of "default queries". Storing the GENERATOR rather than its output keeps both halves: `"generated": "sent"` still resolves from the accounts at click time, and the entry is an ordinary row that can be reordered, renamed, unpinned or removed. The row now follows one rule instead of carrying one member the user did not own. Two properties had to travel with the entry. The composed query, resolved through Config::resolvedQuery() so what lands in the bar is what actually ran; and FLAT mode, since a sent view lists messages and a threaded one folds every reply back into the conversation the user sent one message into. The sent generator implies flat rather than trusting the file to say so, because a hand-edited row would otherwise produce a threaded sent view. An unknown generator is reported but the row is KEPT: a later build may know it, and dropping it here would delete it from the file on the next save, which is the same data loss the unknown-field handling exists to prevent. A generator whose accounts configure nothing is skipped entirely, exactly as the hardcoded button was hidden rather than offering one that finds nothing. Eight new tests. The four pre-existing Sent tests reach this through migration and were left alone, which is what proves the migrated path still behaves; the new ones cover a STORED file, which is the path every launch after the first takes. Mutations: a generator resolving to nothing fails three, ignoring flat fails two, and not skipping an empty generator fails one. A rename test guards the property the change exists for, since anything keyed on the literal name "Sent" would break it. Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
Diffstat (limited to 'tests/test_config.cpp')
-rw-r--r--tests/test_config.cpp156
1 files changed, 156 insertions, 0 deletions
diff --git a/tests/test_config.cpp b/tests/test_config.cpp
index 8024728..dfe463b 100644
--- a/tests/test_config.cpp
+++ b/tests/test_config.cpp
@@ -62,6 +62,11 @@ private slots:
void futureVersionIsRefusedAndReported();
void startupQueryFallsBackToDocumentOrder();
void scopedSavedQueryParenthesisesADisjunction();
+ void aGeneratedQueryResolvesFromTheAccounts();
+ void aGeneratedQueryTracksAConfigChange();
+ void anUnknownGeneratorResolvesToNothingAndReports();
+ void migrationAddsSentWhenAnAccountHasOne();
+ void migrationAddsNoSentWithoutTheKey();
void generalSectionKeysAreActuallyRead();
void messageZoomDefaultsAndValidates();
void messageZoomOutOfRangeIsReported();
@@ -1416,5 +1421,156 @@ void TestConfig::scopedSavedQueryParenthesisesADisjunction()
QCOMPARE(config.resolvedQuery(orphan), QStringLiteral("tag:inbox"));
}
+// ---------------------------------------------------------------------------
+// Generated saved queries
+// ---------------------------------------------------------------------------
+
+static QString twoAccountsWithSent()
+{
+ return QStringLiteral(
+ "[account.work]\n"
+ "name=Test User\n"
+ "address=user@example.org\n"
+ "maildir=work-mail\n"
+ "sent=Sent\n"
+ "\n"
+ "[account.personal]\n"
+ "name=Test User\n"
+ "address=me@example.net\n"
+ "maildir=personal\n"
+ "sent=[Provider]/Posta inviata\n"
+ );
+}
+
+void TestConfig::aGeneratedQueryResolvesFromTheAccounts()
+{
+ QTemporaryDir dir;
+ const QString path = writeIni(dir, twoAccountsWithSent());
+ writeQueries(dir, QStringLiteral(R"({
+ "version": 1,
+ "queries": [
+ { "name": "Sent", "generated": "sent", "pinned": true }
+ ]
+ })"));
+
+ Config config;
+ config.load(path);
+
+ const SavedQuery sent = config.savedQueries().at(0);
+ QVERIFY(sent.isGenerated());
+ // The stored query is empty; the text comes from the accounts.
+ QVERIFY(sent.query.isEmpty());
+ QCOMPARE(config.resolvedQuery(sent), config.allSentQuery());
+ QVERIFY(config.resolvedQuery(sent).contains(
+ QStringLiteral("path:\"work-mail/Sent/**\"")));
+ // The quotes matter: "[" and "]" are Xapian syntax and an unquoted term
+ // is parsed rather than matched.
+ QVERIFY(config.resolvedQuery(sent).contains(
+ QStringLiteral("path:\"personal/[Provider]/Posta inviata/**\"")));
+
+ // Flat, not threaded: a sent view lists messages, and that property has to
+ // travel with the entry or it is lost the moment Sent is a stored row.
+ QVERIFY(sent.flat);
+}
+
+/// The whole reason Sent is generated rather than stored. A stored copy would
+/// keep naming an account that has been renamed or a folder that has moved.
+void TestConfig::aGeneratedQueryTracksAConfigChange()
+{
+ QTemporaryDir dir;
+ const QString queries = QStringLiteral(R"({
+ "version": 1,
+ "queries": [ { "name": "Sent", "generated": "sent" } ]
+ })");
+
+ const QString before = writeIni(dir, twoAccountsWithSent());
+ writeQueries(dir, queries);
+ Config first;
+ first.load(before);
+ const QString firstResolved = first.resolvedQuery(first.savedQueries().at(0));
+
+ // The user corrects a folder name. Nothing in queries.json changes.
+ QTemporaryDir second;
+ const QString after = writeIni(second, QStringLiteral(
+ "[account.work]\n"
+ "name=Test User\n"
+ "address=user@example.org\n"
+ "maildir=work-mail\n"
+ "sent=Sent Items\n"
+ ));
+ writeQueries(second, queries);
+ Config later;
+ later.load(after);
+ const QString laterResolved = later.resolvedQuery(later.savedQueries().at(0));
+
+ QVERIFY(firstResolved != laterResolved);
+ QVERIFY(laterResolved.contains(QStringLiteral("Sent Items")));
+}
+
+void TestConfig::anUnknownGeneratorResolvesToNothingAndReports()
+{
+ QTemporaryDir dir;
+ const QString path = writeIni(dir, twoAccountsWithSent());
+ writeQueries(dir, QStringLiteral(R"({
+ "version": 1,
+ "queries": [ { "name": "Future", "generated": "not_a_generator" } ]
+ })"));
+
+ Config config;
+ config.load(path);
+
+ // Kept rather than dropped: a later build may know this generator, and
+ // silently deleting the row on save would lose it.
+ QCOMPARE(config.savedQueries().size(), 1);
+ QVERIFY(config.resolvedQuery(config.savedQueries().at(0)).isEmpty());
+ QVERIFY2(!config.problems().isEmpty(),
+ "an unknown generator must be reported, not silently inert");
+}
+
+void TestConfig::migrationAddsSentWhenAnAccountHasOne()
+{
+ QTemporaryDir dir;
+ const QString path = writeIni(dir, twoAccountsWithSent()
+ + QStringLiteral(
+ "\n[queries]\n"
+ "Inbox=tag:inbox\n"
+ ));
+
+ Config config;
+ config.load(path);
+
+ const QList<SavedQuery> queries = config.savedQueries();
+ QCOMPARE(queries.size(), 2);
+ // Last, where the button already sat: after the saved queries.
+ QCOMPARE(queries.at(1).name, QStringLiteral("Sent"));
+ QVERIFY(queries.at(1).isGenerated());
+ QVERIFY(queries.at(1).pinned);
+ QVERIFY(queries.at(1).flat);
+}
+
+/// Today the button is hidden entirely when no account configures a sent
+/// folder, rather than offering one that always finds nothing. The migration
+/// must not invent a row that would do exactly that.
+void TestConfig::migrationAddsNoSentWithoutTheKey()
+{
+ QTemporaryDir dir;
+ const QString path = writeIni(dir, QStringLiteral(
+ "[account.work]\n"
+ "name=Test User\n"
+ "address=user@example.org\n"
+ "maildir=work-mail\n"
+ "\n"
+ "[queries]\n"
+ "Inbox=tag:inbox\n"
+ ));
+
+ Config config;
+ config.load(path);
+
+ const QList<SavedQuery> queries = config.savedQueries();
+ QCOMPARE(queries.size(), 1);
+ QCOMPARE(queries.at(0).name, QStringLiteral("Inbox"));
+}
+
QTEST_MAIN(TestConfig)
#include "test_config.moc"