File indexing completed on 2024-12-22 04:45:41

0001 /*
0002    SPDX-FileCopyrightText: 2022-2024 Laurent Montel <montel@kde.org>
0003 
0004    SPDX-License-Identifier: LGPL-2.0-or-later
0005 */
0006 
0007 #include "generalsettingswidgettest.h"
0008 #include "administratorsettingsdialog/general/generalsettingswidget.h"
0009 #include "settingswidgetshelper.h"
0010 #include <QCheckBox>
0011 #include <QComboBox>
0012 #include <QFormLayout>
0013 #include <QLabel>
0014 #include <QLineEdit>
0015 #include <QSpinBox>
0016 
0017 QTEST_MAIN(GeneralSettingsWidgetTest)
0018 GeneralSettingsWidgetTest::GeneralSettingsWidgetTest(QObject *parent)
0019     : QObject{parent}
0020 {
0021 }
0022 
0023 void GeneralSettingsWidgetTest::shouldHaveDefaultValues()
0024 {
0025     GeneralSettingsWidget w(nullptr);
0026     QVERIFY(w.widgetResizable());
0027 
0028     auto mainLayout = w.findChild<QFormLayout *>(QStringLiteral("mainLayout"));
0029     QVERIFY(mainLayout);
0030 
0031     auto mEnableFavoriteRooms = w.findChild<QCheckBox *>(QStringLiteral("mEnableFavoriteRooms"));
0032     QVERIFY(mEnableFavoriteRooms);
0033     QVERIFY(!mEnableFavoriteRooms->isChecked());
0034     QVERIFY(!mEnableFavoriteRooms->text().isEmpty());
0035     QCOMPARE(SettingsWidgetHelper::widgetSettingsName(mEnableFavoriteRooms), QStringLiteral("Favorite_Rooms"));
0036 
0037     auto mSiteUrl = w.findChild<QLineEdit *>(QStringLiteral("mSiteUrl"));
0038     QVERIFY(mSiteUrl);
0039     QVERIFY(mSiteUrl->text().isEmpty());
0040     QCOMPARE(SettingsWidgetHelper::widgetSettingsName(mSiteUrl), QStringLiteral("Site_Url"));
0041     SettingsWidgetHelper::checkLabelToolButton(&w, QStringLiteral("Site_Url"));
0042 
0043     auto mSiteName = w.findChild<QLineEdit *>(QStringLiteral("mSiteName"));
0044     QVERIFY(mSiteName);
0045     QVERIFY(mSiteName->text().isEmpty());
0046     QCOMPARE(SettingsWidgetHelper::widgetSettingsName(mSiteName), QStringLiteral("Site_Name"));
0047     SettingsWidgetHelper::checkLabelToolButton(&w, QStringLiteral("Site_Name"));
0048 
0049     auto utf8Label = w.findChild<QLabel *>(QStringLiteral("utf8Label"));
0050     QVERIFY(utf8Label);
0051     QVERIFY(!utf8Label->text().isEmpty());
0052 
0053     auto mUTF8UsernamesValidation = w.findChild<QLineEdit *>(QStringLiteral("mUTF8UsernamesValidation"));
0054     QVERIFY(mUTF8UsernamesValidation);
0055     QVERIFY(mUTF8UsernamesValidation->text().isEmpty());
0056     QVERIFY(!mUTF8UsernamesValidation->toolTip().isEmpty());
0057     QCOMPARE(SettingsWidgetHelper::widgetSettingsName(mUTF8UsernamesValidation), QStringLiteral("UTF8_User_Names_Validation"));
0058     SettingsWidgetHelper::checkLabelToolButton(&w, QStringLiteral("UTF8_User_Names_Validation"));
0059 
0060     auto mUTF8ChannelNamesValidation = w.findChild<QLineEdit *>(QStringLiteral("mUTF8ChannelNamesValidation"));
0061     QVERIFY(mUTF8ChannelNamesValidation);
0062     QVERIFY(mUTF8UsernamesValidation->text().isEmpty());
0063     QVERIFY(!mUTF8ChannelNamesValidation->toolTip().isEmpty());
0064     QCOMPARE(SettingsWidgetHelper::widgetSettingsName(mUTF8ChannelNamesValidation), QStringLiteral("UTF8_Channel_Names_Validation"));
0065     SettingsWidgetHelper::checkLabelToolButton(&w, QStringLiteral("UTF8_Channel_Names_Validation"));
0066 
0067     auto mFirstChannelAfterLogin = w.findChild<QLineEdit *>(QStringLiteral("mFirstChannelAfterLogin"));
0068     QVERIFY(mFirstChannelAfterLogin);
0069     QVERIFY(mFirstChannelAfterLogin->text().isEmpty());
0070     QCOMPARE(SettingsWidgetHelper::widgetSettingsName(mFirstChannelAfterLogin), QStringLiteral("First_Channel_After_Login"));
0071     SettingsWidgetHelper::checkLabelToolButton(&w, QStringLiteral("First_Channel_After_Login"));
0072 
0073     auto mDeepLinkUrl = w.findChild<QLineEdit *>(QStringLiteral("mDeepLinkUrl"));
0074     QVERIFY(mDeepLinkUrl);
0075     QVERIFY(mDeepLinkUrl->text().isEmpty());
0076     QCOMPARE(SettingsWidgetHelper::widgetSettingsName(mDeepLinkUrl), QStringLiteral("DeepLink_Url"));
0077 
0078     auto mCDNPrefix = w.findChild<QLineEdit *>(QStringLiteral("mCDNPrefix"));
0079     QVERIFY(mCDNPrefix);
0080     QVERIFY(mCDNPrefix->text().isEmpty());
0081     QCOMPARE(SettingsWidgetHelper::widgetSettingsName(mCDNPrefix), QStringLiteral("CDN_PREFIX"));
0082 
0083     auto mUnreadCount = w.findChild<QComboBox *>(QStringLiteral("mUnreadCount"));
0084     QVERIFY(mUnreadCount);
0085     QCOMPARE(mUnreadCount->count(), 4);
0086     QCOMPARE(SettingsWidgetHelper::widgetSettingsName(mUnreadCount), QStringLiteral("Unread_Count"));
0087 
0088     auto mUnreadCountDirectMessages = w.findChild<QComboBox *>(QStringLiteral("mUnreadCountDirectMessages"));
0089     QVERIFY(mUnreadCountDirectMessages);
0090     QCOMPARE(mUnreadCountDirectMessages->count(), 2);
0091     QCOMPARE(SettingsWidgetHelper::widgetSettingsName(mUnreadCountDirectMessages), QStringLiteral("Unread_Count_DM"));
0092 
0093     auto mEnableUpdateChecker = w.findChild<QCheckBox *>(QStringLiteral("mEnableUpdateChecker"));
0094     QVERIFY(mEnableUpdateChecker);
0095     QVERIFY(!mEnableUpdateChecker->isChecked());
0096     QVERIFY(!mEnableUpdateChecker->text().isEmpty());
0097     QVERIFY(!mEnableUpdateChecker->toolTip().isEmpty());
0098     QCOMPARE(SettingsWidgetHelper::widgetSettingsName(mEnableUpdateChecker), QStringLiteral("Update_EnableChecker"));
0099 
0100     auto mUpdateLatestAvailableVersion = w.findChild<QLineEdit *>(QStringLiteral("mUpdateLatestAvailableVersion"));
0101     QVERIFY(mUpdateLatestAvailableVersion);
0102     QVERIFY(mUpdateLatestAvailableVersion->text().isEmpty());
0103     QCOMPARE(SettingsWidgetHelper::widgetSettingsName(mUpdateLatestAvailableVersion), QStringLiteral("Update_LatestAvailableVersion"));
0104 
0105     auto updateLabel = w.findChild<QLabel *>(QStringLiteral("updateLabel"));
0106     QVERIFY(updateLabel);
0107     QVERIFY(!updateLabel->text().isEmpty());
0108 
0109     auto timeZoneLabel = w.findChild<QLabel *>(QStringLiteral("timeZoneLabel"));
0110     QVERIFY(timeZoneLabel);
0111     QVERIFY(!timeZoneLabel->text().isEmpty());
0112 
0113     auto mDefaultTimeZone = w.findChild<QComboBox *>(QStringLiteral("mDefaultTimeZone"));
0114     QVERIFY(mDefaultTimeZone);
0115     QCOMPARE(mDefaultTimeZone->count(), 3);
0116     QCOMPARE(SettingsWidgetHelper::widgetSettingsName(mDefaultTimeZone), QStringLiteral("Default_Timezone_For_Reporting"));
0117 
0118     auto mUTF8NamesSlugify = w.findChild<QCheckBox *>(QStringLiteral("mUTF8NamesSlugify"));
0119     QVERIFY(mUTF8NamesSlugify);
0120     QVERIFY(!mUTF8NamesSlugify->isChecked());
0121     QVERIFY(!mUTF8NamesSlugify->text().isEmpty());
0122     QCOMPARE(SettingsWidgetHelper::widgetSettingsName(mUTF8NamesSlugify), QStringLiteral("UTF8_Names_Slugify"));
0123 
0124     auto reportingLabel = w.findChild<QLabel *>(QStringLiteral("reportingLabel"));
0125     QVERIFY(reportingLabel);
0126     QVERIFY(!reportingLabel->text().isEmpty());
0127 
0128     auto mSendStatisticsRocketChat = w.findChild<QCheckBox *>(QStringLiteral("mSendStatisticsRocketChat"));
0129     QVERIFY(mSendStatisticsRocketChat);
0130     QVERIFY(!mSendStatisticsRocketChat->isChecked());
0131     QVERIFY(!mSendStatisticsRocketChat->text().isEmpty());
0132     QCOMPARE(SettingsWidgetHelper::widgetSettingsName(mSendStatisticsRocketChat), QStringLiteral("Statistics_reporting"));
0133 
0134     auto notificationLabel = w.findChild<QLabel *>(QStringLiteral("notificationLabel"));
0135     QVERIFY(notificationLabel);
0136     QVERIFY(!notificationLabel->text().isEmpty());
0137 
0138     auto mMaxRoomMembersDisablingMessageNotifications = w.findChild<QSpinBox *>(QStringLiteral("mMaxRoomMembersDisablingMessageNotifications"));
0139     QVERIFY(mMaxRoomMembersDisablingMessageNotifications);
0140     QVERIFY(!mMaxRoomMembersDisablingMessageNotifications->toolTip().isEmpty());
0141     QCOMPARE(SettingsWidgetHelper::widgetSettingsName(mMaxRoomMembersDisablingMessageNotifications), QStringLiteral("Notifications_Max_Room_Members"));
0142     SettingsWidgetHelper::checkLabelToolButton(&w, QStringLiteral("Notifications_Max_Room_Members"));
0143 
0144     auto streamCastLabel = w.findChild<QLabel *>(QStringLiteral("streamCastLabel"));
0145     QVERIFY(streamCastLabel);
0146     QVERIFY(!streamCastLabel->text().isEmpty());
0147 
0148     auto mStreamCastAddress = w.findChild<QLineEdit *>(QStringLiteral("mStreamCastAddress"));
0149     QVERIFY(mStreamCastAddress);
0150     QVERIFY(mStreamCastAddress->text().isEmpty());
0151     QVERIFY(!mStreamCastAddress->toolTip().isEmpty());
0152     QCOMPARE(SettingsWidgetHelper::widgetSettingsName(mStreamCastAddress), QStringLiteral("Stream_Cast_Address"));
0153 }
0154 
0155 #include "moc_generalsettingswidgettest.cpp"