]> cloud.milkyroute.net Git - dolphin.git/commitdiff
Add unit test which checks that DolphinDetailsView::expandedUrls()
authorFrank Reininghaus <frank78ac@googlemail.com>
Wed, 17 Nov 2010 20:59:05 +0000 (20:59 +0000)
committerFrank Reininghaus <frank78ac@googlemail.com>
Wed, 17 Nov 2010 20:59:05 +0000 (20:59 +0000)
works as expected.

svn path=/trunk/KDE/kdebase/apps/; revision=1198202

src/tests/dolphindetailsviewtest.cpp
src/tests/testbase.h
src/views/dolphindetailsview.h

index 20d5daebdb9505a34b979e4d6f11090171cdce6e..0ca19bdddce76b67e42af92973936ec4b40acf87 100644 (file)
@@ -40,11 +40,92 @@ class DolphinDetailsViewTest : public TestBase
 
 private slots:
 
+    void testExpandedUrls();
+
     void bug217447_shiftArrowSelection();
     void bug234600_overlappingIconsWhenZooming();
 
+private:
+
+    QModelIndex proxyModelIndexForUrl(const KUrl& url) const {
+        const QModelIndex index = m_dolphinModel->indexForUrl(url);
+        return m_proxyModel->mapFromSource(index);
+    }
 };
 
+/**
+ * This test verifies that DolphinDetailsView::expandedUrls() returns the right set of URLs.
+ * The test creates a folder hierarchy: 3 folders (a, b, c) contain 3 subfolders (also names a, b, c) each.
+ * Each of those contains 3 further subfolders of the same name.
+ */
+
+void DolphinDetailsViewTest::testExpandedUrls()
+{
+    QStringList files;
+    QStringList subFolderNames;
+    subFolderNames << "a" << "b" << "c";
+
+    foreach(const QString& level1, subFolderNames) {
+        foreach(const QString& level2, subFolderNames) {
+            foreach(const QString& level3, subFolderNames) {
+                files << level1 + "/" + level2 + "/" + level3 + "/testfile";
+            }
+        }
+    }
+
+    createFiles(files);
+
+    m_view->setMode(DolphinView::DetailsView);
+    DolphinDetailsView* detailsView = qobject_cast<DolphinDetailsView*>(itemView());
+    QVERIFY(detailsView);
+    detailsView->setFoldersExpandable(true);
+    m_view->resize(400, 400);
+    m_view->show();
+    QTest::qWaitForWindowShown(m_view);
+    reloadViewAndWait();
+
+    // We start with an empty set of expanded URLs.
+    QSet<KUrl> expectedExpandedUrls;
+    QCOMPARE(detailsView->expandedUrls(), expectedExpandedUrls);
+
+    // Every time we expand a folder, we have to wait until the view has finished loading
+    // its contents before we can expand further subfolders. We keep track of the reloading
+    // using a signal spy.
+    QSignalSpy spyFinishedPathLoading(m_view, SIGNAL(finishedPathLoading(const KUrl&)));
+
+    // Expand URLs one by one and verify the result of DolphinDetailsView::expandedUrls()
+    QStringList itemsToExpand;
+    itemsToExpand << "b" << "b/a" << "b/a/c" << "b/c" << "c";
+
+    foreach(const QString& item, itemsToExpand) {
+        KUrl url(m_path + item);
+        detailsView->expand(proxyModelIndexForUrl(url));
+        expectedExpandedUrls += url;
+        QCOMPARE(detailsView->expandedUrls(), expectedExpandedUrls);
+
+        // Before we proceed, we have to make sure that the view has finished
+        // loading the contents of the expanded folder.
+        while (spyFinishedPathLoading.isEmpty()) {
+            QTest::qWait(10);
+        }
+        spyFinishedPathLoading.takeFirst();
+    }
+
+    // Collapse URLs one by one and verify the result of DolphinDetailsView::expandedUrls()
+    QStringList itemsToCollapse;
+    itemsToCollapse << "b/c" << "b/a/c" << "c" << "b/a" << "b";
+
+    foreach(const QString& item, itemsToCollapse) {
+        KUrl url(m_path + item);
+        detailsView->collapse(proxyModelIndexForUrl(url));
+        expectedExpandedUrls -= url;
+        QCOMPARE(detailsView->expandedUrls(), expectedExpandedUrls);
+    }
+
+    m_view->hide();
+    cleanupTestDir();
+}
+
 /**
  * When the first item in the view is active and Shift is held while the "arrow down"
  * key is pressed repeatedly, the selection should grow by one item for each key press.
index a940a529675831671619bbb4bd2d4ef90d260e9f..d292132911b9a065502e67128cb9e5a3c3761ee5 100644 (file)
@@ -30,7 +30,7 @@ class DolphinModel;
 class DolphinSortFilterProxyModel;
 class DolphinView;
 
-/*
+/**
  * The class TestBase aims to make writing Dolphin unit tests easier.
  * It provides functionality that almost every unit test needs: setup of the DolphinView and
  * easy creation of test files and subfolders in a temporary directory which is removed in
@@ -56,7 +56,7 @@ public:
 
     KUrl testDirUrl() const;
 
-    /*
+    /**
      * The following functions create either a file, a list of files, or a directory.
      * The paths may be absolute or relative to the test directory. Any missing parent
      * directories will be created automatically.
@@ -66,7 +66,7 @@ public:
     void createFiles(const QStringList& files);
     void createDir(const QString& path);
 
-    /*
+    /**
      * Remove the test directory and create an empty one.
      */
 
@@ -79,10 +79,11 @@ public:
     DolphinSortFilterProxyModel* m_proxyModel;
     DolphinView* m_view;
 
+    QString m_path;
+
 private:
 
     KTempDir* m_tempDir;
-    QString m_path;
     QDir* m_dir;
 
     void makePathAbsoluteAndCreateParents(QString& path);
index 479683f66f9ed5b99f7e39fcae025356bddab2dd..fddbdc6c0db7559858c4da093c88d2991798f961 100644 (file)
@@ -211,6 +211,9 @@ private:
 
     QFont m_font;
     QSize m_decorationSize;
+
+    // For unit tests
+    friend class DolphinDetailsViewTest;
 };
 
 #endif