]> cloud.milkyroute.net Git - dolphin.git/blobdiff - src/tests/placesitemmodeltest.cpp
Merge branch 'Applications/18.04'
[dolphin.git] / src / tests / placesitemmodeltest.cpp
index ef24292ed42ea2137306397c512cc37058bf9256..fc21ce055f9c0d46c0ae59e4a088f6ab489b6aea 100644 (file)
 
 #include <QTest>
 #include <QSignalSpy>
-#include <QDebug>
-#include <QList>
-#include <QByteArray>
 #include <QStandardPaths>
 #include <QAction>
 #include <QDBusInterface>
-#include <QUrlQuery>
 
 #include <KBookmarkManager>
 #include <KConfig>
@@ -36,7 +32,6 @@
 #include "panels/places/placesitemmodel.h"
 #include "panels/places/placesitem.h"
 #include "views/viewproperties.h"
-#include "kitemviews/kitemrange.h"
 
 Q_DECLARE_METATYPE(KItemRangeList)
 Q_DECLARE_METATYPE(KItemRange)
@@ -83,6 +78,8 @@ private slots:
     void testIcons();
     void testDragAndDrop();
     void testHideDevices();
+    void testDuplicatedEntries();
+    void renameAfterCreation();
 
 private:
     PlacesItemModel* m_model;
@@ -231,7 +228,8 @@ void PlacesItemModelTest::init()
 
 void PlacesItemModelTest::cleanup()
 {
-    for (int i : m_tobeRemoved) {
+    const auto tobeRemoved = m_tobeRemoved;
+    for (const int i : tobeRemoved) {
         int before = m_model->count();
         m_model->deleteItem(i);
         QTRY_COMPARE(m_model->count(), before - 1);
@@ -544,7 +542,6 @@ void PlacesItemModelTest::testSystemItems()
 
 void PlacesItemModelTest::testEditBookmark()
 {
-    const QUrl tempUrl = QUrl::fromLocalFile(QStandardPaths::writableLocation(QStandardPaths::TempLocation));
     QScopedPointer<PlacesItemModel> other(new PlacesItemModel());
 
     createPlaceItem(QStringLiteral("Temporary Dir"), QUrl::fromLocalFile(QStandardPaths::writableLocation(QStandardPaths::TempLocation)), QString());
@@ -780,6 +777,67 @@ void PlacesItemModelTest::testHideDevices()
     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)