diff --git a/dolphin/src/tests/kfileitemmodeltest.cpp b/dolphin/src/tests/kfileitemmodeltest.cpp index fcc8052695..513ecef5a0 100644 --- a/dolphin/src/tests/kfileitemmodeltest.cpp +++ b/dolphin/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;