2023-10-28 13:05:18 +00:00
|
|
|
#include <QAbstractItemModelTester>
|
2023-10-24 09:08:30 +00:00
|
|
|
#include <QSignalSpy>
|
|
|
|
#include <QTest>
|
|
|
|
|
|
|
|
#include <memory>
|
|
|
|
|
|
|
|
#include <StatusQ/leftjoinmodel.h>
|
2023-12-21 15:06:52 +00:00
|
|
|
#include <TestHelpers/testmodel.h>
|
2023-10-24 09:08:30 +00:00
|
|
|
|
|
|
|
class TestLeftJoinModel: public QObject
|
|
|
|
{
|
|
|
|
Q_OBJECT
|
|
|
|
|
|
|
|
private slots:
|
|
|
|
|
|
|
|
void emptyModelTest() {
|
|
|
|
LeftJoinModel model;
|
2023-10-28 13:05:18 +00:00
|
|
|
QAbstractItemModelTester tester(&model);
|
2023-10-24 09:08:30 +00:00
|
|
|
|
|
|
|
QCOMPARE(model.rowCount(), 0);
|
|
|
|
QCOMPARE(model.roleNames(), {});
|
|
|
|
}
|
|
|
|
|
|
|
|
void initializationTest()
|
|
|
|
{
|
2023-12-21 15:06:52 +00:00
|
|
|
TestModel leftModel({
|
2023-10-24 09:08:30 +00:00
|
|
|
{ "title", { "Token 1", "Token 2" }},
|
|
|
|
{ "communityId", { "community_1", "community_2" }}
|
|
|
|
});
|
|
|
|
|
2023-12-21 15:06:52 +00:00
|
|
|
TestModel rightModel({
|
2023-10-24 09:08:30 +00:00
|
|
|
{ "name", { "Community 1", "Community 2" }},
|
|
|
|
{ "communityId", { "community_1", "community_2" }}
|
|
|
|
});
|
|
|
|
|
|
|
|
LeftJoinModel model;
|
2023-10-28 13:05:18 +00:00
|
|
|
QAbstractItemModelTester tester(&model);
|
|
|
|
|
2023-10-24 09:08:30 +00:00
|
|
|
model.setLeftModel(&leftModel);
|
|
|
|
|
|
|
|
QCOMPARE(model.rowCount(), 0);
|
|
|
|
QCOMPARE(model.roleNames(), {});
|
|
|
|
|
|
|
|
model.setRightModel(&rightModel);
|
|
|
|
|
|
|
|
QCOMPARE(model.rowCount(), 0);
|
|
|
|
QCOMPARE(model.roleNames(), {});
|
|
|
|
|
|
|
|
model.setJoinRole("communityId");
|
|
|
|
|
|
|
|
QCOMPARE(model.rowCount(), 2);
|
|
|
|
|
|
|
|
QHash<int, QByteArray> roles{{0, "title" }, {1, "communityId"}, {2, "name"}};
|
|
|
|
QCOMPARE(model.roleNames(), roles);
|
|
|
|
}
|
|
|
|
|
2023-10-28 16:42:36 +00:00
|
|
|
void collidingRolesTest()
|
2023-10-24 09:08:30 +00:00
|
|
|
{
|
2023-12-21 15:06:52 +00:00
|
|
|
TestModel leftModel({
|
2023-10-28 16:42:36 +00:00
|
|
|
{ "name", { "Token 1", "Token 2" }},
|
|
|
|
{ "communityId", { "community_1", "community_2" }}
|
|
|
|
});
|
|
|
|
|
2023-12-21 15:06:52 +00:00
|
|
|
TestModel rightModel({
|
2023-10-28 16:42:36 +00:00
|
|
|
{ "name", { "Community 1", "Community 2" }},
|
2023-10-24 09:08:30 +00:00
|
|
|
{ "communityId", { "community_1", "community_2" }}
|
|
|
|
});
|
|
|
|
|
|
|
|
LeftJoinModel model;
|
2023-10-28 13:05:18 +00:00
|
|
|
QAbstractItemModelTester tester(&model);
|
2023-10-24 09:08:30 +00:00
|
|
|
|
2023-10-28 16:42:36 +00:00
|
|
|
model.setLeftModel(&leftModel);
|
|
|
|
|
|
|
|
QCOMPARE(model.rowCount(), 0);
|
|
|
|
QCOMPARE(model.roleNames(), {});
|
|
|
|
|
|
|
|
model.setRightModel(&rightModel);
|
|
|
|
|
|
|
|
QCOMPARE(model.rowCount(), 0);
|
|
|
|
QCOMPARE(model.roleNames(), {});
|
|
|
|
|
2023-10-24 09:08:30 +00:00
|
|
|
QTest::ignoreMessage(QtWarningMsg,
|
2023-10-28 16:42:36 +00:00
|
|
|
"Source models contain conflicting model names: "
|
|
|
|
"(\"name\")!");
|
|
|
|
|
|
|
|
model.setJoinRole("communityId");
|
2023-10-24 09:08:30 +00:00
|
|
|
|
|
|
|
QCOMPARE(model.rowCount(), 0);
|
|
|
|
QCOMPARE(model.roleNames(), {});
|
|
|
|
}
|
|
|
|
|
2023-10-28 16:42:36 +00:00
|
|
|
void duplicatedRolesTest()
|
|
|
|
{
|
|
|
|
{
|
2023-12-21 15:06:52 +00:00
|
|
|
TestModel leftModel({
|
2023-10-28 16:42:36 +00:00
|
|
|
{ "name", { "Token 1", "Token 2" }},
|
|
|
|
{ "name", { "Token 1", "Token 2" }},
|
|
|
|
{ "communityId", { "community_1", "community_2" }}
|
|
|
|
});
|
|
|
|
|
2023-12-21 15:06:52 +00:00
|
|
|
TestModel rightModel({
|
2023-10-28 16:42:36 +00:00
|
|
|
{ "title", { "Community 1", "Community 2" }},
|
|
|
|
{ "communityId", { "community_1", "community_2" }}
|
|
|
|
});
|
|
|
|
|
|
|
|
LeftJoinModel model;
|
|
|
|
QAbstractItemModelTester tester(&model);
|
|
|
|
|
|
|
|
model.setLeftModel(&leftModel);
|
|
|
|
|
|
|
|
QCOMPARE(model.rowCount(), 0);
|
|
|
|
QCOMPARE(model.roleNames(), {});
|
|
|
|
|
|
|
|
model.setRightModel(&rightModel);
|
|
|
|
|
|
|
|
QCOMPARE(model.rowCount(), 0);
|
|
|
|
QCOMPARE(model.roleNames(), {});
|
|
|
|
|
|
|
|
QTest::ignoreMessage(QtWarningMsg,
|
|
|
|
"Each of the source models must have unique "
|
|
|
|
"role names!");
|
|
|
|
|
|
|
|
model.setJoinRole("communityId");
|
|
|
|
|
|
|
|
QCOMPARE(model.rowCount(), 0);
|
|
|
|
QCOMPARE(model.roleNames(), {});
|
|
|
|
}
|
|
|
|
{
|
2023-12-21 15:06:52 +00:00
|
|
|
TestModel leftModel({
|
2023-10-28 16:42:36 +00:00
|
|
|
{ "name", { "Token 1", "Token 2" }},
|
|
|
|
{ "communityId", { "community_1", "community_2" }},
|
|
|
|
{ "communityId", { "community_1", "community_2" }}
|
|
|
|
});
|
|
|
|
|
2023-12-21 15:06:52 +00:00
|
|
|
TestModel rightModel({
|
2023-10-28 16:42:36 +00:00
|
|
|
{ "title", { "Community 1", "Community 2" }},
|
|
|
|
{ "communityId", { "community_1", "community_2" }}
|
|
|
|
});
|
|
|
|
|
|
|
|
LeftJoinModel model;
|
|
|
|
QAbstractItemModelTester tester(&model);
|
|
|
|
|
|
|
|
model.setLeftModel(&leftModel);
|
|
|
|
|
|
|
|
QCOMPARE(model.rowCount(), 0);
|
|
|
|
QCOMPARE(model.roleNames(), {});
|
|
|
|
|
|
|
|
model.setRightModel(&rightModel);
|
|
|
|
|
|
|
|
QCOMPARE(model.rowCount(), 0);
|
|
|
|
QCOMPARE(model.roleNames(), {});
|
|
|
|
|
|
|
|
QTest::ignoreMessage(QtWarningMsg,
|
|
|
|
"Each of the source models must have unique "
|
|
|
|
"role names!");
|
|
|
|
|
|
|
|
model.setJoinRole("communityId");
|
|
|
|
|
|
|
|
QCOMPARE(model.rowCount(), 0);
|
|
|
|
QCOMPARE(model.roleNames(), {});
|
|
|
|
}
|
|
|
|
{
|
2023-12-21 15:06:52 +00:00
|
|
|
TestModel leftModel({
|
2023-10-28 16:42:36 +00:00
|
|
|
{ "name", { "Token 1", "Token 2" }},
|
|
|
|
{ "communityId", { "community_1", "community_2" }}
|
|
|
|
});
|
|
|
|
|
2023-12-21 15:06:52 +00:00
|
|
|
TestModel rightModel({
|
2023-10-28 16:42:36 +00:00
|
|
|
{ "title", { "Community 1", "Community 2" }},
|
|
|
|
{ "title", { "Community 1", "Community 2" }},
|
|
|
|
{ "communityId", { "community_1", "community_2" }}
|
|
|
|
});
|
|
|
|
|
|
|
|
LeftJoinModel model;
|
|
|
|
QAbstractItemModelTester tester(&model);
|
|
|
|
|
|
|
|
model.setLeftModel(&leftModel);
|
|
|
|
|
|
|
|
QCOMPARE(model.rowCount(), 0);
|
|
|
|
QCOMPARE(model.roleNames(), {});
|
|
|
|
|
|
|
|
model.setRightModel(&rightModel);
|
|
|
|
|
|
|
|
QCOMPARE(model.rowCount(), 0);
|
|
|
|
QCOMPARE(model.roleNames(), {});
|
|
|
|
|
|
|
|
QTest::ignoreMessage(QtWarningMsg,
|
|
|
|
"Each of the source models must have unique "
|
|
|
|
"role names!");
|
|
|
|
|
|
|
|
model.setJoinRole("communityId");
|
|
|
|
|
|
|
|
QCOMPARE(model.rowCount(), 0);
|
|
|
|
QCOMPARE(model.roleNames(), {});
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2023-10-24 09:08:30 +00:00
|
|
|
void noJoinRoleTest()
|
|
|
|
{
|
|
|
|
{
|
2023-12-21 15:06:52 +00:00
|
|
|
TestModel leftModel({
|
2023-10-24 09:08:30 +00:00
|
|
|
{ "title", { "Token 1", "Token 2" }},
|
|
|
|
{ "communityId", { "community_1", "community_2" }}
|
|
|
|
});
|
|
|
|
|
2023-12-21 15:06:52 +00:00
|
|
|
TestModel rightModel({
|
2023-10-24 09:08:30 +00:00
|
|
|
{ "name", { "Community 1", "Community 2" }},
|
|
|
|
{ "communityId", { "community_1", "community_2" }}
|
|
|
|
});
|
|
|
|
|
|
|
|
LeftJoinModel model;
|
2023-10-28 13:05:18 +00:00
|
|
|
QAbstractItemModelTester tester(&model);
|
|
|
|
|
2023-10-24 09:08:30 +00:00
|
|
|
model.setLeftModel(&leftModel);
|
|
|
|
|
|
|
|
QCOMPARE(model.rowCount(), 0);
|
|
|
|
QCOMPARE(model.roleNames(), {});
|
|
|
|
|
|
|
|
model.setRightModel(&rightModel);
|
|
|
|
|
|
|
|
QCOMPARE(model.rowCount(), 0);
|
|
|
|
QCOMPARE(model.roleNames(), {});
|
|
|
|
|
|
|
|
QTest::ignoreMessage(QtWarningMsg,
|
|
|
|
"Both left and right models have to contain "
|
|
|
|
"join role someRole!");
|
|
|
|
|
|
|
|
model.setJoinRole("someRole");
|
|
|
|
|
|
|
|
QCOMPARE(model.rowCount(), 0);
|
|
|
|
QCOMPARE(model.roleNames(), {});
|
|
|
|
}
|
|
|
|
{
|
2023-12-21 15:06:52 +00:00
|
|
|
TestModel leftModel({
|
2023-10-24 09:08:30 +00:00
|
|
|
{ "title", { "Token 1", "Token 2" }},
|
|
|
|
{ "communityId", { "community_1", "community_2" }}
|
|
|
|
});
|
|
|
|
|
2023-12-21 15:06:52 +00:00
|
|
|
TestModel rightModel({
|
2023-10-24 09:08:30 +00:00
|
|
|
{ "name", { "Community 1", "Community 2" }},
|
|
|
|
{ "communityId", { "community_1", "community_2" }}
|
|
|
|
});
|
|
|
|
|
|
|
|
LeftJoinModel model;
|
2023-10-28 13:05:18 +00:00
|
|
|
QAbstractItemModelTester tester(&model);
|
|
|
|
|
2023-10-24 09:08:30 +00:00
|
|
|
model.setLeftModel(&leftModel);
|
|
|
|
|
|
|
|
QCOMPARE(model.rowCount(), 0);
|
|
|
|
QCOMPARE(model.roleNames(), {});
|
|
|
|
|
|
|
|
model.setRightModel(&rightModel);
|
|
|
|
|
|
|
|
QCOMPARE(model.rowCount(), 0);
|
|
|
|
QCOMPARE(model.roleNames(), {});
|
|
|
|
|
|
|
|
QTest::ignoreMessage(QtWarningMsg,
|
|
|
|
"Both left and right models have to contain "
|
|
|
|
"join role title!");
|
|
|
|
|
|
|
|
model.setJoinRole("title");
|
|
|
|
|
|
|
|
QCOMPARE(model.rowCount(), 0);
|
|
|
|
QCOMPARE(model.roleNames(), {});
|
|
|
|
}
|
|
|
|
{
|
2023-12-21 15:06:52 +00:00
|
|
|
TestModel leftModel({
|
2023-10-24 09:08:30 +00:00
|
|
|
{ "title", { "Token 1", "Token 2" }},
|
|
|
|
{ "communityId", { "community_1", "community_2" }}
|
|
|
|
});
|
|
|
|
|
2023-12-21 15:06:52 +00:00
|
|
|
TestModel rightModel({
|
2023-10-24 09:08:30 +00:00
|
|
|
{ "name", { "Community 1", "Community 2" }},
|
|
|
|
{ "communityId", { "community_1", "community_2" }}
|
|
|
|
});
|
|
|
|
|
|
|
|
LeftJoinModel model;
|
2023-10-28 13:05:18 +00:00
|
|
|
QAbstractItemModelTester tester(&model);
|
|
|
|
|
2023-10-24 09:08:30 +00:00
|
|
|
model.setLeftModel(&leftModel);
|
|
|
|
|
|
|
|
QCOMPARE(model.rowCount(), 0);
|
|
|
|
QCOMPARE(model.roleNames(), {});
|
|
|
|
|
|
|
|
model.setRightModel(&rightModel);
|
|
|
|
|
|
|
|
QCOMPARE(model.rowCount(), 0);
|
|
|
|
QCOMPARE(model.roleNames(), {});
|
|
|
|
|
|
|
|
QTest::ignoreMessage(QtWarningMsg,
|
|
|
|
"Both left and right models have to contain "
|
|
|
|
"join role name!");
|
|
|
|
|
|
|
|
model.setJoinRole("name");
|
|
|
|
|
|
|
|
QCOMPARE(model.rowCount(), 0);
|
|
|
|
QCOMPARE(model.roleNames(), {});
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void basicAccesTest()
|
|
|
|
{
|
2023-12-21 15:06:52 +00:00
|
|
|
TestModel leftModel({
|
2023-10-24 09:08:30 +00:00
|
|
|
{ "title", { "Token 1", "Token 2" }},
|
|
|
|
{ "communityId", { "community_1", "community_2" }}
|
|
|
|
});
|
|
|
|
|
2023-12-21 15:06:52 +00:00
|
|
|
TestModel rightModel({
|
2023-10-24 09:08:30 +00:00
|
|
|
{ "name", { "Community 1", "Community 2" }},
|
2023-10-28 16:42:36 +00:00
|
|
|
{ "color", { "red", "blue" }},
|
2023-10-24 09:08:30 +00:00
|
|
|
{ "communityId", { "community_1", "community_2" }}
|
|
|
|
});
|
|
|
|
|
|
|
|
LeftJoinModel model;
|
2023-10-28 13:05:18 +00:00
|
|
|
QAbstractItemModelTester tester(&model);
|
|
|
|
|
2023-10-24 09:08:30 +00:00
|
|
|
model.setLeftModel(&leftModel);
|
|
|
|
model.setRightModel(&rightModel);
|
|
|
|
model.setJoinRole("communityId");
|
|
|
|
|
|
|
|
QCOMPARE(model.rowCount(), 2);
|
|
|
|
QCOMPARE(model.data(model.index(0, 0), 0), QString("Token 1"));
|
|
|
|
QCOMPARE(model.data(model.index(1, 0), 0), QString("Token 2"));
|
|
|
|
QCOMPARE(model.data(model.index(0, 0), 1), QString("community_1"));
|
|
|
|
QCOMPARE(model.data(model.index(1, 0), 1), QString("community_2"));
|
|
|
|
QCOMPARE(model.data(model.index(0, 0), 2), QString("Community 1"));
|
|
|
|
QCOMPARE(model.data(model.index(1, 0), 2), QString("Community 2"));
|
2023-10-28 16:42:36 +00:00
|
|
|
QCOMPARE(model.data(model.index(0, 0), 3), QString("red"));
|
|
|
|
QCOMPARE(model.data(model.index(1, 0), 3), QString("blue"));
|
2023-10-24 09:08:30 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void changesPropagationTest()
|
|
|
|
{
|
2023-12-21 15:06:52 +00:00
|
|
|
TestModel leftModel({
|
2023-10-24 09:08:30 +00:00
|
|
|
{ "title", { "Token 1", "Token 2" }},
|
|
|
|
{ "communityId", { "community_1", "community_2" }}
|
|
|
|
});
|
|
|
|
|
2023-12-21 15:06:52 +00:00
|
|
|
TestModel rightModel({
|
2023-10-24 09:08:30 +00:00
|
|
|
{ "name", { "Community 1", "Community 2" }},
|
|
|
|
{ "communityId", { "community_1", "community_2" }},
|
|
|
|
{ "color", { "red", "green" }}
|
|
|
|
});
|
|
|
|
|
|
|
|
LeftJoinModel model;
|
2023-10-28 13:05:18 +00:00
|
|
|
QAbstractItemModelTester tester(&model);
|
|
|
|
|
2023-10-24 09:08:30 +00:00
|
|
|
model.setLeftModel(&leftModel);
|
|
|
|
model.setRightModel(&rightModel);
|
|
|
|
model.setJoinRole("communityId");
|
|
|
|
|
|
|
|
{
|
|
|
|
QSignalSpy dataChangedSpy(&model, &LeftJoinModel::dataChanged);
|
|
|
|
|
|
|
|
rightModel.update(0, 0, "Community 1 Updated");
|
|
|
|
QCOMPARE(dataChangedSpy.count(), 1);
|
|
|
|
|
|
|
|
QCOMPARE(dataChangedSpy.first().at(0), model.index(0, 0));
|
|
|
|
QCOMPARE(dataChangedSpy.first().at(1), model.index(model.rowCount() - 1, 0));
|
|
|
|
QCOMPARE(dataChangedSpy.first().at(2).value<QVector<int>>(), {2});
|
|
|
|
|
|
|
|
QCOMPARE(model.rowCount(), 2);
|
|
|
|
QCOMPARE(model.data(model.index(0, 0), 0), QString("Token 1"));
|
|
|
|
QCOMPARE(model.data(model.index(1, 0), 0), QString("Token 2"));
|
|
|
|
QCOMPARE(model.data(model.index(0, 0), 1), QString("community_1"));
|
|
|
|
QCOMPARE(model.data(model.index(1, 0), 1), QString("community_2"));
|
|
|
|
QCOMPARE(model.data(model.index(0, 0), 2), QString("Community 1 Updated"));
|
|
|
|
QCOMPARE(model.data(model.index(1, 0), 2), QString("Community 2"));
|
|
|
|
}
|
|
|
|
{
|
|
|
|
QSignalSpy dataChangedSpy(&model, &LeftJoinModel::dataChanged);
|
|
|
|
|
|
|
|
leftModel.update(1, 0, "Token 2 Updated");
|
|
|
|
QCOMPARE(dataChangedSpy.count(), 1);
|
|
|
|
|
|
|
|
QCOMPARE(dataChangedSpy.first().at(0), model.index(1, 0));
|
|
|
|
QCOMPARE(dataChangedSpy.first().at(1), model.index(1, 0));
|
|
|
|
QCOMPARE(dataChangedSpy.first().at(2).value<QVector<int>>(), {0});
|
|
|
|
|
|
|
|
QCOMPARE(model.rowCount(), 2);
|
|
|
|
QCOMPARE(model.data(model.index(0, 0), 0), QString("Token 1"));
|
|
|
|
QCOMPARE(model.data(model.index(1, 0), 0), QString("Token 2 Updated"));
|
|
|
|
QCOMPARE(model.data(model.index(0, 0), 1), QString("community_1"));
|
|
|
|
QCOMPARE(model.data(model.index(1, 0), 1), QString("community_2"));
|
|
|
|
QCOMPARE(model.data(model.index(0, 0), 2), QString("Community 1 Updated"));
|
|
|
|
QCOMPARE(model.data(model.index(1, 0), 2), QString("Community 2"));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2023-12-18 09:53:17 +00:00
|
|
|
// TODO: cover also move and layoutChanged
|
|
|
|
void insertRemovePropagationTest()
|
|
|
|
{
|
2023-12-21 15:06:52 +00:00
|
|
|
TestModel leftModel({
|
2023-12-18 09:53:17 +00:00
|
|
|
{ "title", { "Token 1", "Token 2" }},
|
|
|
|
{ "communityId", { "community_1", "community_2" }}
|
|
|
|
});
|
|
|
|
|
2023-12-21 15:06:52 +00:00
|
|
|
TestModel rightModel({
|
2023-12-18 09:53:17 +00:00
|
|
|
{ "name", { "Community 1", "Community 2" }},
|
|
|
|
{ "communityId", { "community_1", "community_2" }},
|
|
|
|
{ "color", { "red", "green" }}
|
|
|
|
});
|
|
|
|
|
|
|
|
LeftJoinModel model;
|
|
|
|
QAbstractItemModelTester tester(&model);
|
|
|
|
|
|
|
|
model.setLeftModel(&leftModel);
|
|
|
|
model.setRightModel(&rightModel);
|
|
|
|
model.setJoinRole("communityId");
|
|
|
|
|
|
|
|
QSignalSpy rowsInsertedSpy(&model, &LeftJoinModel::rowsInserted);
|
|
|
|
QSignalSpy rowsRemovedSpy(&model, &LeftJoinModel::rowsRemoved);
|
|
|
|
|
|
|
|
leftModel.insert(1, {"Token 1_1", "community_2"});
|
|
|
|
|
|
|
|
QCOMPARE(model.rowCount(), 3);
|
|
|
|
QCOMPARE(model.data(model.index(0, 0), 0), QString("Token 1"));
|
|
|
|
QCOMPARE(model.data(model.index(1, 0), 0), QString("Token 1_1"));
|
|
|
|
QCOMPARE(model.data(model.index(2, 0), 0), QString("Token 2"));
|
|
|
|
QCOMPARE(model.data(model.index(0, 0), 1), QString("community_1"));
|
|
|
|
QCOMPARE(model.data(model.index(1, 0), 1), QString("community_2"));
|
|
|
|
QCOMPARE(model.data(model.index(2, 0), 1), QString("community_2"));
|
|
|
|
QCOMPARE(model.data(model.index(0, 0), 2), QString("Community 1"));
|
|
|
|
QCOMPARE(model.data(model.index(1, 0), 2), QString("Community 2"));
|
|
|
|
QCOMPARE(model.data(model.index(2, 0), 2), QString("Community 2"));
|
|
|
|
|
|
|
|
leftModel.remove(1);
|
|
|
|
|
|
|
|
QCOMPARE(model.rowCount(), 2);
|
|
|
|
QCOMPARE(model.data(model.index(0, 0), 0), QString("Token 1"));
|
|
|
|
QCOMPARE(model.data(model.index(1, 0), 0), QString("Token 2"));
|
|
|
|
QCOMPARE(model.data(model.index(0, 0), 1), QString("community_1"));
|
|
|
|
QCOMPARE(model.data(model.index(1, 0), 1), QString("community_2"));
|
|
|
|
QCOMPARE(model.data(model.index(0, 0), 2), QString("Community 1"));
|
|
|
|
QCOMPARE(model.data(model.index(1, 0), 2), QString("Community 2"));
|
|
|
|
|
|
|
|
QCOMPARE(rowsInsertedSpy.count(), 1);
|
|
|
|
QCOMPARE(rowsInsertedSpy.first().at(0), QModelIndex{});
|
|
|
|
QCOMPARE(rowsInsertedSpy.first().at(1), 1);
|
|
|
|
QCOMPARE(rowsInsertedSpy.first().at(2), 1);
|
|
|
|
|
|
|
|
QCOMPARE(rowsRemovedSpy.count(), 1);
|
|
|
|
QCOMPARE(rowsRemovedSpy.first().at(0), QModelIndex{});
|
|
|
|
QCOMPARE(rowsRemovedSpy.first().at(1), 1);
|
|
|
|
QCOMPARE(rowsRemovedSpy.first().at(2), 1);
|
|
|
|
}
|
|
|
|
|
2023-10-24 09:08:30 +00:00
|
|
|
void rightModelJoinRoleChangesPropagationTest()
|
|
|
|
{
|
2023-12-21 15:06:52 +00:00
|
|
|
TestModel leftModel({
|
2023-10-24 09:08:30 +00:00
|
|
|
{ "title", { "Token 1", "Token 2" }},
|
|
|
|
{ "communityId", { "community_1", "community_2" }}
|
|
|
|
});
|
|
|
|
|
2023-12-21 15:06:52 +00:00
|
|
|
TestModel rightModel({
|
2023-10-24 09:08:30 +00:00
|
|
|
{ "name", { "Community 1", "Community 2" }},
|
|
|
|
{ "communityId", { "community_1", "community_2" }}
|
|
|
|
});
|
|
|
|
|
|
|
|
LeftJoinModel model;
|
2023-10-28 13:05:18 +00:00
|
|
|
QAbstractItemModelTester tester(&model);
|
|
|
|
|
2023-10-24 09:08:30 +00:00
|
|
|
model.setLeftModel(&leftModel);
|
|
|
|
model.setRightModel(&rightModel);
|
|
|
|
model.setJoinRole("communityId");
|
|
|
|
|
|
|
|
QSignalSpy dataChangedSpy(&model, &LeftJoinModel::dataChanged);
|
|
|
|
|
|
|
|
rightModel.update(1, 1, "community_3");
|
|
|
|
QCOMPARE(dataChangedSpy.count(), 1);
|
|
|
|
|
|
|
|
QCOMPARE(dataChangedSpy.first().at(0), model.index(0, 0));
|
|
|
|
QCOMPARE(dataChangedSpy.first().at(1), model.index(model.rowCount() - 1, 0));
|
|
|
|
QCOMPARE(dataChangedSpy.first().at(2).value<QVector<int>>(), {2});
|
|
|
|
|
|
|
|
QCOMPARE(model.rowCount(), 2);
|
|
|
|
QCOMPARE(model.data(model.index(0, 0), 0), QString("Token 1"));
|
|
|
|
QCOMPARE(model.data(model.index(1, 0), 0), QString("Token 2"));
|
|
|
|
QCOMPARE(model.data(model.index(0, 0), 1), QString("community_1"));
|
|
|
|
QCOMPARE(model.data(model.index(1, 0), 1), QString("community_2"));
|
|
|
|
QCOMPARE(model.data(model.index(0, 0), 2), QString("Community 1"));
|
|
|
|
QCOMPARE(model.data(model.index(1, 0), 2), {});
|
|
|
|
}
|
|
|
|
|
|
|
|
void rightModelRemovalPropagationTest()
|
|
|
|
{
|
2023-12-21 15:06:52 +00:00
|
|
|
TestModel leftModel({
|
2023-10-24 09:08:30 +00:00
|
|
|
{ "title", { "Token 1", "Token 2" }},
|
|
|
|
{ "communityId", { "community_1", "community_2" }}
|
|
|
|
});
|
|
|
|
|
2023-12-21 15:06:52 +00:00
|
|
|
TestModel rightModel({
|
2023-10-24 09:08:30 +00:00
|
|
|
{ "name", { "Community 1", "Community 2" }},
|
|
|
|
{ "communityId", { "community_1", "community_2" }}
|
|
|
|
});
|
|
|
|
|
|
|
|
LeftJoinModel model;
|
2023-10-28 13:05:18 +00:00
|
|
|
QAbstractItemModelTester tester(&model);
|
|
|
|
|
2023-10-24 09:08:30 +00:00
|
|
|
model.setLeftModel(&leftModel);
|
|
|
|
model.setRightModel(&rightModel);
|
|
|
|
model.setJoinRole("communityId");
|
|
|
|
|
|
|
|
QSignalSpy dataChangedSpy(&model, &LeftJoinModel::dataChanged);
|
|
|
|
|
|
|
|
rightModel.remove(1);
|
|
|
|
QCOMPARE(dataChangedSpy.count(), 1);
|
|
|
|
|
|
|
|
QCOMPARE(dataChangedSpy.first().at(0), model.index(0, 0));
|
|
|
|
QCOMPARE(dataChangedSpy.first().at(1), model.index(model.rowCount() - 1, 0));
|
|
|
|
QCOMPARE(dataChangedSpy.first().at(2).value<QVector<int>>(), {2});
|
|
|
|
|
|
|
|
QCOMPARE(model.rowCount(), 2);
|
|
|
|
QCOMPARE(model.data(model.index(0, 0), 0), QString("Token 1"));
|
|
|
|
QCOMPARE(model.data(model.index(1, 0), 0), QString("Token 2"));
|
|
|
|
QCOMPARE(model.data(model.index(0, 0), 1), QString("community_1"));
|
|
|
|
QCOMPARE(model.data(model.index(1, 0), 1), QString("community_2"));
|
|
|
|
QCOMPARE(model.data(model.index(0, 0), 2), QString("Community 1"));
|
|
|
|
QCOMPARE(model.data(model.index(1, 0), 2), {});
|
|
|
|
}
|
|
|
|
|
|
|
|
void rightModelAdditionPropagationTest()
|
|
|
|
{
|
2023-12-21 15:06:52 +00:00
|
|
|
TestModel leftModel({
|
2023-10-24 09:08:30 +00:00
|
|
|
{ "title", { "Token 1", "Token 2", "Token 3"}},
|
|
|
|
{ "communityId", { "community_1", "community_2", "community_3" }}
|
|
|
|
});
|
|
|
|
|
2023-12-21 15:06:52 +00:00
|
|
|
TestModel rightModel({
|
2023-10-24 09:08:30 +00:00
|
|
|
{ "name", { "Community 1", "Community 2" }},
|
|
|
|
{ "communityId", { "community_1", "community_2" }}
|
|
|
|
});
|
|
|
|
|
|
|
|
LeftJoinModel model;
|
2023-10-28 13:05:18 +00:00
|
|
|
QAbstractItemModelTester tester(&model);
|
|
|
|
|
2023-10-24 09:08:30 +00:00
|
|
|
model.setLeftModel(&leftModel);
|
|
|
|
model.setRightModel(&rightModel);
|
|
|
|
model.setJoinRole("communityId");
|
|
|
|
|
|
|
|
QSignalSpy dataChangedSpy(&model, &LeftJoinModel::dataChanged);
|
|
|
|
|
|
|
|
rightModel.insert(2, {"Community 3", "community_3"});
|
|
|
|
QCOMPARE(dataChangedSpy.count(), 1);
|
|
|
|
|
|
|
|
QCOMPARE(dataChangedSpy.first().at(0), model.index(0, 0));
|
|
|
|
QCOMPARE(dataChangedSpy.first().at(1), model.index(model.rowCount() - 1, 0));
|
|
|
|
QCOMPARE(dataChangedSpy.first().at(2).value<QVector<int>>(), {2});
|
|
|
|
|
|
|
|
QCOMPARE(model.rowCount(), 3);
|
|
|
|
QCOMPARE(model.data(model.index(0, 0), 0), QString("Token 1"));
|
|
|
|
QCOMPARE(model.data(model.index(1, 0), 0), QString("Token 2"));
|
|
|
|
QCOMPARE(model.data(model.index(2, 0), 0), QString("Token 3"));
|
|
|
|
QCOMPARE(model.data(model.index(0, 0), 1), QString("community_1"));
|
|
|
|
QCOMPARE(model.data(model.index(1, 0), 1), QString("community_2"));
|
|
|
|
QCOMPARE(model.data(model.index(2, 0), 1), QString("community_3"));
|
|
|
|
QCOMPARE(model.data(model.index(0, 0), 2), QString("Community 1"));
|
|
|
|
QCOMPARE(model.data(model.index(1, 0), 2), QString("Community 2"));
|
|
|
|
QCOMPARE(model.data(model.index(2, 0), 2), QString("Community 3"));
|
|
|
|
}
|
|
|
|
|
|
|
|
void leftModelJoinRoleChangesPropagationTest()
|
|
|
|
{
|
2023-12-21 15:06:52 +00:00
|
|
|
TestModel leftModel({
|
2023-10-24 09:08:30 +00:00
|
|
|
{ "title", { "Token 1", "Token 2", "Token 3"}},
|
|
|
|
{ "communityId", { "community_1", "community_2", "community_1" }}
|
|
|
|
});
|
|
|
|
|
2023-12-21 15:06:52 +00:00
|
|
|
TestModel rightModel({
|
2023-10-24 09:08:30 +00:00
|
|
|
{ "name", { "Community 1", "Community 2" }},
|
|
|
|
{ "communityId", { "community_1", "community_2" }}
|
|
|
|
});
|
|
|
|
|
|
|
|
LeftJoinModel model;
|
2023-10-28 13:05:18 +00:00
|
|
|
QAbstractItemModelTester tester(&model);
|
|
|
|
|
2023-10-24 09:08:30 +00:00
|
|
|
model.setLeftModel(&leftModel);
|
|
|
|
model.setRightModel(&rightModel);
|
|
|
|
model.setJoinRole("communityId");
|
|
|
|
|
|
|
|
QSignalSpy dataChangedSpy(&model, &LeftJoinModel::dataChanged);
|
|
|
|
|
|
|
|
leftModel.update(1, 1, "community_1");
|
2023-12-18 09:53:17 +00:00
|
|
|
QCOMPARE(dataChangedSpy.count(), 1);
|
2023-10-24 09:08:30 +00:00
|
|
|
|
|
|
|
QCOMPARE(dataChangedSpy.first().at(0), model.index(1, 0));
|
|
|
|
QCOMPARE(dataChangedSpy.first().at(1), model.index(1, 0));
|
|
|
|
|
2023-12-18 09:53:17 +00:00
|
|
|
auto changedRoles = dataChangedSpy.first().at(2).value<QVector<int>>();
|
|
|
|
QVERIFY(changedRoles.contains(1));
|
|
|
|
QVERIFY(changedRoles.contains(2));
|
2023-10-24 09:08:30 +00:00
|
|
|
|
|
|
|
QCOMPARE(model.rowCount(), 3);
|
|
|
|
QCOMPARE(model.data(model.index(0, 0), 0), QString("Token 1"));
|
|
|
|
QCOMPARE(model.data(model.index(1, 0), 0), QString("Token 2"));
|
|
|
|
QCOMPARE(model.data(model.index(2, 0), 0), QString("Token 3"));
|
|
|
|
QCOMPARE(model.data(model.index(0, 0), 1), QString("community_1"));
|
|
|
|
QCOMPARE(model.data(model.index(1, 0), 1), QString("community_1"));
|
|
|
|
QCOMPARE(model.data(model.index(2, 0), 1), QString("community_1"));
|
|
|
|
QCOMPARE(model.data(model.index(0, 0), 2), QString("Community 1"));
|
|
|
|
QCOMPARE(model.data(model.index(1, 0), 2), QString("Community 1"));
|
|
|
|
QCOMPARE(model.data(model.index(2, 0), 2), QString("Community 1"));
|
|
|
|
}
|
|
|
|
|
|
|
|
void modelsDeletedBeforeInitializationTest()
|
|
|
|
{
|
2023-12-21 15:06:52 +00:00
|
|
|
auto leftModel = std::make_unique<TestModel>(
|
2023-12-18 09:53:17 +00:00
|
|
|
QList<QPair<QString, QVariantList>>{
|
|
|
|
{ "title", { "Token 1", "Token 2", "Token 3"}},
|
|
|
|
{ "communityId", { "community_1", "community_2", "community_1" }}
|
|
|
|
});
|
2023-10-24 09:08:30 +00:00
|
|
|
|
2023-12-21 15:06:52 +00:00
|
|
|
auto rightModel = std::make_unique<TestModel>(
|
2023-12-18 09:53:17 +00:00
|
|
|
QList<QPair<QString, QVariantList>>{
|
|
|
|
{ "name", { "Community 1", "Community 2" }},
|
|
|
|
{ "communityId", { "community_1", "community_2" }}
|
|
|
|
});
|
2023-10-24 09:08:30 +00:00
|
|
|
|
|
|
|
LeftJoinModel model;
|
2023-10-28 13:05:18 +00:00
|
|
|
QAbstractItemModelTester tester(&model);
|
|
|
|
|
2023-12-18 09:53:17 +00:00
|
|
|
QSignalSpy modelResetSpy(&model, &LeftJoinModel::modelReset);
|
|
|
|
|
2023-10-24 09:08:30 +00:00
|
|
|
model.setLeftModel(leftModel.get());
|
|
|
|
model.setRightModel(rightModel.get());
|
|
|
|
|
|
|
|
leftModel.reset();
|
|
|
|
rightModel.reset();
|
|
|
|
|
|
|
|
model.setJoinRole("communityId");
|
|
|
|
|
|
|
|
QCOMPARE(model.roleNames(), {});
|
|
|
|
QCOMPARE(model.rowCount(), 0);
|
|
|
|
QCOMPARE(model.data(model.index(0, 0), 0), {});
|
|
|
|
QCOMPARE(model.data(model.index(0, 0), 2), {});
|
|
|
|
|
2023-12-21 15:06:52 +00:00
|
|
|
TestModel newLeftModel({
|
2023-10-24 09:08:30 +00:00
|
|
|
{ "title", { "Token 1", "Token 2", "Token 3"}},
|
|
|
|
{ "communityId", { "community_1", "community_2", "community_1" }}
|
|
|
|
});
|
|
|
|
|
2023-12-21 15:06:52 +00:00
|
|
|
TestModel newRightModel({
|
2023-10-24 09:08:30 +00:00
|
|
|
{ "name", { "Community 1", "Community 2" }},
|
|
|
|
{ "communityId", { "community_1", "community_2" }}
|
|
|
|
});
|
|
|
|
|
|
|
|
model.setLeftModel(&newLeftModel);
|
|
|
|
model.setRightModel(&newRightModel);
|
2023-12-18 09:53:17 +00:00
|
|
|
|
|
|
|
QCOMPARE(model.rowCount(), 3);
|
|
|
|
QCOMPARE(model.data(model.index(0, 0), 0), QString("Token 1"));
|
|
|
|
QCOMPARE(model.data(model.index(1, 0), 0), QString("Token 2"));
|
|
|
|
QCOMPARE(model.data(model.index(2, 0), 0), QString("Token 3"));
|
|
|
|
QCOMPARE(model.data(model.index(0, 0), 1), QString("community_1"));
|
|
|
|
QCOMPARE(model.data(model.index(1, 0), 1), QString("community_2"));
|
|
|
|
QCOMPARE(model.data(model.index(2, 0), 1), QString("community_1"));
|
|
|
|
QCOMPARE(model.data(model.index(0, 0), 2), QString("Community 1"));
|
|
|
|
QCOMPARE(model.data(model.index(1, 0), 2), QString("Community 2"));
|
|
|
|
QCOMPARE(model.data(model.index(2, 0), 2), QString("Community 1"));
|
|
|
|
|
|
|
|
QCOMPARE(modelResetSpy.count(), 1);
|
2023-10-24 09:08:30 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void modelsDeletedAfterInitializationTest()
|
|
|
|
{
|
2023-12-21 15:06:52 +00:00
|
|
|
auto leftModel = std::make_unique<TestModel>(
|
2023-10-24 09:08:30 +00:00
|
|
|
QList<QPair<QString, QVariantList>>{
|
|
|
|
{ "title", { "Token 1", "Token 2", "Token 3"}},
|
|
|
|
{ "communityId", { "community_1", "community_2", "community_1" }}
|
|
|
|
});
|
|
|
|
|
2023-12-21 15:06:52 +00:00
|
|
|
auto rightModel = std::make_unique<TestModel>(
|
2023-10-24 09:08:30 +00:00
|
|
|
QList<QPair<QString, QVariantList>>{
|
|
|
|
{ "name", { "Community 1", "Community 2" }},
|
|
|
|
{ "communityId", { "community_1", "community_2" }}
|
|
|
|
});
|
|
|
|
|
|
|
|
LeftJoinModel model;
|
2023-10-28 13:05:18 +00:00
|
|
|
QAbstractItemModelTester tester(&model);
|
|
|
|
|
2023-12-18 09:53:17 +00:00
|
|
|
QSignalSpy modelResetSpy(&model, &LeftJoinModel::modelReset);
|
|
|
|
|
2023-10-24 09:08:30 +00:00
|
|
|
model.setLeftModel(leftModel.get());
|
|
|
|
model.setRightModel(rightModel.get());
|
|
|
|
|
|
|
|
model.setJoinRole("communityId");
|
|
|
|
|
2023-12-18 09:53:17 +00:00
|
|
|
QCOMPARE(modelResetSpy.count(), 1);
|
|
|
|
|
2023-10-24 09:08:30 +00:00
|
|
|
leftModel.reset();
|
|
|
|
rightModel.reset();
|
|
|
|
|
|
|
|
QHash<int, QByteArray> roles{{0, "title" }, {1, "communityId"}, {2, "name"}};
|
|
|
|
QCOMPARE(model.roleNames(), roles);
|
|
|
|
QCOMPARE(model.rowCount(), 0);
|
|
|
|
QCOMPARE(model.data(model.index(0, 0), 0), {});
|
|
|
|
QCOMPARE(model.data(model.index(0, 0), 2), {});
|
|
|
|
|
2023-12-21 15:06:52 +00:00
|
|
|
TestModel newLeftModel({
|
2023-10-24 09:08:30 +00:00
|
|
|
{ "title", { "Token 1", "Token 2", "Token 3"}},
|
|
|
|
{ "communityId", { "community_1", "community_2", "community_1" }}
|
|
|
|
});
|
|
|
|
|
2023-12-21 15:06:52 +00:00
|
|
|
TestModel newRightModel({
|
2023-10-24 09:08:30 +00:00
|
|
|
{ "name", { "Community 1", "Community 2" }},
|
|
|
|
{ "communityId", { "community_1", "community_2" }}
|
|
|
|
});
|
|
|
|
|
|
|
|
model.setLeftModel(&newLeftModel);
|
|
|
|
|
2023-12-18 09:53:17 +00:00
|
|
|
QCOMPARE(modelResetSpy.count(), 2);
|
|
|
|
QCOMPARE(model.rowCount(), 0);
|
|
|
|
|
2023-10-24 09:08:30 +00:00
|
|
|
model.setRightModel(&newRightModel);
|
2023-12-18 09:53:17 +00:00
|
|
|
|
|
|
|
QCOMPARE(model.rowCount(), 3);
|
|
|
|
QCOMPARE(model.data(model.index(0, 0), 0), QString("Token 1"));
|
|
|
|
QCOMPARE(model.data(model.index(1, 0), 0), QString("Token 2"));
|
|
|
|
QCOMPARE(model.data(model.index(2, 0), 0), QString("Token 3"));
|
|
|
|
QCOMPARE(model.data(model.index(0, 0), 1), QString("community_1"));
|
|
|
|
QCOMPARE(model.data(model.index(1, 0), 1), QString("community_2"));
|
|
|
|
QCOMPARE(model.data(model.index(2, 0), 1), QString("community_1"));
|
|
|
|
QCOMPARE(model.data(model.index(0, 0), 2), QString("Community 1"));
|
|
|
|
QCOMPARE(model.data(model.index(1, 0), 2), QString("Community 2"));
|
|
|
|
QCOMPARE(model.data(model.index(2, 0), 2), QString("Community 1"));
|
|
|
|
|
|
|
|
QCOMPARE(modelResetSpy.count(), 3);
|
2023-10-24 09:08:30 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void rightModelDeletedAfterInitializationTest()
|
|
|
|
{
|
2023-12-21 15:06:52 +00:00
|
|
|
auto leftModel = std::make_unique<TestModel>(
|
2023-10-24 09:08:30 +00:00
|
|
|
QList<QPair<QString, QVariantList>>{
|
|
|
|
{ "title", { "Token 1", "Token 2", "Token 3"}},
|
|
|
|
{ "communityId", { "community_1", "community_2", "community_1" }}
|
|
|
|
});
|
|
|
|
|
2023-12-21 15:06:52 +00:00
|
|
|
auto rightModel = std::make_unique<TestModel>(
|
2023-10-24 09:08:30 +00:00
|
|
|
QList<QPair<QString, QVariantList>>{
|
|
|
|
{ "name", { "Community 1", "Community 2" }},
|
|
|
|
{ "communityId", { "community_1", "community_2" }}
|
|
|
|
});
|
|
|
|
|
|
|
|
LeftJoinModel model;
|
2023-10-28 13:05:18 +00:00
|
|
|
QAbstractItemModelTester tester(&model);
|
|
|
|
|
2023-10-24 09:08:30 +00:00
|
|
|
model.setLeftModel(leftModel.get());
|
|
|
|
model.setRightModel(rightModel.get());
|
|
|
|
|
|
|
|
model.setJoinRole("communityId");
|
|
|
|
|
|
|
|
rightModel.reset();
|
|
|
|
|
|
|
|
QHash<int, QByteArray> roles{{0, "title" }, {1, "communityId"}, {2, "name"}};
|
|
|
|
QCOMPARE(model.roleNames(), roles);
|
|
|
|
QCOMPARE(model.rowCount(), 3);
|
|
|
|
QCOMPARE(model.data(model.index(0, 0), 0), "Token 1");
|
|
|
|
QCOMPARE(model.data(model.index(0, 0), 1), "community_1");
|
|
|
|
QCOMPARE(model.data(model.index(0, 0), 2), {});
|
|
|
|
|
2023-12-21 15:06:52 +00:00
|
|
|
TestModel newLeftModel({
|
2023-10-24 09:08:30 +00:00
|
|
|
{ "title", { "Token 1", "Token 2", "Token 3"}},
|
|
|
|
{ "communityId", { "community_1", "community_2", "community_1" }}
|
|
|
|
});
|
|
|
|
|
2023-12-21 15:06:52 +00:00
|
|
|
TestModel newRightModel({
|
2023-10-24 09:08:30 +00:00
|
|
|
{ "name", { "Community 1", "Community 2" }},
|
|
|
|
{ "communityId", { "community_1", "community_2" }}
|
|
|
|
});
|
|
|
|
|
2023-12-18 09:53:17 +00:00
|
|
|
model.setRightModel(&newRightModel);
|
|
|
|
|
|
|
|
QCOMPARE(model.rowCount(), 3);
|
|
|
|
QCOMPARE(model.data(model.index(0, 0), 0), QString("Token 1"));
|
|
|
|
QCOMPARE(model.data(model.index(1, 0), 0), QString("Token 2"));
|
|
|
|
QCOMPARE(model.data(model.index(2, 0), 0), QString("Token 3"));
|
|
|
|
QCOMPARE(model.data(model.index(0, 0), 1), QString("community_1"));
|
|
|
|
QCOMPARE(model.data(model.index(1, 0), 1), QString("community_2"));
|
|
|
|
QCOMPARE(model.data(model.index(2, 0), 1), QString("community_1"));
|
|
|
|
QCOMPARE(model.data(model.index(0, 0), 2), QString("Community 1"));
|
|
|
|
QCOMPARE(model.data(model.index(1, 0), 2), QString("Community 2"));
|
|
|
|
QCOMPARE(model.data(model.index(2, 0), 2), QString("Community 1"));
|
|
|
|
}
|
|
|
|
|
|
|
|
void rightModelChangedWithSameRolesAfterInitializationTest()
|
|
|
|
{
|
2023-12-21 15:06:52 +00:00
|
|
|
TestModel leftModel({
|
2023-12-18 09:53:17 +00:00
|
|
|
{ "title", { "Token 1", "Token 2", "Token 3"}},
|
|
|
|
{ "communityId", { "community_1", "community_2", "community_1" }}
|
|
|
|
});
|
|
|
|
|
2023-12-21 15:06:52 +00:00
|
|
|
TestModel rightModel({
|
2023-12-18 09:53:17 +00:00
|
|
|
{ "name", { "Community 1", "Community 2" }},
|
|
|
|
{ "communityId", { "community_1", "community_2" }}
|
|
|
|
});
|
|
|
|
|
|
|
|
LeftJoinModel model;
|
|
|
|
QAbstractItemModelTester tester(&model);
|
|
|
|
|
|
|
|
model.setLeftModel(&leftModel);
|
|
|
|
model.setRightModel(&rightModel);
|
|
|
|
|
|
|
|
model.setJoinRole("communityId");
|
|
|
|
|
2023-12-21 15:06:52 +00:00
|
|
|
TestModel newRightModel({
|
2023-12-18 09:53:17 +00:00
|
|
|
{ "name", { "Community A", "Community B" }},
|
|
|
|
{ "communityId", { "community_1", "community_2" }}
|
|
|
|
});
|
|
|
|
|
|
|
|
QSignalSpy modelResetSpy(&model, &LeftJoinModel::modelReset);
|
|
|
|
QSignalSpy dataChangedSpy(&model, &LeftJoinModel::dataChanged);
|
|
|
|
|
|
|
|
model.setRightModel(&newRightModel);
|
|
|
|
|
|
|
|
QHash<int, QByteArray> roles{{0, "title" }, {1, "communityId"}, {2, "name"}};
|
|
|
|
QCOMPARE(model.roleNames(), roles);
|
|
|
|
QCOMPARE(model.rowCount(), 3);
|
|
|
|
|
|
|
|
QCOMPARE(model.rowCount(), 3);
|
|
|
|
QCOMPARE(model.data(model.index(0, 0), 0), QString("Token 1"));
|
|
|
|
QCOMPARE(model.data(model.index(1, 0), 0), QString("Token 2"));
|
|
|
|
QCOMPARE(model.data(model.index(2, 0), 0), QString("Token 3"));
|
|
|
|
QCOMPARE(model.data(model.index(0, 0), 1), QString("community_1"));
|
|
|
|
QCOMPARE(model.data(model.index(1, 0), 1), QString("community_2"));
|
|
|
|
QCOMPARE(model.data(model.index(2, 0), 1), QString("community_1"));
|
|
|
|
QCOMPARE(model.data(model.index(0, 0), 2), QString("Community A"));
|
|
|
|
QCOMPARE(model.data(model.index(1, 0), 2), QString("Community B"));
|
|
|
|
QCOMPARE(model.data(model.index(2, 0), 2), QString("Community A"));
|
|
|
|
|
|
|
|
QCOMPARE(modelResetSpy.count(), 0);
|
|
|
|
QCOMPARE(dataChangedSpy.count(), 1);
|
|
|
|
|
|
|
|
QCOMPARE(dataChangedSpy.first().at(0), model.index(0, 0));
|
|
|
|
QCOMPARE(dataChangedSpy.first().at(1), model.index(model.rowCount() - 1, 0));
|
|
|
|
QCOMPARE(dataChangedSpy.first().at(2).value<QVector<int>>(), {2});
|
|
|
|
}
|
|
|
|
|
|
|
|
void rightModelChangedWithDifferentRolesAfterInitializationTest()
|
|
|
|
{
|
2023-12-21 15:06:52 +00:00
|
|
|
TestModel leftModel({
|
2023-12-18 09:53:17 +00:00
|
|
|
{ "title", { "Token 1", "Token 2", "Token 3"}},
|
|
|
|
{ "communityId", { "community_1", "community_2", "community_1" }}
|
|
|
|
});
|
|
|
|
|
2023-12-21 15:06:52 +00:00
|
|
|
TestModel rightModel({
|
2023-12-18 09:53:17 +00:00
|
|
|
{ "name", { "Community 1", "Community 2" }},
|
|
|
|
{ "communityId", { "community_1", "community_2" }}
|
|
|
|
});
|
|
|
|
|
|
|
|
LeftJoinModel model;
|
|
|
|
QAbstractItemModelTester tester(&model);
|
|
|
|
|
|
|
|
model.setLeftModel(&leftModel);
|
|
|
|
model.setRightModel(&rightModel);
|
|
|
|
|
|
|
|
model.setJoinRole("communityId");
|
|
|
|
|
2023-12-21 15:06:52 +00:00
|
|
|
TestModel newRightModel({
|
2023-12-18 09:53:17 +00:00
|
|
|
{ "communityId", { "community_1", "community_2" }},
|
|
|
|
{ "name", { "Community A", "Community B" }}
|
|
|
|
});
|
|
|
|
|
|
|
|
QSignalSpy modelResetSpy(&model, &LeftJoinModel::modelReset);
|
|
|
|
QSignalSpy dataChangedSpy(&model, &LeftJoinModel::dataChanged);
|
2023-10-24 09:08:30 +00:00
|
|
|
|
|
|
|
model.setRightModel(&newRightModel);
|
2023-12-18 09:53:17 +00:00
|
|
|
|
|
|
|
QHash<int, QByteArray> roles{{0, "title" }, {1, "communityId"}, {3, "name"}};
|
|
|
|
QCOMPARE(model.roleNames(), roles);
|
|
|
|
QCOMPARE(model.rowCount(), 3);
|
|
|
|
|
|
|
|
QCOMPARE(model.rowCount(), 3);
|
|
|
|
QCOMPARE(model.data(model.index(0, 0), 0), QString("Token 1"));
|
|
|
|
QCOMPARE(model.data(model.index(1, 0), 0), QString("Token 2"));
|
|
|
|
QCOMPARE(model.data(model.index(2, 0), 0), QString("Token 3"));
|
|
|
|
QCOMPARE(model.data(model.index(0, 0), 1), QString("community_1"));
|
|
|
|
QCOMPARE(model.data(model.index(1, 0), 1), QString("community_2"));
|
|
|
|
QCOMPARE(model.data(model.index(2, 0), 1), QString("community_1"));
|
|
|
|
QCOMPARE(model.data(model.index(0, 0), 3), QString("Community A"));
|
|
|
|
QCOMPARE(model.data(model.index(1, 0), 3), QString("Community B"));
|
|
|
|
QCOMPARE(model.data(model.index(2, 0), 3), QString("Community A"));
|
|
|
|
|
|
|
|
QCOMPARE(modelResetSpy.count(), 1);
|
|
|
|
QCOMPARE(dataChangedSpy.count(), 0);
|
2023-10-24 09:08:30 +00:00
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
QTEST_MAIN(TestLeftJoinModel)
|
|
|
|
#include "tst_LeftJoinModel.moc"
|