diff --git a/autotests/roomtreemodeltest.cpp b/autotests/roomtreemodeltest.cpp index 28ca5b2ff..df8856358 100644 --- a/autotests/roomtreemodeltest.cpp +++ b/autotests/roomtreemodeltest.cpp @@ -6,6 +6,7 @@ #include "enums/neochatroomtype.h" #include "models/roomtreemodel.h" +#include "models/sortfilterroomtreemodel.h" #include "neochatconnection.h" #include "testutils.h" @@ -30,12 +31,18 @@ void RoomTreeModelTest::testTreeModel() RoomTreeModel model; model.setConnection(connection); + + SortFilterRoomTreeModel filterModel; + filterModel.setSourceModel(&model); + QAbstractItemModelTester tester(&model); + QAbstractItemModelTester testerFilter(&filterModel); QCOMPARE(model.rowCount(), static_cast(NeoChatRoomType::TypesCount)); // Check data category auto category = static_cast(NeoChatRoomType::typeForRoom(room)); + QCOMPARE(category, NeoChatRoomType::Normal); auto normalCategoryIdx = model.index(category, 0); QCOMPARE(model.data(normalCategoryIdx, RoomTreeModel::DisplayNameRole).toString(), QStringLiteral("Normal")); QCOMPARE(model.data(normalCategoryIdx, RoomTreeModel::DelegateTypeRole).toString(), QStringLiteral("section")); @@ -48,7 +55,14 @@ void RoomTreeModelTest::testTreeModel() QCOMPARE(model.data(roomIdx, RoomTreeModel::CurrentRoomRole).value(), room); QCOMPARE(model.data(roomIdx, RoomTreeModel::CategoryRole).toInt(), category); - QVERIFY(false); + // Move room + room->setProperty("isFavorite", true); + model.moveRoom(room); + + auto newCategory = static_cast(NeoChatRoomType::typeForRoom(room)); + QCOMPARE(newCategory, NeoChatRoomType::Favorite); + auto newCategoryIdx = model.index(newCategory, 0); + QVERIFY(newCategoryIdx != normalCategoryIdx); } QTEST_MAIN(RoomTreeModelTest) diff --git a/src/enums/neochatroomtype.h b/src/enums/neochatroomtype.h index f3ddb5ab3..4d926ba26 100644 --- a/src/enums/neochatroomtype.h +++ b/src/enums/neochatroomtype.h @@ -41,7 +41,8 @@ public: if (room->joinState() == Quotient::JoinState::Invite) { return NeoChatRoomType::Invited; } - if (room->isFavourite()) { + // HACK for the unit tests + if (room->isFavourite() || room->property("isFavorite").toBool()) { return NeoChatRoomType::Favorite; } if (room->isLowPriority()) { diff --git a/src/models/roomtreemodel.cpp b/src/models/roomtreemodel.cpp index f048836c4..d629601e9 100644 --- a/src/models/roomtreemodel.cpp +++ b/src/models/roomtreemodel.cpp @@ -44,6 +44,7 @@ bool TreeItem::removeChildren(int position, int count) for (int row = 0; row < count; ++row) { m_childItems.erase(m_childItems.cbegin() + position); + qWarning() << "removing" << position; } return true; @@ -246,6 +247,7 @@ void RoomTreeModel::newRoom(Room *r) categoryItem->appendChild(std::make_unique(room, categoryItem)); connectRoomSignals(room); endInsertRows(); + qWarning() << "adding room" << type << "new count" << categoryItem->childCount(); } void RoomTreeModel::leftRoom(Room *r) @@ -302,8 +304,6 @@ void RoomTreeModel::moveRoom(Quotient::Room *room) auto newParentItem = getItem(newParent); Q_ASSERT(newParentItem); - qWarning() << "Moving" << room << "from" << oldType << "row" << oldRow << "to" << newType << "row" << newParentItem->childCount(); - // HACK: We're doing this as a remove then insert because moving doesn't work // properly with DelegateChooser for whatever reason. diff --git a/src/models/roomtreemodel.h b/src/models/roomtreemodel.h index 24a43db53..b58d8f29f 100644 --- a/src/models/roomtreemodel.h +++ b/src/models/roomtreemodel.h @@ -15,6 +15,7 @@ class Room; class NeoChatConnection; class NeoChatRoom; +class RoomTreeModelTest; class TreeItem { @@ -122,4 +123,6 @@ private: void refreshRoomRoles(NeoChatRoom *room, const QList &roles = {}); std::unique_ptr m_rootItem; + + friend RoomTreeModelTest; }; diff --git a/src/models/sortfilterroomtreemodel.cpp b/src/models/sortfilterroomtreemodel.cpp index c20c729c0..0d371d766 100644 --- a/src/models/sortfilterroomtreemodel.cpp +++ b/src/models/sortfilterroomtreemodel.cpp @@ -127,6 +127,7 @@ bool SortFilterRoomTreeModel::filterAcceptsRow(int source_row, const QModelIndex const QModelIndex index = sourceModel()->index(source_row, 0, source_parent); if (!index.isValid()) { qWarning() << source_row << source_parent << sourceModel()->rowCount(source_parent); + return true; } if (sourceModel()->data(index, RoomTreeModel::IsCategoryRole).toBool()) {