diff --git a/src/tests/placesitemmodeltest.cpp b/src/tests/placesitemmodeltest.cpp --- a/src/tests/placesitemmodeltest.cpp +++ b/src/tests/placesitemmodeltest.cpp @@ -26,6 +26,7 @@ #include #include #include +#include #include #include @@ -86,6 +87,7 @@ PlacesItemModel* m_model; QSet m_tobeRemoved; QMap m_interfacesMap; + QList m_userTagsList; int m_expectedModelCount = 15; bool m_hasDesktopFolder = false; bool m_hasDownloadsFolder = false; @@ -100,6 +102,7 @@ void schedulePlaceRemoval(int index); void cancelPlaceRemoval(int index); void removeTestUserData(); + void listUserTags(); QMimeData *createMimeData(const QList &indexes) const; }; @@ -182,6 +185,10 @@ << QStringLiteral("search:/documents") << QStringLiteral("search:/images") << QStringLiteral("search:/audio") << QStringLiteral("search:/videos") << QStringLiteral("/foreign") << QStringLiteral("/media/floppy0") << QStringLiteral("/media/XO-Y4") << QStringLiteral("/media/cdrom"); + + for (const auto &tagUrl : qAsConst(m_userTagsList)) { + urls << tagUrl.toString(); + } } return urls; } @@ -210,6 +217,24 @@ } } +void PlacesItemModelTest::listUserTags() +{ + KCoreDirLister tagLister; + QSignalSpy completedSpy(&tagLister, QOverload<>::of(&KCoreDirLister::completed)); + + connect(&tagLister, &KCoreDirLister::itemsAdded, this, [this](const QUrl &, const KFileItemList &items) { + if (!items.isEmpty()) { + m_userTagsList << QUrl(QStringLiteral("tags:/")); // since it's ignored by KCoreDirLister's listing. + m_userTagsList << items.urlList(); + m_expectedModelCount += m_userTagsList.count(); + } + }); + + QVERIFY(tagLister.openUrl(QUrl(QStringLiteral("tags:/")))); + QVERIFY(completedSpy.wait()); + QCOMPARE(completedSpy.count(), 1); +} + QMimeData *PlacesItemModelTest::createMimeData(const QList &indexes) const { QByteArray itemData; @@ -282,6 +307,8 @@ m_expectedModelCount++; } + listUserTags(); + qRegisterMetaType(); qRegisterMetaType(); } @@ -303,33 +330,39 @@ void PlacesItemModelTest::testGroups() { const auto groups = m_model->groups(); - int expectedGroupSize = 3; + int expectedRemoteIndex = 3; if (m_hasDesktopFolder) { - expectedGroupSize++; + expectedRemoteIndex++; } if (m_hasDownloadsFolder) { - expectedGroupSize++; + expectedRemoteIndex++; } - QCOMPARE(groups.size(), 6); + const int expectedGroupsCount = m_userTagsList.isEmpty() ? 6 : 7; + QCOMPARE(groups.count(), expectedGroupsCount); QCOMPARE(groups.at(0).first, 0); QCOMPARE(groups.at(0).second.toString(), QStringLiteral("Places")); - QCOMPARE(groups.at(1).first, expectedGroupSize); + QCOMPARE(groups.at(1).first, expectedRemoteIndex); QCOMPARE(groups.at(1).second.toString(), QStringLiteral("Remote")); - QCOMPARE(groups.at(2).first, expectedGroupSize + 2); + QCOMPARE(groups.at(2).first, expectedRemoteIndex + 2); QCOMPARE(groups.at(2).second.toString(), QStringLiteral("Recently Saved")); - QCOMPARE(groups.at(3).first, expectedGroupSize + 4); + QCOMPARE(groups.at(3).first, expectedRemoteIndex + 4); QCOMPARE(groups.at(3).second.toString(), QStringLiteral("Search For")); - QCOMPARE(groups.at(4).first, expectedGroupSize + 8); + QCOMPARE(groups.at(4).first, expectedRemoteIndex + 8); QCOMPARE(groups.at(4).second.toString(), QStringLiteral("Devices")); - QCOMPARE(groups.at(5).first, expectedGroupSize + 9); + QCOMPARE(groups.at(5).first, expectedRemoteIndex + 9); QCOMPARE(groups.at(5).second.toString(), QStringLiteral("Removable Devices")); + + if (!m_userTagsList.isEmpty()) { + QCOMPARE(groups.at(6).first, expectedRemoteIndex + 12); + QCOMPARE(groups.at(6).second.toString(), QStringLiteral("Tags")); + } } void PlacesItemModelTest::testPlaceItem_data()