From 46bdfeb27a072a44ce05affb0ccc3ca9c330197d Mon Sep 17 00:00:00 2001 From: "Danilo M." Date: Fri, 14 Aug 2026 11:27:56 +0200 Subject: feat(rules): seed the rules dialog even when it is open The dialog is non-modal and single-instance, so a second Create tagging rule reaches one that is already up. Seeding it beats dropping the request, which would read as a broken menu item. Co-Authored-By: Claude Opus 5 --- tests/test_tagrules.cpp | 44 ++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 44 insertions(+) (limited to 'tests/test_tagrules.cpp') diff --git a/tests/test_tagrules.cpp b/tests/test_tagrules.cpp index 3954d80..1779245 100644 --- a/tests/test_tagrules.cpp +++ b/tests/test_tagrules.cpp @@ -47,6 +47,7 @@ private slots: void aDismissedWarningComesBackWhenThereIsSomethingNewToSay(); void aSeededDialogOpensOnTheNewRuleWithoutWritingIt(); void aSeededIdThatCollidesDoesNotReplaceTheRuleItMatches(); + void seedingTwiceAddsTwoRulesRatherThanReplacingOne(); void aNameTypedWithSpacesIsSanitisedInTheField(); void aRuleAddedAndNamedInTheDialogSurvivesAReopen(); void unknownFieldsSurviveASave(); @@ -1011,6 +1012,49 @@ void TestTagRules::aSeededIdThatCollidesDoesNotReplaceTheRuleItMatches() QStringLiteral("from:vendor.example.org")); } +void TestTagRules::seedingTwiceAddsTwoRulesRatherThanReplacingOne() +{ + // The dialog is non-modal and single-instance, so a second Create tagging + // rule arrives at a dialog that is already up. It must append, not replace + // the first seed and not be dropped. + 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 first; + first.id = QStringLiteral("first-seed"); + first.query = QStringLiteral("from:one.example.org"); + + TagRulesDialog dialog(first); + QCOMPARE(dialog.ruleCountForTest(), 2); + + TagRule second; + second.id = QStringLiteral("second-seed"); + second.query = QStringLiteral("from:two.example.org"); + dialog.seedRule(second); + + QCOMPARE(dialog.ruleCountForTest(), 3); + QCOMPARE(dialog.nameLineForTest(), QStringLiteral("second-seed")); + + // The first seed survived rather than being overwritten. + dialog.selectRuleForTest(1); + QCOMPARE(dialog.nameLineForTest(), QStringLiteral("first-seed")); +} + void TestTagRules::aFolderRowUsesTheDropdownAndKeepsItsSuffix() { // A path: without its suffix matches nothing and notmuch says nothing -- cgit v1.2.3