File indexing completed on 2025-02-02 05:08:40

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 "followupreminderinfotest.h"
0008 #include "../followupreminderinfo.h"
0009 
0010 #include <KConfigGroup>
0011 #include <KSharedConfig>
0012 #include <QStandardPaths>
0013 #include <QTest>
0014 
0015 FollowUpReminderInfoTest::FollowUpReminderInfoTest(QObject *parent)
0016     : QObject(parent)
0017 {
0018     QStandardPaths::setTestModeEnabled(true);
0019 }
0020 
0021 void FollowUpReminderInfoTest::shouldHaveDefaultValue()
0022 {
0023     FollowUpReminder::FollowUpReminderInfo info;
0024     QCOMPARE(info.originalMessageItemId(), Akonadi::Item::Id(-1));
0025     QCOMPARE(info.messageId(), QString());
0026     QCOMPARE(info.isValid(), false);
0027     QCOMPARE(info.to(), QString());
0028     QCOMPARE(info.subject(), QString());
0029     QCOMPARE(info.uniqueIdentifier(), -1);
0030 }
0031 
0032 void FollowUpReminderInfoTest::shoudBeNotValid()
0033 {
0034     FollowUpReminder::FollowUpReminderInfo info;
0035     // We need a messageId not empty and a valid date and a "To" not empty
0036     info.setMessageId(QStringLiteral("foo"));
0037     QCOMPARE(info.isValid(), false);
0038 
0039     const QDate date(2014, 1, 1);
0040     info.setFollowUpReminderDate(QDate(date));
0041     QCOMPARE(info.isValid(), false);
0042 
0043     const QString to = QStringLiteral("kde.org");
0044     info.setTo(to);
0045     QCOMPARE(info.isValid(), true);
0046 
0047     info.setOriginalMessageItemId(Akonadi::Item::Id(42));
0048     QCOMPARE(info.isValid(), true);
0049 }
0050 
0051 void FollowUpReminderInfoTest::shoudBeValidEvenIfSubjectIsEmpty()
0052 {
0053     FollowUpReminder::FollowUpReminderInfo info;
0054     // We need a Akonadi::Id valid and a messageId not empty and a valid date and a "To" not empty
0055     info.setMessageId(QStringLiteral("foo"));
0056     const QDate date(2014, 1, 1);
0057     info.setFollowUpReminderDate(QDate(date));
0058     const QString to = QStringLiteral("kde.org");
0059     info.setTo(to);
0060     info.setOriginalMessageItemId(Akonadi::Item::Id(42));
0061     QCOMPARE(info.isValid(), true);
0062 }
0063 
0064 void FollowUpReminderInfoTest::shouldRestoreFromSettings()
0065 {
0066     FollowUpReminder::FollowUpReminderInfo info;
0067     info.setMessageId(QStringLiteral("foo"));
0068     const QDate date(2014, 1, 1);
0069     info.setFollowUpReminderDate(QDate(date));
0070     const QString to = QStringLiteral("kde.org");
0071     info.setTo(to);
0072     info.setOriginalMessageItemId(Akonadi::Item::Id(42));
0073     info.setSubject(QStringLiteral("Subject"));
0074     info.setUniqueIdentifier(42);
0075     info.setTodoId(52);
0076 
0077     KConfigGroup grp(KSharedConfig::openConfig(), QStringLiteral("testsettings"));
0078     info.writeConfig(grp, info.uniqueIdentifier());
0079 
0080     FollowUpReminder::FollowUpReminderInfo restoreInfo(grp);
0081     QCOMPARE(info, restoreInfo);
0082 }
0083 
0084 void FollowUpReminderInfoTest::shouldCopyReminderInfo()
0085 {
0086     FollowUpReminder::FollowUpReminderInfo info;
0087     info.setMessageId(QStringLiteral("foo"));
0088     const QDate date(2014, 1, 1);
0089     info.setFollowUpReminderDate(QDate(date));
0090     const QString to = QStringLiteral("kde.org");
0091     info.setTo(to);
0092     info.setOriginalMessageItemId(Akonadi::Item::Id(42));
0093     info.setSubject(QStringLiteral("Subject"));
0094     info.setUniqueIdentifier(42);
0095     info.setTodoId(52);
0096 
0097     FollowUpReminder::FollowUpReminderInfo copyInfo(info);
0098     QCOMPARE(info, copyInfo);
0099 }
0100 
0101 QTEST_GUILESS_MAIN(FollowUpReminderInfoTest)
0102 
0103 #include "moc_followupreminderinfotest.cpp"