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 "retentionpolicysettingswidgettest.h" 0008 #include "administratorsettingsdialog/retentionpolicy/retentionpolicysettingswidget.h" 0009 #include "settingswidgetshelper.h" 0010 #include <QCheckBox> 0011 #include <QComboBox> 0012 #include <QSpinBox> 0013 0014 QTEST_MAIN(RetentionPolicySettingsWidgetTest) 0015 RetentionPolicySettingsWidgetTest::RetentionPolicySettingsWidgetTest(QObject *parent) 0016 : QObject{parent} 0017 { 0018 } 0019 0020 void RetentionPolicySettingsWidgetTest::shouldHaveDefaultValues() 0021 { 0022 RetentionPolicySettingsWidget w(nullptr); 0023 QVERIFY(w.widgetResizable()); 0024 0025 auto mEnabled = w.findChild<QCheckBox *>(QStringLiteral("mEnabled")); 0026 QVERIFY(mEnabled); 0027 QVERIFY(!mEnabled->isChecked()); 0028 QVERIFY(!mEnabled->text().isEmpty()); 0029 QCOMPARE(SettingsWidgetHelper::widgetSettingsName(mEnabled), QStringLiteral("RetentionPolicy_Enabled")); 0030 0031 auto mUseAdvancedRetentionPolicyConfiguration = w.findChild<QCheckBox *>(QStringLiteral("mUseAdvancedRetentionPolicyConfiguration")); 0032 QVERIFY(mUseAdvancedRetentionPolicyConfiguration); 0033 QVERIFY(!mUseAdvancedRetentionPolicyConfiguration->isChecked()); 0034 QVERIFY(!mUseAdvancedRetentionPolicyConfiguration->text().isEmpty()); 0035 QCOMPARE(SettingsWidgetHelper::widgetSettingsName(mUseAdvancedRetentionPolicyConfiguration), QStringLiteral("RetentionPolicy_Advanced_Precision")); 0036 0037 auto mDontPruneThreads = w.findChild<QCheckBox *>(QStringLiteral("mDontPruneThreads")); 0038 QVERIFY(mDontPruneThreads); 0039 QVERIFY(!mDontPruneThreads->isChecked()); 0040 QVERIFY(!mDontPruneThreads->text().isEmpty()); 0041 QCOMPARE(SettingsWidgetHelper::widgetSettingsName(mDontPruneThreads), QStringLiteral("RetentionPolicy_DoNotPruneThreads")); 0042 0043 auto mDontPruneDiscussion = w.findChild<QCheckBox *>(QStringLiteral("mDontPruneDiscussion")); 0044 QVERIFY(mDontPruneDiscussion); 0045 QVERIFY(!mDontPruneDiscussion->isChecked()); 0046 QVERIFY(!mDontPruneDiscussion->text().isEmpty()); 0047 QCOMPARE(SettingsWidgetHelper::widgetSettingsName(mDontPruneDiscussion), QStringLiteral("RetentionPolicy_DoNotPruneDiscussion")); 0048 0049 auto mDontPrunePinnedMessages = w.findChild<QCheckBox *>(QStringLiteral("mDontPrunePinnedMessages")); 0050 QVERIFY(mDontPrunePinnedMessages); 0051 QVERIFY(!mDontPrunePinnedMessages->isChecked()); 0052 QVERIFY(!mDontPrunePinnedMessages->text().isEmpty()); 0053 QCOMPARE(SettingsWidgetHelper::widgetSettingsName(mDontPrunePinnedMessages), QStringLiteral("RetentionPolicy_DoNotPrunePinned")); 0054 0055 auto mOnlyDeleteFiles = w.findChild<QCheckBox *>(QStringLiteral("mOnlyDeleteFiles")); 0056 QVERIFY(mOnlyDeleteFiles); 0057 QVERIFY(!mOnlyDeleteFiles->isChecked()); 0058 QVERIFY(!mOnlyDeleteFiles->text().isEmpty()); 0059 QVERIFY(!mOnlyDeleteFiles->toolTip().isEmpty()); 0060 QCOMPARE(SettingsWidgetHelper::widgetSettingsName(mOnlyDeleteFiles), QStringLiteral("RetentionPolicy_FilesOnly")); 0061 0062 auto mAppliesChannels = w.findChild<QCheckBox *>(QStringLiteral("mAppliesChannels")); 0063 QVERIFY(mAppliesChannels); 0064 QVERIFY(!mAppliesChannels->isChecked()); 0065 QVERIFY(!mAppliesChannels->text().isEmpty()); 0066 QCOMPARE(SettingsWidgetHelper::widgetSettingsName(mAppliesChannels), QStringLiteral("RetentionPolicy_AppliesToChannels")); 0067 0068 auto mAppliesGroups = w.findChild<QCheckBox *>(QStringLiteral("mAppliesGroups")); 0069 QVERIFY(mAppliesGroups); 0070 QVERIFY(!mAppliesGroups->isChecked()); 0071 QVERIFY(!mAppliesGroups->text().isEmpty()); 0072 QCOMPARE(SettingsWidgetHelper::widgetSettingsName(mAppliesGroups), QStringLiteral("RetentionPolicy_AppliesToGroups")); 0073 0074 auto mAppliesMessages = w.findChild<QCheckBox *>(QStringLiteral("mAppliesMessages")); 0075 QVERIFY(mAppliesMessages); 0076 QVERIFY(!mAppliesMessages->isChecked()); 0077 QVERIFY(!mAppliesMessages->text().isEmpty()); 0078 QCOMPARE(SettingsWidgetHelper::widgetSettingsName(mAppliesMessages), QStringLiteral("RetentionPolicy_AppliesToDMs")); 0079 0080 auto mMaximumMessageDirectMessages = w.findChild<QSpinBox *>(QStringLiteral("mMaximumMessageDirectMessages")); 0081 QVERIFY(mMaximumMessageDirectMessages); 0082 QVERIFY(!mMaximumMessageDirectMessages->toolTip().isEmpty()); 0083 QCOMPARE(mMaximumMessageDirectMessages->maximum(), 9999); 0084 QCOMPARE(SettingsWidgetHelper::widgetSettingsName(mMaximumMessageDirectMessages), QStringLiteral("RetentionPolicy_MaxAge_DMs")); 0085 SettingsWidgetHelper::checkLabelToolButton(&w, QStringLiteral("RetentionPolicy_MaxAge_DMs")); 0086 0087 auto mMaximumMessagePrivateGroups = w.findChild<QSpinBox *>(QStringLiteral("mMaximumMessagePrivateGroups")); 0088 QVERIFY(mMaximumMessagePrivateGroups); 0089 QVERIFY(!mMaximumMessagePrivateGroups->toolTip().isEmpty()); 0090 QCOMPARE(mMaximumMessagePrivateGroups->maximum(), 9999); 0091 QCOMPARE(SettingsWidgetHelper::widgetSettingsName(mMaximumMessagePrivateGroups), QStringLiteral("RetentionPolicy_MaxAge_Groups")); 0092 SettingsWidgetHelper::checkLabelToolButton(&w, QStringLiteral("RetentionPolicy_MaxAge_Groups")); 0093 0094 auto mMaximumMessageChannels = w.findChild<QSpinBox *>(QStringLiteral("mMaximumMessageChannels")); 0095 QVERIFY(mMaximumMessageChannels); 0096 QVERIFY(!mMaximumMessageChannels->toolTip().isEmpty()); 0097 QCOMPARE(mMaximumMessageChannels->maximum(), 9999); 0098 QCOMPARE(SettingsWidgetHelper::widgetSettingsName(mMaximumMessageChannels), QStringLiteral("RetentionPolicy_MaxAge_Channels")); 0099 SettingsWidgetHelper::checkLabelToolButton(&w, QStringLiteral("RetentionPolicy_MaxAge_Channels")); 0100 0101 auto mTimerPrecision = w.findChild<QComboBox *>(QStringLiteral("mTimerPrecision")); 0102 QVERIFY(mTimerPrecision); 0103 QCOMPARE(mTimerPrecision->count(), 4); 0104 QCOMPARE(SettingsWidgetHelper::widgetSettingsName(mTimerPrecision), QStringLiteral("RetentionPolicy_Precision")); 0105 } 0106 0107 #include "moc_retentionpolicysettingswidgettest.cpp"