More unit tests
This commit is contained in:
@@ -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<int>(NeoChatRoomType::TypesCount));
|
||||
|
||||
// Check data category
|
||||
auto category = static_cast<int>(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<NeoChatRoom *>(), room);
|
||||
QCOMPARE(model.data(roomIdx, RoomTreeModel::CategoryRole).toInt(), category);
|
||||
|
||||
QVERIFY(false);
|
||||
// Move room
|
||||
room->setProperty("isFavorite", true);
|
||||
model.moveRoom(room);
|
||||
|
||||
auto newCategory = static_cast<int>(NeoChatRoomType::typeForRoom(room));
|
||||
QCOMPARE(newCategory, NeoChatRoomType::Favorite);
|
||||
auto newCategoryIdx = model.index(newCategory, 0);
|
||||
QVERIFY(newCategoryIdx != normalCategoryIdx);
|
||||
}
|
||||
|
||||
QTEST_MAIN(RoomTreeModelTest)
|
||||
|
||||
@@ -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()) {
|
||||
|
||||
@@ -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<TreeItem>(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.
|
||||
|
||||
|
||||
@@ -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<int> &roles = {});
|
||||
|
||||
std::unique_ptr<TreeItem> m_rootItem;
|
||||
|
||||
friend RoomTreeModelTest;
|
||||
};
|
||||
|
||||
@@ -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()) {
|
||||
|
||||
Reference in New Issue
Block a user