X-Git-Url: https://cloud.milkyroute.net/gitweb/dolphin.git/blobdiff_plain/da6f8fe0862585287153f0d90e19eab0b34bfbef..87e8d0ba5f:/src/tests/placesitemmodeltest.cpp diff --git a/src/tests/placesitemmodeltest.cpp b/src/tests/placesitemmodeltest.cpp index 7c4cf308b..a74b3ea6c 100644 --- a/src/tests/placesitemmodeltest.cpp +++ b/src/tests/placesitemmodeltest.cpp @@ -82,6 +82,9 @@ private slots: void testIcons_data(); void testIcons(); void testDragAndDrop(); + void testHideDevices(); + void testDuplicatedEntries(); + void renameAfterCreation(); private: PlacesItemModel* m_model; @@ -758,6 +761,90 @@ void PlacesItemModelTest::testDragAndDrop() CHECK_PLACES_URLS(urls); } +void PlacesItemModelTest::testHideDevices() +{ + QSignalSpy itemsRemoved(m_model, &PlacesItemModel::itemsRemoved); + QStringList urls = initialUrls(); + + m_model->setGroupHidden(KFilePlacesModel::RemovableDevicesType, true); + QTRY_VERIFY(m_model->isGroupHidden(KFilePlacesModel::RemovableDevicesType)); + QTRY_COMPARE(itemsRemoved.count(), 3); + + // remove removable-devices + urls.removeOne(QStringLiteral("/media/floppy0")); + urls.removeOne(QStringLiteral("/media/XO-Y4")); + urls.removeOne(QStringLiteral("/media/cdrom")); + + // check if the correct urls was removed + CHECK_PLACES_URLS(urls); + + delete m_model; + m_model = new PlacesItemModel(); + QTRY_COMPARE(m_model->count(), urls.count()); + CHECK_PLACES_URLS(urls); + + // revert changes + m_model->setGroupHidden(KFilePlacesModel::RemovableDevicesType, false); + urls = initialUrls(); + QTRY_COMPARE(m_model->count(), urls.count()); + CHECK_PLACES_URLS(urls); +} + +void PlacesItemModelTest::testDuplicatedEntries() +{ + QStringList urls = initialUrls(); + // create a duplicated entry on bookmark + KBookmarkManager *bookmarkManager = KBookmarkManager::managerForFile(bookmarksFile(), QStringLiteral("kfilePlaces")); + KBookmarkGroup root = bookmarkManager->root(); + KBookmark bookmark = root.addBookmark(QStringLiteral("Duplicated Search Videos"), QUrl("search:/videos"), {}); + + const QString id = QUuid::createUuid().toString(); + bookmark.setMetaDataItem(QStringLiteral("ID"), id); + bookmark.setMetaDataItem(QStringLiteral("OnlyInApp"), KAboutData::applicationData().componentName()); + bookmarkManager->emitChanged(bookmarkManager->root()); + + PlacesItemModel *newModel = new PlacesItemModel(); + QTRY_COMPARE(placesUrls(newModel).count(QStringLiteral("search:/videos")), 1); + QTRY_COMPARE(urls, placesUrls(newModel)); + delete newModel; +} + +void PlacesItemModelTest::renameAfterCreation() +{ + const QUrl tempUrl = QUrl::fromLocalFile(QStandardPaths::writableLocation(QStandardPaths::TempLocation)); + QStringList urls = initialUrls(); + PlacesItemModel *model = new PlacesItemModel(); + + CHECK_PLACES_URLS(urls); + QTRY_COMPARE(model->count(), m_model->count()); + + // create a new place + createPlaceItem(QStringLiteral("Temporary Dir"), tempUrl, QString()); + urls.insert(3, tempUrl.toLocalFile()); + + // make sure that the new item will be removed later + removePlaceAfter(3); + + CHECK_PLACES_URLS(urls); + QCOMPARE(model->count(), m_model->count()); + + + // modify place text + QSignalSpy changedSpy(m_model, &PlacesItemModel::itemsChanged); + + PlacesItem *item = m_model->placesItem(3); + item->setText(QStringLiteral("New Temporary Dir")); + item->setUrl(item->url()); + item->setIcon(item->icon()); + m_model->refresh(); + + QTRY_COMPARE(changedSpy.count(), 1); + + // check if the place was modified in both models + QTRY_COMPARE(m_model->placesItem(3)->text(), QStringLiteral("New Temporary Dir")); + QTRY_COMPARE(model->placesItem(3)->text(), QStringLiteral("New Temporary Dir")); +} + QTEST_MAIN(PlacesItemModelTest) #include "placesitemmodeltest.moc"