File indexing completed on 2024-10-27 04:50:48
0001 /* 0002 SPDX-FileCopyrightText: 2014-2024 Laurent Montel <montel@kde.org> 0003 0004 SPDX-License-Identifier: GPL-2.0-or-later 0005 */ 0006 0007 #include "sendlaterconfigtest.h" 0008 #include "sendlaterutil.h" 0009 0010 #include <MessageComposer/SendLaterInfo> 0011 0012 #include <QStandardPaths> 0013 #include <QTest> 0014 0015 SendLaterConfigTest::SendLaterConfigTest(QObject *parent) 0016 : QObject(parent) 0017 { 0018 QStandardPaths::setTestModeEnabled(true); 0019 } 0020 0021 SendLaterConfigTest::~SendLaterConfigTest() = default; 0022 0023 void SendLaterConfigTest::init() 0024 { 0025 mConfig = KSharedConfig::openConfig(QStringLiteral("test-sendlateragent.rc"), KConfig::SimpleConfig); 0026 mSendlaterRegExpFilter = QRegularExpression(QStringLiteral("SendLaterItem \\d+")); 0027 cleanup(); 0028 } 0029 0030 void SendLaterConfigTest::cleanup() 0031 { 0032 const QStringList filterGroups = mConfig->groupList(); 0033 for (const QString &group : filterGroups) { 0034 mConfig->deleteGroup(group); 0035 } 0036 mConfig->sync(); 0037 mConfig->reparseConfiguration(); 0038 } 0039 0040 void SendLaterConfigTest::cleanupTestCase() 0041 { 0042 // Make sure to clean config 0043 cleanup(); 0044 } 0045 0046 void SendLaterConfigTest::shouldConfigBeEmpty() 0047 { 0048 const QStringList filterGroups = mConfig->groupList(); 0049 QCOMPARE(filterGroups.isEmpty(), true); 0050 } 0051 0052 void SendLaterConfigTest::shouldAddAnItem() 0053 { 0054 MessageComposer::SendLaterInfo info; 0055 const QString to = QStringLiteral("kde.org"); 0056 info.setTo(to); 0057 info.setItemId(Akonadi::Item::Id(42)); 0058 info.setSubject(QStringLiteral("Subject")); 0059 info.setRecurrence(true); 0060 info.setRecurrenceEachValue(5); 0061 info.setRecurrenceUnit(MessageComposer::SendLaterInfo::Years); 0062 const QDate date(2014, 1, 1); 0063 info.setDateTime(QDateTime(date.startOfDay())); 0064 info.setLastDateTimeSend(QDateTime(date.startOfDay())); 0065 0066 SendLaterUtil::writeSendLaterInfo(mConfig, &info); 0067 const QStringList itemList = mConfig->groupList().filter(mSendlaterRegExpFilter); 0068 0069 QCOMPARE(itemList.isEmpty(), false); 0070 QCOMPARE(itemList.count(), 1); 0071 } 0072 0073 void SendLaterConfigTest::shouldNotAddInvalidItem() 0074 { 0075 MessageComposer::SendLaterInfo info; 0076 SendLaterUtil::writeSendLaterInfo(mConfig, &info); 0077 const QStringList itemList = mConfig->groupList().filter(mSendlaterRegExpFilter); 0078 0079 QCOMPARE(itemList.isEmpty(), true); 0080 } 0081 0082 QTEST_MAIN(SendLaterConfigTest) 0083 0084 #include "moc_sendlaterconfigtest.cpp"