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

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 "emailsettingswidgettest.h"
0008 #include "administratorsettingsdialog/email/emailsettingswidget.h"
0009 #include "settingswidgetshelper.h"
0010 #include <KPasswordLineEdit>
0011 #include <QComboBox>
0012 #include <QLabel>
0013 #include <QLineEdit>
0014 #include <QPlainTextEdit>
0015 #include <QSpinBox>
0016 QTEST_MAIN(EmailSettingsWidgetTest)
0017 EmailSettingsWidgetTest::EmailSettingsWidgetTest(QObject *parent)
0018     : QObject{parent}
0019 {
0020 }
0021 
0022 void EmailSettingsWidgetTest::shouldHaveDefaultValues()
0023 {
0024     EmailSettingsWidget w(nullptr);
0025     auto smtpLabel = w.findChild<QLabel *>(QStringLiteral("smtpLabel"));
0026     QVERIFY(smtpLabel);
0027     QVERIFY(!smtpLabel->text().isEmpty());
0028 
0029     auto mSmtpHost = w.findChild<QLineEdit *>(QStringLiteral("mSmtpHost"));
0030     QVERIFY(mSmtpHost);
0031     QVERIFY(mSmtpHost->text().isEmpty());
0032     QVERIFY(mSmtpHost->toolTip().isEmpty());
0033     QCOMPARE(SettingsWidgetHelper::widgetSettingsName(mSmtpHost), QStringLiteral("SMTP_Host"));
0034     SettingsWidgetHelper::checkLabelToolButton(&w, QStringLiteral("SMTP_Host"));
0035 
0036     auto mSmtpPort = w.findChild<QSpinBox *>(QStringLiteral("mSmtpPort"));
0037     QVERIFY(mSmtpPort);
0038     QVERIFY(mSmtpPort->toolTip().isEmpty());
0039     QCOMPARE(SettingsWidgetHelper::widgetSettingsName(mSmtpPort), QStringLiteral("SMTP_Port"));
0040     SettingsWidgetHelper::checkLabelToolButton(&w, QStringLiteral("SMTP_Port"));
0041 
0042     auto mIgnoreTls = w.findChild<QCheckBox *>(QStringLiteral("mIgnoreTls"));
0043     QVERIFY(mIgnoreTls);
0044     QVERIFY(!mIgnoreTls->isChecked());
0045     QVERIFY(!mIgnoreTls->text().isEmpty());
0046     QVERIFY(mIgnoreTls->toolTip().isEmpty());
0047     QCOMPARE(SettingsWidgetHelper::widgetSettingsName(mIgnoreTls), QStringLiteral("SMTP_IgnoreTLS"));
0048 
0049     auto mUserName = w.findChild<QLineEdit *>(QStringLiteral("mUserName"));
0050     QVERIFY(mUserName);
0051     QVERIFY(mUserName->text().isEmpty());
0052     QVERIFY(mUserName->toolTip().isEmpty());
0053     QCOMPARE(SettingsWidgetHelper::widgetSettingsName(mUserName), QStringLiteral("SMTP_Username"));
0054     SettingsWidgetHelper::checkLabelToolButton(&w, QStringLiteral("SMTP_Username"));
0055 
0056     auto mFromEmail = w.findChild<QLineEdit *>(QStringLiteral("mFromEmail"));
0057     QVERIFY(mFromEmail);
0058     QVERIFY(mFromEmail->text().isEmpty());
0059     QVERIFY(mFromEmail->toolTip().isEmpty());
0060     QCOMPARE(SettingsWidgetHelper::widgetSettingsName(mFromEmail), QStringLiteral("From_Email"));
0061     SettingsWidgetHelper::checkLabelToolButton(&w, QStringLiteral("From_Email"));
0062 
0063     auto mSmtpPassword = w.findChild<KPasswordLineEdit *>(QStringLiteral("mSmtpPassword"));
0064     QVERIFY(mSmtpPassword);
0065     QVERIFY(mSmtpPassword->password().isEmpty());
0066     QVERIFY(mSmtpPassword->toolTip().isEmpty());
0067     QCOMPARE(SettingsWidgetHelper::widgetSettingsName(mSmtpPassword), QStringLiteral("SMTP_Password"));
0068     SettingsWidgetHelper::checkLabelToolButton(&w, QStringLiteral("SMTP_Password"));
0069 
0070     auto privacyLabel = w.findChild<QLabel *>(QStringLiteral("privacyLabel"));
0071     QVERIFY(privacyLabel);
0072     QVERIFY(!privacyLabel->text().isEmpty());
0073 
0074     auto mShowMessageEmailNotification = w.findChild<QCheckBox *>(QStringLiteral("mShowMessageEmailNotification"));
0075     QVERIFY(mShowMessageEmailNotification);
0076     QVERIFY(!mShowMessageEmailNotification->isChecked());
0077     QVERIFY(!mShowMessageEmailNotification->text().isEmpty());
0078     QVERIFY(mShowMessageEmailNotification->toolTip().isEmpty());
0079     QCOMPARE(SettingsWidgetHelper::widgetSettingsName(mShowMessageEmailNotification), QStringLiteral("Email_notification_show_message"));
0080 
0081     auto mAddSenderReplyTo = w.findChild<QCheckBox *>(QStringLiteral("mAddSenderReplyTo"));
0082     QVERIFY(mAddSenderReplyTo);
0083     QVERIFY(!mAddSenderReplyTo->isChecked());
0084     QVERIFY(!mAddSenderReplyTo->text().isEmpty());
0085     QVERIFY(mAddSenderReplyTo->toolTip().isEmpty());
0086     QCOMPARE(SettingsWidgetHelper::widgetSettingsName(mAddSenderReplyTo), QStringLiteral("Add_Sender_To_ReplyTo"));
0087 
0088     auto directReplyLabel = w.findChild<QLabel *>(QStringLiteral("directReplyLabel"));
0089     QVERIFY(directReplyLabel);
0090     QVERIFY(!directReplyLabel->text().isEmpty());
0091 
0092     auto mEnableDirectReply = w.findChild<QCheckBox *>(QStringLiteral("mEnableDirectReply"));
0093     QVERIFY(mEnableDirectReply);
0094     QVERIFY(!mEnableDirectReply->isChecked());
0095     QVERIFY(!mEnableDirectReply->text().isEmpty());
0096     QVERIFY(!mEnableDirectReply->toolTip().isEmpty());
0097     QCOMPARE(SettingsWidgetHelper::widgetSettingsName(mEnableDirectReply), QStringLiteral("Direct_Reply_Enable"));
0098 
0099     auto mDebugDirectReply = w.findChild<QCheckBox *>(QStringLiteral("mDebugDirectReply"));
0100     QVERIFY(mDebugDirectReply);
0101     QVERIFY(!mDebugDirectReply->isChecked());
0102     QVERIFY(!mDebugDirectReply->text().isEmpty());
0103     QVERIFY(!mDebugDirectReply->toolTip().isEmpty());
0104     QCOMPARE(SettingsWidgetHelper::widgetSettingsName(mDebugDirectReply), QStringLiteral("Direct_Reply_Debug"));
0105 
0106     auto forgotPasswordLabel = w.findChild<QLabel *>(QStringLiteral("forgotPasswordLabel"));
0107     QVERIFY(forgotPasswordLabel);
0108     QVERIFY(!forgotPasswordLabel->text().isEmpty());
0109 
0110     auto subjectLabel = w.findChild<QLabel *>(QStringLiteral("subjectLabel"));
0111     QVERIFY(subjectLabel);
0112     QVERIFY(!subjectLabel->text().isEmpty());
0113 
0114     auto mDirectMessageEmailSubject = w.findChild<QPlainTextEdit *>(QStringLiteral("mDirectMessageEmailSubject"));
0115     QVERIFY(mDirectMessageEmailSubject);
0116     QVERIFY(mDirectMessageEmailSubject->toPlainText().isEmpty());
0117     QCOMPARE(SettingsWidgetHelper::widgetSettingsName(mDirectMessageEmailSubject), QStringLiteral("Offline_DM_Email"));
0118     SettingsWidgetHelper::checkLabelToolButton(&w, QStringLiteral("Offline_DM_Email"));
0119 
0120     auto mMentionEmailSubject = w.findChild<QPlainTextEdit *>(QStringLiteral("mMentionEmailSubject"));
0121     QVERIFY(mMentionEmailSubject);
0122     QVERIFY(mMentionEmailSubject->toPlainText().isEmpty());
0123     QCOMPARE(SettingsWidgetHelper::widgetSettingsName(mMentionEmailSubject), QStringLiteral("Offline_Mention_Email"));
0124     SettingsWidgetHelper::checkLabelToolButton(&w, QStringLiteral("Offline_Mention_Email"));
0125 
0126     auto mMentionAllEmailSubject = w.findChild<QPlainTextEdit *>(QStringLiteral("mMentionAllEmailSubject"));
0127     QVERIFY(mMentionAllEmailSubject);
0128     QVERIFY(mMentionAllEmailSubject->toPlainText().isEmpty());
0129     QCOMPARE(SettingsWidgetHelper::widgetSettingsName(mMentionAllEmailSubject), QStringLiteral("Offline_Mention_All_Email"));
0130     SettingsWidgetHelper::checkLabelToolButton(&w, QStringLiteral("Offline_Mention_All_Email"));
0131 
0132     auto verificationLabel = w.findChild<QLabel *>(QStringLiteral("verificationLabel"));
0133     QVERIFY(verificationLabel);
0134     QVERIFY(!verificationLabel->text().isEmpty());
0135 
0136     auto mVerificationSubject = w.findChild<QLineEdit *>(QStringLiteral("mVerificationSubject"));
0137     QVERIFY(mVerificationSubject);
0138     QVERIFY(mVerificationSubject->text().isEmpty());
0139     QVERIFY(mVerificationSubject->toolTip().isEmpty());
0140     QCOMPARE(SettingsWidgetHelper::widgetSettingsName(mVerificationSubject), QStringLiteral("Verification_Email_Subject"));
0141     SettingsWidgetHelper::checkLabelToolButton(&w, QStringLiteral("Verification_Email_Subject"));
0142 
0143     auto mVerificationBody = w.findChild<QPlainTextEdit *>(QStringLiteral("mVerificationBody"));
0144     QVERIFY(mVerificationBody);
0145     QVERIFY(mVerificationBody->toPlainText().isEmpty());
0146     QCOMPARE(SettingsWidgetHelper::widgetSettingsName(mVerificationBody), QStringLiteral("Verification_Email"));
0147     SettingsWidgetHelper::checkLabelToolButton(&w, QStringLiteral("Verification_Email"));
0148 
0149     auto mForgotPasswordSubject = w.findChild<QLineEdit *>(QStringLiteral("mForgotPasswordSubject"));
0150     QVERIFY(mForgotPasswordSubject);
0151     QVERIFY(mForgotPasswordSubject->text().isEmpty());
0152     QVERIFY(mForgotPasswordSubject->toolTip().isEmpty());
0153     QCOMPARE(SettingsWidgetHelper::widgetSettingsName(mForgotPasswordSubject), QStringLiteral("Forgot_Password_Email_Subject"));
0154     SettingsWidgetHelper::checkLabelToolButton(&w, QStringLiteral("Forgot_Password_Email_Subject"));
0155 
0156     auto mForgotPasswordBody = w.findChild<QPlainTextEdit *>(QStringLiteral("mForgotPasswordBody"));
0157     QVERIFY(mForgotPasswordBody);
0158     QVERIFY(mForgotPasswordBody->toPlainText().isEmpty());
0159     QCOMPARE(SettingsWidgetHelper::widgetSettingsName(mForgotPasswordBody), QStringLiteral("Forgot_Password_Email"));
0160     SettingsWidgetHelper::checkLabelToolButton(&w, QStringLiteral("Forgot_Password_Email"));
0161 
0162     auto emailAddressChangedLabel = w.findChild<QLabel *>(QStringLiteral("emailAddressChangedLabel"));
0163     QVERIFY(emailAddressChangedLabel);
0164     QVERIFY(!emailAddressChangedLabel->text().isEmpty());
0165 
0166     auto mEmailAddressChangedSubject = w.findChild<QLineEdit *>(QStringLiteral("mEmailAddressChangedSubject"));
0167     QVERIFY(mEmailAddressChangedSubject);
0168     QVERIFY(mEmailAddressChangedSubject->text().isEmpty());
0169     QVERIFY(mEmailAddressChangedSubject->toolTip().isEmpty());
0170     QCOMPARE(SettingsWidgetHelper::widgetSettingsName(mEmailAddressChangedSubject), QStringLiteral("Email_Changed_Email_Subject"));
0171     SettingsWidgetHelper::checkLabelToolButton(&w, QStringLiteral("Email_Changed_Email_Subject"));
0172 
0173     auto mEmailAddressChangedBody = w.findChild<QPlainTextEdit *>(QStringLiteral("mEmailAddressChangedBody"));
0174     QVERIFY(mEmailAddressChangedBody);
0175     QVERIFY(mEmailAddressChangedBody->toPlainText().isEmpty());
0176     QCOMPARE(SettingsWidgetHelper::widgetSettingsName(mEmailAddressChangedBody), QStringLiteral("Email_Changed_Email"));
0177     SettingsWidgetHelper::checkLabelToolButton(&w, QStringLiteral("Email_Changed_Email"));
0178 
0179     auto invitationLabel = w.findChild<QLabel *>(QStringLiteral("invitationLabel"));
0180     QVERIFY(invitationLabel);
0181     QVERIFY(!invitationLabel->text().isEmpty());
0182 
0183     auto mInvitationSubject = w.findChild<QLineEdit *>(QStringLiteral("mInvitationSubject"));
0184     QVERIFY(mInvitationSubject);
0185     QVERIFY(mInvitationSubject->text().isEmpty());
0186     QVERIFY(mInvitationSubject->toolTip().isEmpty());
0187     QCOMPARE(SettingsWidgetHelper::widgetSettingsName(mInvitationSubject), QStringLiteral("Invitation_Subject"));
0188     SettingsWidgetHelper::checkLabelToolButton(&w, QStringLiteral("Invitation_Subject"));
0189 
0190     auto mInvitationBody = w.findChild<QPlainTextEdit *>(QStringLiteral("mInvitationBody"));
0191     QVERIFY(mInvitationBody);
0192     QVERIFY(mInvitationBody->toPlainText().isEmpty());
0193     QCOMPARE(SettingsWidgetHelper::widgetSettingsName(mInvitationBody), QStringLiteral("Invitation_Email"));
0194     SettingsWidgetHelper::checkLabelToolButton(&w, QStringLiteral("Invitation_Email"));
0195 
0196     auto mSmtpProtocol = w.findChild<QComboBox *>(QStringLiteral("mSmtpProtocol"));
0197     QVERIFY(mSmtpProtocol);
0198     QCOMPARE(mSmtpProtocol->count(), 2);
0199     QCOMPARE(SettingsWidgetHelper::widgetSettingsName(mSmtpProtocol), QStringLiteral("SMTP_Protocol"));
0200 
0201     auto mPasswordChangedSubject = w.findChild<QLineEdit *>(QStringLiteral("mPasswordChangedSubject"));
0202     QVERIFY(mPasswordChangedSubject);
0203     QVERIFY(mPasswordChangedSubject->text().isEmpty());
0204     QVERIFY(mPasswordChangedSubject->toolTip().isEmpty());
0205     QCOMPARE(SettingsWidgetHelper::widgetSettingsName(mPasswordChangedSubject), QStringLiteral("Password_Changed_Email_Subject"));
0206     SettingsWidgetHelper::checkLabelToolButton(&w, QStringLiteral("Password_Changed_Email_Subject"));
0207 
0208     auto mPasswordChangedBody = w.findChild<QPlainTextEdit *>(QStringLiteral("mPasswordChangedBody"));
0209     QVERIFY(mPasswordChangedBody);
0210     QVERIFY(mPasswordChangedBody->toPlainText().isEmpty());
0211     QCOMPARE(SettingsWidgetHelper::widgetSettingsName(mPasswordChangedBody), QStringLiteral("Password_Changed_Email"));
0212     SettingsWidgetHelper::checkLabelToolButton(&w, QStringLiteral("Password_Changed_Email"));
0213 }
0214 
0215 #include "moc_emailsettingswidgettest.cpp"