File indexing completed on 2024-05-19 16:41:36
0001 /* 0002 SPDX-FileCopyrightText: 2021 Alexander Lohnau <alexander.lohnau@gmx.de> 0003 SPDX-License-Identifier: GPL-2.0-only OR GPL-3.0-only OR LicenseRef-KDE-Accepted-GPL 0004 */ 0005 0006 #include <QObject> 0007 #include <QStandardPaths> 0008 #include <QTest> 0009 0010 #include "browsers/firefox.h" 0011 0012 using namespace Plasma; 0013 class TestBookmarksMatch : public QObject 0014 { 0015 Q_OBJECT 0016 public: 0017 using QObject::QObject; 0018 0019 private Q_SLOTS: 0020 void testQueryMatchConversion(); 0021 void testQueryMatchConversion_data(); 0022 void testAddToList(); 0023 }; 0024 0025 void TestBookmarksMatch::testQueryMatchConversion() 0026 { 0027 QFETCH(QString, searchTerm); 0028 QFETCH(QString, bookmarkDescription); 0029 QFETCH(int, expectedMatchType); 0030 QFETCH(qreal, expectedRelevance); 0031 0032 BookmarkMatch bookmarkMatch(QIcon::fromTheme("unknown"), searchTerm, "KDE Community", "https://somehost.com/", bookmarkDescription); 0033 QueryMatch match = bookmarkMatch.asQueryMatch(nullptr); 0034 0035 QCOMPARE(match.text(), "KDE Community"); 0036 QCOMPARE(match.data().toString(), "https://somehost.com/"); 0037 QCOMPARE(match.type(), expectedMatchType); 0038 QCOMPARE(match.relevance(), expectedRelevance); 0039 } 0040 0041 void TestBookmarksMatch::testQueryMatchConversion_data() 0042 { 0043 QTest::addColumn<QString>("searchTerm"); 0044 QTest::addColumn<QString>("bookmarkDescription"); 0045 QTest::addColumn<int>("expectedMatchType"); 0046 QTest::addColumn<qreal>("expectedRelevance"); 0047 0048 auto newRow = [](const char *dataTag, const QString searchTerm, const QString bookmarkDescription, int expectedMatchType, qreal expectedRelevance) { 0049 QTest::newRow(dataTag) << searchTerm << bookmarkDescription << expectedMatchType << expectedRelevance; 0050 }; 0051 0052 newRow("no text match", "krunner", "", (int)QueryMatch::PossibleMatch, 0.18); 0053 newRow("title partly matches", "kde", "", (int)QueryMatch::PossibleMatch, 0.45); 0054 newRow("title exactly matches", "kde community", "", (int)QueryMatch::ExactMatch, 1.0); 0055 newRow("url partly matches", "somehost", "", (int)QueryMatch::PossibleMatch, 0.2); 0056 newRow("url exactly matches", "https://somehost.com/", "", (int)QueryMatch::PossibleMatch, 0.2); 0057 newRow("description exactly matches", "test", "test", (int)QueryMatch::ExactMatch, 1.0); 0058 newRow("description partly matches", "test", "testme", (int)QueryMatch::PossibleMatch, 0.3); 0059 } 0060 0061 void TestBookmarksMatch::testAddToList() 0062 { 0063 BookmarkMatch noMatch(QIcon(), "krunner", "KDE Community", "https://somehost.com/"); 0064 BookmarkMatch match(QIcon(), "kde", "KDE Community", "https://somehost.com/"); 0065 0066 QList<BookmarkMatch> onlyMatching; 0067 noMatch.addTo(onlyMatching, false); 0068 match.addTo(onlyMatching, false); 0069 QCOMPARE(onlyMatching.count(), 1); 0070 0071 QList<BookmarkMatch> allMatches; 0072 noMatch.addTo(allMatches, true); 0073 match.addTo(allMatches, true); 0074 QCOMPARE(allMatches.count(), 2); 0075 } 0076 0077 QTEST_MAIN(TestBookmarksMatch) 0078 0079 #include "bookmarksmatchtest.moc"