File indexing completed on 2025-01-05 04:55:02

0001 #include <QTest>
0002 #include <QDebug>
0003 #include <QStandardItemModel>
0004 #include <sink/test.h>
0005 #include <sink/store.h>
0006 #include <sink/resourcecontrol.h>
0007 
0008 #include "entitymodel.h"
0009 
0010 class EntityModelTest : public QObject
0011 {
0012     Q_OBJECT
0013 private slots:
0014 
0015     void initTestCase()
0016     {
0017         Sink::Test::initTest();
0018     }
0019 
0020     void testModel()
0021     {
0022         Sink::ApplicationDomain::DummyResource::create("account1");
0023 
0024         using namespace Sink::ApplicationDomain;
0025         auto account = ApplicationDomainType::createEntity<SinkAccount>();
0026         Sink::Store::create(account).exec().waitForFinished();
0027 
0028         auto resource = Sink::ApplicationDomain::DummyResource::create(account.identifier());
0029         Sink::Store::create(resource).exec().waitForFinished();
0030 
0031         auto calendar1 = ApplicationDomainType::createEntity<Calendar>(resource.identifier());
0032         calendar1.setName("name1");
0033         Sink::Store::create(calendar1).exec().waitForFinished();
0034 
0035         auto calendar2 = ApplicationDomainType::createEntity<Calendar>(resource.identifier());
0036         calendar2.setName("name2");
0037         Sink::Store::create(calendar2).exec().waitForFinished();
0038 
0039 
0040         Sink::ResourceControl::flushMessageQueue(resource.identifier()).exec().waitForFinished();
0041 
0042         {
0043             EntityModel model;
0044             model.setType("calendar");
0045             model.setRoles({"name"});
0046             model.setAccountId(account.identifier());
0047             QTRY_COMPARE(model.rowCount({}), 2);
0048         }
0049 
0050         {
0051             EntityModel model;
0052             model.setType("calendar");
0053             model.setRoles({"name"});
0054             model.setAccountId(account.identifier());
0055             model.setEntityId(calendar2.identifier());
0056             QTRY_COMPARE(model.rowCount({}), 1);
0057             QCOMPARE(model.data(0).value("name").toString(), QLatin1String{"name2"});
0058         }
0059 
0060         {
0061             EntityLoader model;
0062             model.setType("calendar");
0063             model.setRoles({"name"});
0064             model.setAccountId(account.identifier());
0065             model.setEntityId(calendar2.identifier());
0066             QTRY_COMPARE(model.rowCount({}), 1);
0067             QCOMPARE(model.property("name").toString(), QLatin1String{"name2"});
0068         }
0069     }
0070 };
0071 
0072 QTEST_MAIN(EntityModelTest)
0073 #include "entitymodeltest.moc"