File indexing completed on 2025-01-05 04:55:03
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 #include "maillistmodel.h" 0008 #include "mailtemplates.h" 0009 0010 class MaillistModelTest : public QObject 0011 { 0012 Q_OBJECT 0013 private slots: 0014 0015 void initTestCase() 0016 { 0017 Sink::Test::initTest(); 0018 } 0019 0020 void testMailListModel() 0021 { 0022 using namespace Sink::ApplicationDomain; 0023 auto account = ApplicationDomainType::createEntity<SinkAccount>(); 0024 Sink::Store::create(account).exec().waitForFinished(); 0025 0026 auto resource = Sink::ApplicationDomain::DummyResource::create(account.identifier()); 0027 Sink::Store::create(resource).exec().waitForFinished(); 0028 0029 auto folder1 = ApplicationDomainType::createEntity<Folder>(resource.identifier()); 0030 Sink::Store::create(folder1).exec().waitForFinished(); 0031 0032 auto folder2 = ApplicationDomainType::createEntity<Folder>(resource.identifier()); 0033 Sink::Store::create(folder2).exec().waitForFinished(); 0034 0035 0036 auto mail1 = ApplicationDomainType::createEntity<Mail>(resource.identifier()); 0037 mail1.setFolder(folder1); 0038 KMime::Types::Mailbox from; 0039 from.fromUnicodeString("from@example.org"); 0040 auto message = MailTemplates::createMessage({}, {"foo@test.com"}, {}, {}, from, "Subject", "Body", false, {}, {}, {}); 0041 mail1.setMimeMessage(message->encodedContent(true)); 0042 Sink::Store::create(mail1).exec().waitForFinished(); 0043 0044 auto mail2 = ApplicationDomainType::createEntity<Mail>(resource.identifier()); 0045 mail2.setFolder(folder2); 0046 Sink::Store::create(mail2).exec().waitForFinished(); 0047 0048 Sink::ResourceControl::flushMessageQueue(resource.identifier()).exec().waitForFinished(); 0049 0050 { 0051 MailListModel model; 0052 model.setFilter({{"folder", QVariant::fromValue(Folder::Ptr::create(folder1))}}); 0053 QTRY_COMPARE(model.rowCount({}), 1); 0054 0055 { 0056 auto idx = model.index(0, 0, {}); 0057 auto mail = idx.data(MailListModel::DomainObject).value<Mail::Ptr>(); 0058 QVERIFY(mail); 0059 QVERIFY(!mail->getSubject().isEmpty()); 0060 } 0061 } 0062 { 0063 MailListModel model; 0064 model.setFilter({{"mail", QVariant::fromValue(Mail::Ptr::create(mail1))}}); 0065 QTRY_COMPARE(model.rowCount({}), 1); 0066 0067 { 0068 auto idx = model.index(0, 0, {}); 0069 auto mail = idx.data(MailListModel::DomainObject).value<Mail::Ptr>(); 0070 QVERIFY(mail); 0071 QVERIFY(!mail->getSubject().isEmpty()); 0072 QVERIFY(mail->getFullPayloadAvailable()); 0073 } 0074 } 0075 } 0076 }; 0077 0078 QTEST_MAIN(MaillistModelTest) 0079 #include "maillistmodeltest.moc"