File indexing completed on 2024-12-01 04:35:25

0001 /*
0002    SPDX-FileCopyrightText: 2018-2024 Laurent Montel <montel@kde.org>
0003 
0004    SPDX-License-Identifier: LGPL-2.0-or-later
0005 */
0006 
0007 #include "notificationoptionstest.h"
0008 #include "notifications/notificationoptions.h"
0009 #include <QJsonDocument>
0010 #include <QJsonObject>
0011 #include <QTest>
0012 QTEST_GUILESS_MAIN(NotificationOptionsTest)
0013 
0014 NotificationOptionsTest::NotificationOptionsTest(QObject *parent)
0015     : QObject(parent)
0016 {
0017 }
0018 
0019 void NotificationOptionsTest::shouldHaveDefaultValue()
0020 {
0021     NotificationOptions w;
0022     QVERIFY(w.desktopNotifications().isEmpty());
0023     QVERIFY(w.mobilePushNotification().isEmpty());
0024     QVERIFY(w.emailNotifications().isEmpty());
0025     QVERIFY(w.unreadTrayIconAlert().isEmpty());
0026     QVERIFY(!w.disableNotifications());
0027     QVERIFY(!w.hideUnreadStatus());
0028     QVERIFY(!w.muteGroupMentions());
0029     QVERIFY(w.audioNotificationValue().isEmpty());
0030 }
0031 
0032 void NotificationOptionsTest::shouldAssignValue()
0033 {
0034     NotificationOptions w;
0035     NotificationOptions::NotificationValue desktopNotifications = NotificationOptions::NotificationValue{QStringLiteral("bla"), QString()};
0036     w.setDesktopNotifications(desktopNotifications);
0037 
0038     NotificationOptions::NotificationValue mobilePushNotification = NotificationOptions::NotificationValue{QStringLiteral("bli"), QString()};
0039     w.setMobilePushNotification(mobilePushNotification);
0040 
0041     NotificationOptions::NotificationValue emailNotifications = NotificationOptions::NotificationValue{QStringLiteral("blu"), QString()};
0042     w.setEmailNotifications(emailNotifications);
0043 
0044     QString unreadTrayIconAlert = QStringLiteral("Ablu");
0045     w.setUnreadTrayIconAlert(unreadTrayIconAlert);
0046 
0047     QString audioNotificationValue = QStringLiteral("ZZZZ");
0048     w.setAudioNotificationValue(audioNotificationValue);
0049 
0050     bool disableNotifications = true;
0051     w.setDisableNotifications(disableNotifications);
0052 
0053     bool hideUnreadStatus = true;
0054     w.setHideUnreadStatus(hideUnreadStatus);
0055 
0056     bool muteGroupMentions = true;
0057     w.setMuteGroupMentions(muteGroupMentions);
0058 
0059     QCOMPARE(w.desktopNotifications(), desktopNotifications);
0060     QCOMPARE(w.mobilePushNotification(), mobilePushNotification);
0061     QCOMPARE(w.emailNotifications(), emailNotifications);
0062     QCOMPARE(w.unreadTrayIconAlert(), unreadTrayIconAlert);
0063     QCOMPARE(w.audioNotificationValue(), audioNotificationValue);
0064     QCOMPARE(w.disableNotifications(), disableNotifications);
0065     QCOMPARE(w.hideUnreadStatus(), hideUnreadStatus);
0066     QCOMPARE(w.muteGroupMentions(), muteGroupMentions);
0067 
0068     NotificationOptions t;
0069     t = w;
0070     QCOMPARE(t, w);
0071 }
0072 
0073 void NotificationOptionsTest::shouldParseNotification_data()
0074 {
0075     QTest::addColumn<QString>("fileNameinit");
0076     QTest::addColumn<QString>("desktopNotifications");
0077     QTest::addColumn<QString>("mobilePushNotification");
0078     QTest::addColumn<QString>("emailNotifications");
0079     NotificationOptions notif;
0080     QTest::addRow("notification1") << QStringLiteral("notification1") << QStringLiteral("default") << QStringLiteral("all") << QStringLiteral("all");
0081 }
0082 
0083 void NotificationOptionsTest::shouldParseNotification()
0084 {
0085     QFETCH(QString, fileNameinit);
0086     QFETCH(QString, desktopNotifications);
0087     QFETCH(QString, mobilePushNotification);
0088     QFETCH(QString, emailNotifications);
0089 
0090     const QString originalJsonFile = QLatin1String(RUQOLA_DATA_DIR) + QLatin1String("/notificationoption/") + fileNameinit + QLatin1String(".json");
0091     QFile f(originalJsonFile);
0092     QVERIFY(f.open(QIODevice::ReadOnly));
0093     const QByteArray content = f.readAll();
0094     f.close();
0095     const QJsonDocument doc = QJsonDocument::fromJson(content);
0096     const QJsonObject notification = doc.object();
0097 
0098     NotificationOptions w;
0099     w.parseNotificationOptions(notification);
0100     QCOMPARE(w.desktopNotifications().currentValue(), desktopNotifications);
0101     QCOMPARE(w.mobilePushNotification().currentValue(), mobilePushNotification);
0102     QCOMPARE(w.emailNotifications().currentValue(), emailNotifications);
0103 }
0104 
0105 #include "moc_notificationoptionstest.cpp"