aboutsummaryrefslogtreecommitdiffstats
path: root/tests/test_tagdialog.cpp
diff options
context:
space:
mode:
authorDanilo M. <danix@danix.xyz>2026-08-07 10:32:08 +0200
committerDanilo M. <danix@danix.xyz>2026-08-07 10:32:08 +0200
commit6935bfc99ed0df5c79867f7015ba04041e03f908 (patch)
tree38c407c5ce7a5ae55331c89603fa2b6e4776d147 /tests/test_tagdialog.cpp
parentdb4dbbf4bf4fd8aab1a9e20d87c266ce7836a946 (diff)
downloadqtmaildir-6935bfc99ed0df5c79867f7015ba04041e03f908.tar.gz
qtmaildir-6935bfc99ed0df5c79867f7015ba04041e03f908.zip
fix(tags): the Remove field suggests only tags the selection has
Both TagDialog fields built their completer from knownTags, the whole database's tag list, so removing a tag offered every tag in existence rather than the handful the selected threads actually carry. The candidates were already in the dialog: currentTags, used until now only to render the checkbox list. The constructor now walks two (field, vocabulary) pairs instead of two fields sharing one list, with knownTags for Add and currentTags.keys() for Remove. On a multi-thread selection that is the union, not the intersection, since removing a tag two of three threads carry is a meaningful request. The setWidget and per-token prefix machinery is untouched: these fields hold a comma-separated list, and QLineEdit::setCompleter is the trap this dialog already works around. Only the candidate list changed. Completion stays a suggestion, never a whitelist, so a tag absent from the candidates still applies. Tests type keys rather than using setText, which does not drive a completer at all. Verified load-bearing by mutation: reverting the Remove vocabulary to knownTags fails the new test. Closes item 48. Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
Diffstat (limited to 'tests/test_tagdialog.cpp')
-rw-r--r--tests/test_tagdialog.cpp62
1 files changed, 62 insertions, 0 deletions
diff --git a/tests/test_tagdialog.cpp b/tests/test_tagdialog.cpp
index df0fece..5289599 100644
--- a/tests/test_tagdialog.cpp
+++ b/tests/test_tagdialog.cpp
@@ -45,6 +45,8 @@ private slots:
void nothingTouchedYieldsNoChange();
void completionFollowsTheTagAfterAComma();
void acceptingACandidateKeepsTheOtherTags();
+ void removeCompletesOnlyTheSelectionsOwnTags();
+ void removeStillAcceptsATagItDoesNotSuggest();
};
void TestTagDialog::validNamesAreAccepted()
@@ -319,5 +321,65 @@ void TestTagDialog::acceptingACandidateKeepsTheOtherTags()
QVERIFY(addEdit->text().contains(QStringLiteral(", ")));
}
+void TestTagDialog::removeCompletesOnlyTheSelectionsOwnTags()
+{
+ // Reported by the user: removing a tag suggested every tag in the database.
+ // Only the tags the selection already carries can be removed, and those are
+ // already in the dialog as currentTags.
+ //
+ // Typed rather than setText(), which does not drive a completer at all.
+ TagDialog dialog({ QStringLiteral("inbox"), QStringLiteral("unread"),
+ QStringLiteral("flagged"), QStringLiteral("archive") },
+ { { QStringLiteral("inbox"), 1 } }, 1);
+ dialog.show();
+ QVERIFY(QTest::qWaitForWindowExposed(&dialog));
+
+ const QList<QLineEdit *> edits = dialog.findChildren<QLineEdit *>();
+ QVERIFY(edits.size() >= 2);
+ QLineEdit *removeEdit = edits.at(1);
+ removeEdit->setFocus();
+ QTRY_COMPARE(QApplication::focusWidget(), removeEdit);
+
+ QCompleter *completer = removeEdit->findChild<QCompleter *>();
+ QVERIFY(completer);
+
+ // "fl" matches "flagged", which the database has and the selection does not.
+ QTest::keyClicks(removeEdit, QStringLiteral("fl"));
+ QCOMPARE(completer->completionPrefix(), QStringLiteral("fl"));
+ QCOMPARE(completer->completionCount(), 0);
+
+ // A tag the selection does carry still completes.
+ removeEdit->clear();
+ QTest::keyClicks(removeEdit, QStringLiteral("inb"));
+ QCOMPARE(completer->completionPrefix(), QStringLiteral("inb"));
+ QCOMPARE(completer->completionCount(), 1);
+ QCOMPARE(completer->currentCompletion(), QStringLiteral("inbox"));
+
+ // Add is unchanged: it must still reach the whole vocabulary, since
+ // creating a tag is what that field is for.
+ QLineEdit *addEdit = edits.at(0);
+ addEdit->setFocus();
+ QTRY_COMPARE(QApplication::focusWidget(), addEdit);
+ QCompleter *addCompleter = addEdit->findChild<QCompleter *>();
+ QVERIFY(addCompleter);
+ QTest::keyClicks(addEdit, QStringLiteral("fl"));
+ QVERIFY(addCompleter->completionCount() > 0);
+}
+
+void TestTagDialog::removeStillAcceptsATagItDoesNotSuggest()
+{
+ // Completion is a suggestion, never a whitelist. Narrowing the candidates
+ // must not start validating input against them.
+ TagDialog dialog({ QStringLiteral("inbox") },
+ { { QStringLiteral("inbox"), 1 } }, 1);
+
+ const QList<QLineEdit *> edits = dialog.findChildren<QLineEdit *>();
+ QVERIFY(edits.size() >= 2);
+ edits.at(1)->setText(QStringLiteral("flagged"));
+ dialog.accept();
+
+ QVERIFY(dialog.tagsToRemove().contains(QStringLiteral("flagged")));
+}
+
QTEST_MAIN(TestTagDialog)
#include "test_tagdialog.moc"