File indexing completed on 2024-12-01 04:35:26
0001 /* 0002 SPDX-FileCopyrightText: 2020-2024 Laurent Montel <montel@kde.org> 0003 0004 SPDX-License-Identifier: LGPL-2.0-or-later 0005 */ 0006 0007 #include "ownuserpreferencestest.h" 0008 #include "ownuser/ownuserpreferences.h" 0009 #include "ruqola_autotest_helper.h" 0010 0011 QTEST_GUILESS_MAIN(OwnUserPreferencesTest) 0012 OwnUserPreferencesTest::OwnUserPreferencesTest(QObject *parent) 0013 : QObject(parent) 0014 { 0015 } 0016 0017 void OwnUserPreferencesTest::shouldHaveDefaultValues() 0018 { 0019 OwnUserPreferences p; 0020 QVERIFY(p.highlightWords().isEmpty()); 0021 QVERIFY(p.emailNotificationMode().isEmpty()); 0022 QVERIFY(p.desktopNotifications().isEmpty()); 0023 QVERIFY(p.pushNotifications().isEmpty()); 0024 QVERIFY(p.convertAsciiEmoji()); 0025 QVERIFY(p.useEmojis()); 0026 QVERIFY(!p.hideRoles()); 0027 QVERIFY(p.displayAvatars()); 0028 QCOMPARE(p.idleTimeLimit(), -1); 0029 QVERIFY(!p.showUnread()); 0030 QVERIFY(!p.showRoomAvatar()); 0031 QVERIFY(p.showFavorite()); 0032 QCOMPARE(p.roomListSortOrder(), OwnUserPreferences::RoomListSortOrder::Unknown); 0033 } 0034 0035 void OwnUserPreferencesTest::shouldLoadOwnUserPreferencesInfo_data() 0036 { 0037 QTest::addColumn<QString>("fileName"); 0038 QTest::addColumn<OwnUserPreferences>("ownUserPreferences"); 0039 { 0040 OwnUserPreferences preferences; 0041 preferences.setShowFavorite(false); 0042 preferences.setReceiveLoginDetectionEmail(true); 0043 QTest::addRow("empty") << QStringLiteral("empty") << preferences; 0044 } 0045 { 0046 OwnUserPreferences preferences; 0047 preferences.setEmailNotificationMode(QStringLiteral("mentions")); 0048 preferences.setDesktopNotifications(QStringLiteral("mentions")); 0049 preferences.setConvertAsciiEmoji(false); 0050 preferences.setUseEmojis(false); 0051 preferences.setIdleTimeLimit(300); 0052 preferences.setDisplayAvatars(true); 0053 preferences.setShowFavorite(true); 0054 preferences.setRoomListSortOrder(OwnUserPreferences::RoomListSortOrder::ByLastMessage); 0055 preferences.setReceiveLoginDetectionEmail(true); 0056 QTest::addRow("ownuserpreferences1") << QStringLiteral("ownuserpreferences1") << preferences; 0057 } 0058 } 0059 0060 void OwnUserPreferencesTest::shouldLoadOwnUserPreferencesInfo() 0061 { 0062 QFETCH(QString, fileName); 0063 QFETCH(OwnUserPreferences, ownUserPreferences); 0064 const QString originalJsonFile = QLatin1String(RUQOLA_DATA_DIR) + QLatin1String("/ownuserpreferences/") + fileName + QLatin1String(".json"); 0065 const QJsonObject obj = AutoTestHelper::loadJsonObject(originalJsonFile); 0066 0067 OwnUserPreferences r; 0068 r.parsePreferences(obj); 0069 const bool result = (r == ownUserPreferences); 0070 if (!result) { 0071 qDebug() << "result " << r; 0072 qDebug() << "expected " << ownUserPreferences; 0073 } 0074 QVERIFY(result); 0075 } 0076 0077 #include "moc_ownuserpreferencestest.cpp"