diff options
| author | Danilo M. <danix@danix.xyz> | 2026-08-14 11:26:00 +0200 |
|---|---|---|
| committer | Danilo M. <danix@danix.xyz> | 2026-08-14 11:26:00 +0200 |
| commit | 5694cf6feadd51a047455ae28a02d25d55f83987 (patch) | |
| tree | d4f58ea4823f19b6f422f3e2065460b2ceba90c1 /tests/test_tagrules.cpp | |
| parent | 7b100de3ccf2b62ba5f00e468e632e32925f1ed3 (diff) | |
| download | qtmaildir-5694cf6feadd51a047455ae28a02d25d55f83987.tar.gz qtmaildir-5694cf6feadd51a047455ae28a02d25d55f83987.zip | |
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 <noreply@anthropic.com>
Diffstat (limited to 'tests/test_tagrules.cpp')
| -rw-r--r-- | tests/test_tagrules.cpp | 47 |
1 files changed, 47 insertions, 0 deletions
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 |
