From 5694cf6feadd51a047455ae28a02d25d55f83987 Mon Sep 17 00:00:00 2001 From: "Danilo M." Date: Fri, 14 Aug 2026 11:26:00 +0200 Subject: feat(rules): open the rules dialog on a seeded rule The seed is a whole TagRule rather than a query string, so item 78 can reuse the same path to seed from a sender. It is a pending edit like one made with Add rule: appended, selected, Add tags focused, and written only on Save. Co-Authored-By: Claude Opus 5 --- tests/test_tagrules.cpp | 47 +++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 47 insertions(+) (limited to 'tests/test_tagrules.cpp') diff --git a/tests/test_tagrules.cpp b/tests/test_tagrules.cpp index cc28711..37dcc19 100644 --- a/tests/test_tagrules.cpp +++ b/tests/test_tagrules.cpp @@ -45,6 +45,7 @@ private slots: void aRepairedIdSurvivesASaveAndReload(); void theWarningReadsAsAWarningAndSitsBesideSave(); void aDismissedWarningComesBackWhenThereIsSomethingNewToSay(); + void aSeededDialogOpensOnTheNewRuleWithoutWritingIt(); void aNameTypedWithSpacesIsSanitisedInTheField(); void aRuleAddedAndNamedInTheDialogSurvivesAReopen(); void unknownFieldsSurviveASave(); @@ -924,6 +925,52 @@ void TestTagRules::aRuleAddedAndNamedInTheDialogSurvivesAReopen() QVERIFY(reloaded.warnings().isEmpty()); } +void TestTagRules::aSeededDialogOpensOnTheNewRuleWithoutWritingIt() +{ + // The seeded rule is a pending edit, exactly like one made with Add rule: + // in the working list, selected, and NOT on disk until Save. Asserting the + // file is unchanged is the half that matters, since a dialog that wrote on + // open would tag real mail from a menu click. + QTemporaryDir configHome; + QVERIFY(configHome.isValid()); + qputenv("XDG_CONFIG_HOME", configHome.path().toUtf8()); + QVERIFY(QDir().mkpath(configHome.filePath(QStringLiteral("mailrules")))); + + const QString stored = configHome.filePath( + QStringLiteral("mailrules/rules.json")); + QFile out(stored); + QVERIFY(out.open(QIODevice::WriteOnly)); + out.write(R"({ + "version": 1, + "rules": [ + {"id": "vendor", "query": "from:vendor.example.org", + "add": ["vendor"], "stage": 50, "enabled": true} + ] + })"); + out.close(); + + TagRule seed; + seed.id = QStringLiteral("weekly-digest"); + seed.query = QStringLiteral("from:digest.example.org"); + + TagRulesDialog dialog(seed); + + // Appended after the rules already in the file, and current. + QCOMPARE(dialog.ruleCountForTest(), 2); + QCOMPARE(dialog.nameLineForTest(), QStringLiteral("weekly-digest")); + QCOMPARE(dialog.queryLineForTest(), + QStringLiteral("from:digest.example.org")); + + // Enabled, like a rule made with Add rule. A rule created disabled and + // then forgotten is its own silent failure. + QVERIFY(dialog.currentRuleEnabledForTest()); + + // Nothing written. Reread from disk rather than trusting the dialog. + TagRules onDisk; + onDisk.load(stored); + QCOMPARE(onDisk.rules().size(), 1); +} + void TestTagRules::aFolderRowUsesTheDropdownAndKeepsItsSuffix() { // A path: without its suffix matches nothing and notmuch says nothing -- cgit v1.2.3