File indexing completed on 2024-05-12 16:27:01

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 "ruqolaloginwidgettest.h"
0008 #include "misc/passwordlineeditwidget.h"
0009 #include "ruqolaloginwidget.h"
0010 #include <KBusyIndicatorWidget>
0011 #include <KPasswordLineEdit>
0012 #include <QCheckBox>
0013 #include <QFormLayout>
0014 #include <QLabel>
0015 #include <QLineEdit>
0016 #include <QPushButton>
0017 #include <QTest>
0018 
0019 QTEST_MAIN(RuqolaLoginWidgetTest)
0020 RuqolaLoginWidgetTest::RuqolaLoginWidgetTest(QObject *parent)
0021     : QObject(parent)
0022 {
0023 }
0024 
0025 void RuqolaLoginWidgetTest::shouldHaveDefaultValues()
0026 {
0027     RuqolaLoginWidget w;
0028 
0029     auto mainLayout = w.findChild<QFormLayout *>(QStringLiteral("mainLayout"));
0030     QVERIFY(mainLayout);
0031 
0032     auto mAccountName = w.findChild<QLineEdit *>(QStringLiteral("mAccountName"));
0033     QVERIFY(mAccountName);
0034     QVERIFY(mAccountName->text().isEmpty());
0035 
0036     auto mServerUrl = w.findChild<QLineEdit *>(QStringLiteral("mServerUrl"));
0037     QVERIFY(mServerUrl);
0038     QVERIFY(mServerUrl->text().isEmpty());
0039 
0040     auto mUserName = w.findChild<QLineEdit *>(QStringLiteral("mUserName"));
0041     QVERIFY(mUserName);
0042     QVERIFY(mUserName->text().isEmpty());
0043 
0044     auto mPasswordLineEditWidget = w.findChild<PasswordLineEditWidget *>(QStringLiteral("mPasswordLineEditWidget"));
0045     QVERIFY(mPasswordLineEditWidget);
0046 
0047     //    auto mLdapCheckBox = w.findChild<QCheckBox *>(QStringLiteral("mLdapCheckBox"));
0048     //    QVERIFY(mLdapCheckBox);
0049     //    QVERIFY(!mLdapCheckBox->isChecked());
0050 
0051     auto mLoginButton = w.findChild<QPushButton *>(QStringLiteral("mLoginButton"));
0052     QVERIFY(mLoginButton);
0053     QVERIFY(!mLoginButton->text().isEmpty());
0054 
0055     auto mBusyIndicatorWidget = w.findChild<KBusyIndicatorWidget *>(QStringLiteral("mBusyIndicatorWidget"));
0056     QVERIFY(mBusyIndicatorWidget);
0057 
0058     auto mFailedError = w.findChild<QLabel *>(QStringLiteral("mFailedError"));
0059     QVERIFY(mFailedError);
0060     QVERIFY(mFailedError->text().isEmpty());
0061     QVERIFY(mFailedError->isHidden());
0062     QFont font = mFailedError->font();
0063     QVERIFY(font.bold());
0064 
0065     auto mTwoFactorAuthenticationWidget = w.findChild<QWidget *>(QStringLiteral("mTwoFactorAuthenticationWidget"));
0066     QVERIFY(mTwoFactorAuthenticationWidget);
0067     QVERIFY(!mTwoFactorAuthenticationWidget->isVisible());
0068 
0069     auto twoFactorAuthenticationLayout = w.findChild<QVBoxLayout *>(QStringLiteral("twoFactorAuthenticationLayout"));
0070     QVERIFY(twoFactorAuthenticationLayout);
0071     QCOMPARE(twoFactorAuthenticationLayout->contentsMargins(), QMargins{});
0072 
0073     auto twoFactorAuthenticationLabel = w.findChild<QLabel *>(QStringLiteral("twoFactorAuthenticationLabel"));
0074     QVERIFY(twoFactorAuthenticationLabel);
0075     QVERIFY(!twoFactorAuthenticationLabel->text().isEmpty());
0076 
0077     auto mTwoFactorAuthenticationPasswordLineEdit = w.findChild<KPasswordLineEdit *>(QStringLiteral("mTwoFactorAuthenticationPasswordLineEdit"));
0078     QVERIFY(mTwoFactorAuthenticationPasswordLineEdit);
0079 
0080     auto sendNewEmailCode = w.findChild<QPushButton *>(QStringLiteral("sendNewEmailCode"));
0081     QVERIFY(sendNewEmailCode);
0082     QVERIFY(!sendNewEmailCode->text().isEmpty());
0083 }
0084 
0085 void RuqolaLoginWidgetTest::shouldShowLabelError()
0086 {
0087     RuqolaLoginWidget w;
0088     auto mFailedError = w.findChild<QLabel *>(QStringLiteral("mFailedError"));
0089     QVERIFY(mFailedError);
0090     w.showError(QStringLiteral("bla"));
0091 
0092     QCOMPARE(mFailedError->text(), QStringLiteral("bla"));
0093     QVERIFY(!mFailedError->isHidden());
0094 }
0095 
0096 #include "moc_ruqolaloginwidgettest.cpp"