aboutsummaryrefslogtreecommitdiffstats
path: root/tests/test_messageview.cpp
diff options
context:
space:
mode:
authorDanilo M. <danix@danix.xyz>2026-08-14 12:56:53 +0200
committerDanilo M. <danix@danix.xyz>2026-08-14 12:56:53 +0200
commit8a2e02a3e1a669a738d1de4615720378d5cc2d38 (patch)
treec1dc8fb4cad01987fb192869887e28d7e37fb4f1 /tests/test_messageview.cpp
parentf7f868ce00e01e4026be19437242537967875ce5 (diff)
downloadqtmaildir-8a2e02a3e1a669a738d1de4615720378d5cc2d38.tar.gz
qtmaildir-8a2e02a3e1a669a738d1de4615720378d5cc2d38.zip
feat(search): search for the selected body text
selectedText() reads the selection with no script injection; JavaScript stays disabled in the profile. The page's standard menu is kept and the entries are added to it below a separator. The quoting is tested through a function taking the text, so it needs no live web engine: a selection is arbitrary prose and can carry quotes, newlines and query syntax, none of which notmuch reports as an error.
Diffstat (limited to 'tests/test_messageview.cpp')
-rw-r--r--tests/test_messageview.cpp34
1 files changed, 34 insertions, 0 deletions
diff --git a/tests/test_messageview.cpp b/tests/test_messageview.cpp
index 6403308..f83a377 100644
--- a/tests/test_messageview.cpp
+++ b/tests/test_messageview.cpp
@@ -52,6 +52,7 @@ private slots:
void headerOffersSubjectDateAndSenderForOneMessage();
void headerOffersNoSenderForARealThread();
void headerOffersNothingForAnAbsentField();
+ void bodySelectionBecomesAQuotedSearch();
private:
QWebEngineView *webViewOf(MessageView *view) const
@@ -663,5 +664,38 @@ void TestMessageView::headerOffersNothingForAnAbsentField()
QVERIFY(!query.startsWith(QStringLiteral("cc:")));
}
+void TestMessageView::bodySelectionBecomesAQuotedSearch()
+{
+ // The selection reaches the query as ONE quoted term. Asserted on the
+ // constructed string: a query that lost its quoting is not an error to
+ // notmuch, it simply matches nothing, so nothing downstream would report
+ // this being wrong.
+ //
+ // Takes the text as an argument rather than reading the page, so the
+ // quoting is testable without a live web engine and a rendered document.
+ MessageView view;
+
+ QCOMPARE(view.selectionSearchOffer(QStringLiteral("invoice 4471")).query,
+ QStringLiteral("\"invoice 4471\""));
+
+ // A selection spanning paragraphs arrives full of newlines.
+ QCOMPARE(view.selectionSearchOffer(
+ QStringLiteral("first line\n\nsecond line")).query,
+ QStringLiteral("\"first line second line\""));
+
+ // Query syntax in the selection is data, not syntax: it is quoted, not
+ // interpreted, so a selection reading "a or b" searches for that phrase.
+ QCOMPARE(view.selectionSearchOffer(QStringLiteral("tag:inbox or x")).query,
+ QStringLiteral("\"tag:inbox or x\""));
+
+ // Nothing selected means no entry, rather than an entry searching for "".
+ QVERIFY(view.selectionSearchOffer(QString()).query.isEmpty());
+ QVERIFY(view.selectionSearchOffer(QStringLiteral(" \n ")).query.isEmpty());
+
+ // A usable offer always carries a label for the menu to show.
+ QVERIFY(!view.selectionSearchOffer(QStringLiteral("invoice 4471"))
+ .label.isEmpty());
+}
+
QTEST_MAIN(TestMessageView)
#include "test_messageview.moc"