Add some unit tests for grouping in KFileItemModel

Hopefully, this will prevent regressions in the future.

REVIEW: 111807
This commit is contained in:
Frank Reininghaus 2013-08-04 21:08:26 +02:00
parent cd642d5d9b
commit c0be1016a1

View file

@ -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<QPair<int, QVariant> > expectedGroups;
expectedGroups << QPair<int, QVariant>(0, QLatin1String("B"));
expectedGroups << QPair<int, QVariant>(1, QLatin1String("C"));
expectedGroups << QPair<int, QVariant>(2, QLatin1String("D"));
expectedGroups << QPair<int, QVariant>(3, QLatin1String("E"));
QCOMPARE(m_model->groups(), expectedGroups);
// Rename d.txt to a.txt.
QHash<QByteArray, QVariant> data;
data.insert("text", "a.txt");
m_model->setData(2, data);
QVERIFY(QTest::kWaitForSignal(m_model, SIGNAL(itemsMoved(KItemRange,QList<int>)), DefaultTimeout));
QCOMPARE(itemsInModel(), QStringList() << "a.txt" << "b.txt" << "c.txt" << "e.txt");
expectedGroups.clear();
expectedGroups << QPair<int, QVariant>(0, QLatin1String("A"));
expectedGroups << QPair<int, QVariant>(1, QLatin1String("B"));
expectedGroups << QPair<int, QVariant>(2, QLatin1String("C"));
expectedGroups << QPair<int, QVariant>(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<int>)), DefaultTimeout));
QCOMPARE(itemsInModel(), QStringList() << "a.txt" << "b.txt" << "d.txt" << "e.txt");
expectedGroups.clear();
expectedGroups << QPair<int, QVariant>(0, QLatin1String("A"));
expectedGroups << QPair<int, QVariant>(1, QLatin1String("B"));
expectedGroups << QPair<int, QVariant>(2, QLatin1String("D"));
expectedGroups << QPair<int, QVariant>(3, QLatin1String("E"));
QCOMPARE(m_model->groups(), expectedGroups);
}
QStringList KFileItemModelTest::itemsInModel() const
{
QStringList items;