aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorDanilo M. <danix@danix.xyz>2026-08-14 11:34:33 +0200
committerDanilo M. <danix@danix.xyz>2026-08-14 11:34:33 +0200
commitdda9fd9c918aa169eb01947e02d5b30ec13ee6eb (patch)
tree1f6b31aafb81fd5b8a26a5ed1751822c4c9543ce
parentdfdb452cb5f21a8fe53dcbc610afa9158a83d6cf (diff)
downloadqtmaildir-dda9fd9c918aa169eb01947e02d5b30ec13ee6eb.tar.gz
qtmaildir-dda9fd9c918aa169eb01947e02d5b30ec13ee6eb.zip
test(queries): pin which saved queries offer a tagging rule
Both halves asserted together, plus a guard proving the generated button carries a menu at all: a test for the absence of a menu item passes against no implementation, which item 82 recorded the hard way. The account section is load-bearing rather than scenery. A generated entry resolving to an empty query is skipped entirely, so without a configured maildir and sent folder the Sent button is never built and the assertion would pass by finding nothing. An account section missing maildir hangs the test outright, which is how this was found. Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
-rw-r--r--tests/test_mainwindow.cpp64
1 files changed, 64 insertions, 0 deletions
diff --git a/tests/test_mainwindow.cpp b/tests/test_mainwindow.cpp
index d090016..6e300bf 100644
--- a/tests/test_mainwindow.cpp
+++ b/tests/test_mainwindow.cpp
@@ -204,6 +204,7 @@ private slots:
void aRenamedSentEntryKeepsWorking();
void aGeneratedQueryWithNothingToShowIsSkipped();
void aSavedQueryButtonOffersEditUnpinAndDelete();
+ void onlyAStoredQueryOffersToBecomeATaggingRule();
void unpinningMovesAQueryToTheMenu();
void deletingRemovesTheQueryFromTheFile();
void anEditedQueryKeepsItsUnknownFields();
@@ -5827,6 +5828,69 @@ void TestMainWindow::aSavedQueryButtonOffersEditUnpinAndDelete()
QVERIFY(contextActionNamed(window, button, QStringLiteral("deleteQuery")));
}
+void TestMainWindow::onlyAStoredQueryOffersToBecomeATaggingRule()
+{
+ // A generated entry composes its query from the accounts, so a rule made
+ // from one freezes a snapshot that goes stale when an account is added.
+ //
+ // Both halves are asserted together on purpose: a test that only checks a
+ // menu item is ABSENT passes just as well against a feature that was never
+ // built, which item 82 recorded the hard way.
+ QTemporaryDir dir;
+ QVERIFY(dir.isValid());
+ Config config;
+ // The account is not decoration. A generated entry that resolves to an
+ // empty query is skipped entirely (src/mainwindow.cpp:1692), so without a
+ // configured sent folder the Sent button is never built and the half of
+ // this test that matters would pass by finding nothing.
+ loadWithQueries(config, dir, QStringLiteral(R"({
+ "version": 1,
+ "queries": [
+ { "name": "Inbox", "query": "tag:inbox", "pinned": true },
+ { "name": "Sent", "generated": "sent", "pinned": true }
+ ]
+ })"),
+ QStringLiteral(
+ "[account.work]\n"
+ "name=Test User\n"
+ "address=user@example.org\n"
+ "maildir=work-mail\n"
+ "sent=work-mail/Sent\n"));
+
+ MainWindow window(config);
+ auto *row = window.findChild<QWidget *>(QStringLiteral("savedQueryRow"));
+ QVERIFY(row);
+
+ // By object name, which rebuildSavedQueryRow assigns precisely so a test
+ // need not depend on a label the user can rename.
+ auto *generated = row->findChild<QPushButton *>(
+ QStringLiteral("sentButton"));
+
+ QPushButton *stored = nullptr;
+ const QList<QPushButton *> buttons = row->findChildren<QPushButton *>();
+ for (QPushButton *button : buttons) {
+ if (button->text().contains(QStringLiteral("Inbox"))) {
+ stored = button;
+ break;
+ }
+ }
+
+ QVERIFY2(stored, "no button was built for the stored query");
+ QVERIFY2(generated, "no button was built for the generated query");
+
+ QVERIFY2(contextActionNamed(window, stored, QStringLiteral("queryToRule")),
+ "a stored query must offer Create tagging rule");
+ QVERIFY2(!contextActionNamed(window, generated,
+ QStringLiteral("queryToRule")),
+ "a generated query must not: its query is a snapshot");
+
+ // The guard proving the generated button HAS a menu, so the assertion
+ // above is about this one action and not about a button with no actions.
+ QVERIFY2(contextActionNamed(window, generated,
+ QStringLiteral("deleteQuery")),
+ "the generated button must still carry its other actions");
+}
+
void TestMainWindow::unpinningMovesAQueryToTheMenu()
{
QTemporaryDir dir;