aboutsummaryrefslogtreecommitdiffstats
path: root/tests
diff options
context:
space:
mode:
Diffstat (limited to 'tests')
-rw-r--r--tests/test_config.cpp45
-rw-r--r--tests/test_mainwindow.cpp89
2 files changed, 134 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
diff --git a/tests/test_mainwindow.cpp b/tests/test_mainwindow.cpp
index 949b59e..38a8b08 100644
--- a/tests/test_mainwindow.cpp
+++ b/tests/test_mainwindow.cpp
@@ -169,6 +169,8 @@ private slots:
void narrowingAnEmptyQueryBarIsAPlainSearch();
void aMalformedAccountIsReportedWithoutBlockingTheConstructor();
void aWorkerBackedWindowReturnsRealThreads();
+ void aStartupAccountScopesTheStartupQuery();
+ void aStartupAccountAlsoScopesASavedStartupQuery();
void aGeneratedStartupQueryActuallyRuns();
void everyBuiltinFilterButtonCarriesAnIconAndItsText();
void aQueryInTheMenuCanActuallyBeRun();
@@ -6382,6 +6384,93 @@ void TestMainWindow::aWorkerBackedWindowReturnsRealThreads()
QTRY_VERIFY_WITH_TIMEOUT(model->rowCount(QModelIndex()) == 1, 15000);
}
+void TestMainWindow::aStartupAccountScopesTheStartupQuery()
+{
+ // "Start me in Work - Inbox rather than All accounts - Inbox." The account
+ // dropdown is set before the startup query runs, and because a built-in
+ // filter COMPOSES with the dropdown, the query it runs is scoped to that
+ // account without the filter knowing anything about startup.
+ QTemporaryDir dir;
+ QVERIFY(dir.isValid());
+ const QString path = dir.filePath(QStringLiteral("qtmaildir.conf"));
+ {
+ QSettings s(path, QSettings::IniFormat);
+ // [general] keys are read WITHOUT the prefix, see writeSentConfig.
+ s.setValue(QStringLiteral("startup_query"), QStringLiteral("Inbox"));
+ s.setValue(QStringLiteral("startup_account"), QStringLiteral("work"));
+ s.beginGroup(QStringLiteral("account.work"));
+ s.setValue(QStringLiteral("maildir"), QStringLiteral("work"));
+ s.endGroup();
+ s.beginGroup(QStringLiteral("account.personal"));
+ s.setValue(QStringLiteral("maildir"), QStringLiteral("personal"));
+ s.endGroup();
+ s.sync();
+ }
+ Config config;
+ config.load(path);
+
+ MainWindow window(config);
+
+ QCOMPARE(window.selectedAccountForTesting(), QStringLiteral("work"));
+
+ auto *queryEdit = window.findChild<QLineEdit *>(QStringLiteral("queryEdit"));
+ QVERIFY(queryEdit);
+ QCOMPARE(queryEdit->text(),
+ QStringLiteral("path:\"work/**\" and (tag:inbox)"));
+
+ // And the query that actually RAN carries the scope, not merely the text in
+ // the bar. runQuery() is told the filter is already scoped, so a mistake
+ // here would drop the scope rather than double it, and the bar would still
+ // look right.
+ // The exact string, not contains(): the double-scoped
+ // path:"work/**" and (path:"work/**" and (tag:inbox))
+ // contains the scope too, returns exactly the right rows, and passed a
+ // contains() assertion while being the very thing item 93 exists to avoid.
+ QCOMPARE(window.lastRunQueryForTesting(),
+ QStringLiteral("path:\"work/**\" and (tag:inbox)"));
+}
+
+void TestMainWindow::aStartupAccountAlsoScopesASavedStartupQuery()
+{
+ // The other half, and the one the scoping shortcut can silently drop.
+ // resolvedQuery(query, accountKey) ignores the account key for a SAVED
+ // query, because a saved query states its own scope. So the startup path
+ // gets back an unscoped string, and telling runQuery() the query is
+ // "already scoped" would leave it unscoped for good, with the dropdown
+ // sitting on Work and the list showing everything.
+ QTemporaryDir dir;
+ QVERIFY(dir.isValid());
+ const QString path = dir.filePath(QStringLiteral("qtmaildir.conf"));
+ {
+ QSettings s(path, QSettings::IniFormat);
+ s.setValue(QStringLiteral("startup_query"), QStringLiteral("Mine"));
+ s.setValue(QStringLiteral("startup_account"), QStringLiteral("work"));
+ s.beginGroup(QStringLiteral("account.work"));
+ s.setValue(QStringLiteral("maildir"), QStringLiteral("work"));
+ s.endGroup();
+ s.sync();
+ }
+ QFile queries(dir.filePath(QStringLiteral("queries.json")));
+ QVERIFY(queries.open(QIODevice::WriteOnly | QIODevice::Text));
+ queries.write(QStringLiteral(R"({
+ "version": 1,
+ "queries": [ { "name": "Mine", "query": "tag:todo" } ]
+ })").toUtf8());
+ queries.close();
+
+ Config config;
+ config.load(path);
+
+ MainWindow window(config);
+
+ QCOMPARE(window.selectedAccountForTesting(), QStringLiteral("work"));
+ QVERIFY2(window.lastRunQueryForTesting()
+ == QStringLiteral("path:\"work/**\" and (tag:todo)"),
+ qPrintable(QStringLiteral("the dropdown says Work and the query "
+ "that ran was: ")
+ + window.lastRunQueryForTesting()));
+}
+
void TestMainWindow::aGeneratedStartupQueryActuallyRuns()
{
// The second half of the startup defect. The constructor read