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 "sendlaterutiltest.h"
0008 #include "sendlaterutil.h"
0009 
0010 #include <MessageComposer/SendLaterInfo>
0011 
0012 #include <KConfigGroup>
0013 #include <KSharedConfig>
0014 #include <QDateTime>
0015 #include <QStandardPaths>
0016 #include <QTest>
0017 
0018 SendLaterUtilTest::SendLaterUtilTest(QObject *parent)
0019     : QObject(parent)
0020 {
0021     QStandardPaths::setTestModeEnabled(true);
0022 }
0023 
0024 void SendLaterUtilTest::shouldRestoreFromSettings()
0025 {
0026     MessageComposer::SendLaterInfo info;
0027     const QString to = QStringLiteral("kde.org");
0028     info.setTo(to);
0029     info.setItemId(Akonadi::Item::Id(42));
0030     info.setSubject(QStringLiteral("Subject"));
0031     info.setRecurrence(true);
0032     info.setRecurrenceEachValue(5);
0033     info.setRecurrenceUnit(MessageComposer::SendLaterInfo::Years);
0034     const QDate date(2014, 1, 1);
0035     info.setDateTime(QDateTime(date.startOfDay()));
0036     info.setLastDateTimeSend(QDateTime(date.startOfDay()));
0037     SendLaterUtil::writeSendLaterInfo(KSharedConfig::openConfig(), &info);
0038 
0039     KConfigGroup grp(KSharedConfig::openConfig(), SendLaterUtil::sendLaterPattern().arg(42));
0040     std::unique_ptr<MessageComposer::SendLaterInfo> restoreInfo{SendLaterUtil::readSendLaterInfo(grp)};
0041     QCOMPARE(info, *restoreInfo);
0042 }
0043 
0044 QTEST_GUILESS_MAIN(SendLaterUtilTest)
0045 
0046 #include "moc_sendlaterutiltest.cpp"