From: Frank Reininghaus Date: Sun, 4 Aug 2013 19:08:26 +0000 (+0200) Subject: Add some unit tests for grouping in KFileItemModel X-Git-Url: https://cloud.milkyroute.net/gitweb/dolphin.git/commitdiff_plain/8bf4aab73e1e8584a06a9c954853369c08f41d8a?hp=-c Add some unit tests for grouping in KFileItemModel Hopefully, this will prevent regressions in the future. REVIEW: 111807 --- 8bf4aab73e1e8584a06a9c954853369c08f41d8a diff --git a/src/tests/kfileitemmodeltest.cpp b/src/tests/kfileitemmodeltest.cpp index fcc805269..513ecef5a 100644 --- a/src/tests/kfileitemmodeltest.cpp +++ b/src/tests/kfileitemmodeltest.cpp @@ -84,6 +84,7 @@ private slots: void collapseParentOfHiddenItems(); void removeParentOfHiddenItems(); void testGeneralParentChildRelationships(); + void testNameRoleGroups(); private: QStringList itemsInModel() const; @@ -1175,6 +1176,53 @@ void KFileItemModelTest::testGeneralParentChildRelationships() QCOMPARE(itemsInModel(), QStringList() << "parent1"); } +void KFileItemModelTest::testNameRoleGroups() +{ + QStringList files; + files << "b.txt" << "c.txt" << "d.txt" << "e.txt"; + + m_testDir->createFiles(files); + + m_model->setGroupedSorting(true); + m_model->loadDirectory(m_testDir->url()); + QVERIFY(QTest::kWaitForSignal(m_model, SIGNAL(itemsInserted(KItemRangeList)), DefaultTimeout)); + QCOMPARE(itemsInModel(), QStringList() << "b.txt" << "c.txt" << "d.txt" << "e.txt"); + + QList > expectedGroups; + expectedGroups << QPair(0, QLatin1String("B")); + expectedGroups << QPair(1, QLatin1String("C")); + expectedGroups << QPair(2, QLatin1String("D")); + expectedGroups << QPair(3, QLatin1String("E")); + QCOMPARE(m_model->groups(), expectedGroups); + + // Rename d.txt to a.txt. + QHash data; + data.insert("text", "a.txt"); + m_model->setData(2, data); + QVERIFY(QTest::kWaitForSignal(m_model, SIGNAL(itemsMoved(KItemRange,QList)), DefaultTimeout)); + QCOMPARE(itemsInModel(), QStringList() << "a.txt" << "b.txt" << "c.txt" << "e.txt"); + + expectedGroups.clear(); + expectedGroups << QPair(0, QLatin1String("A")); + expectedGroups << QPair(1, QLatin1String("B")); + expectedGroups << QPair(2, QLatin1String("C")); + expectedGroups << QPair(3, QLatin1String("E")); + QCOMPARE(m_model->groups(), expectedGroups); + + // Rename c.txt to d.txt. + data.insert("text", "d.txt"); + m_model->setData(2, data); + QVERIFY(QTest::kWaitForSignal(m_model, SIGNAL(itemsMoved(KItemRange,QList)), DefaultTimeout)); + QCOMPARE(itemsInModel(), QStringList() << "a.txt" << "b.txt" << "d.txt" << "e.txt"); + + expectedGroups.clear(); + expectedGroups << QPair(0, QLatin1String("A")); + expectedGroups << QPair(1, QLatin1String("B")); + expectedGroups << QPair(2, QLatin1String("D")); + expectedGroups << QPair(3, QLatin1String("E")); + QCOMPARE(m_model->groups(), expectedGroups); +} + QStringList KFileItemModelTest::itemsInModel() const { QStringList items;