aboutsummaryrefslogtreecommitdiffstats
path: root/tests/test_tagrules.cpp
diff options
context:
space:
mode:
authorDanilo M. <danix@danix.xyz>2026-08-14 11:27:56 +0200
committerDanilo M. <danix@danix.xyz>2026-08-14 11:27:56 +0200
commit46bdfeb27a072a44ce05affb0ccc3ca9c330197d (patch)
tree5247380549647904e6ce245830566f51516daa72 /tests/test_tagrules.cpp
parent80d78727bf9a73f609e6456fd114951b6daf347b (diff)
downloadqtmaildir-46bdfeb27a072a44ce05affb0ccc3ca9c330197d.tar.gz
qtmaildir-46bdfeb27a072a44ce05affb0ccc3ca9c330197d.zip
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 <noreply@anthropic.com>
Diffstat (limited to 'tests/test_tagrules.cpp')
-rw-r--r--tests/test_tagrules.cpp44
1 files changed, 44 insertions, 0 deletions
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