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

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 "passwordconfirmwidgettest.h"
0008 #include "misc/passwordconfirmwidget.h"
0009 #include <KPasswordLineEdit>
0010 #include <QFormLayout>
0011 #include <QTest>
0012 QTEST_MAIN(PasswordConfirmWidgetTest)
0013 PasswordConfirmWidgetTest::PasswordConfirmWidgetTest(QObject *parent)
0014     : QObject(parent)
0015 {
0016 }
0017 
0018 void PasswordConfirmWidgetTest::shouldHaveDefaultValues()
0019 {
0020     PasswordConfirmWidget w;
0021 
0022     auto mainLayout = w.findChild<QFormLayout *>(QStringLiteral("mainLayout"));
0023     QVERIFY(mainLayout);
0024     QCOMPARE(mainLayout->contentsMargins(), QMargins{});
0025 
0026     auto mNewPasswordLineEdit = w.findChild<KPasswordLineEdit *>(QStringLiteral("mNewPasswordLineEdit"));
0027     QVERIFY(mNewPasswordLineEdit);
0028 
0029     auto mConfirmPasswordLineEdit = w.findChild<KPasswordLineEdit *>(QStringLiteral("mConfirmPasswordLineEdit"));
0030     QVERIFY(mConfirmPasswordLineEdit);
0031 
0032     QVERIFY(!w.isNewPasswordConfirmed());
0033 }
0034 
0035 void PasswordConfirmWidgetTest::shouldReturnNewPassword()
0036 {
0037     PasswordConfirmWidget w;
0038     auto mNewPasswordLineEdit = w.findChild<KPasswordLineEdit *>(QStringLiteral("mNewPasswordLineEdit"));
0039 
0040     auto mConfirmPasswordLineEdit = w.findChild<KPasswordLineEdit *>(QStringLiteral("mConfirmPasswordLineEdit"));
0041     QVERIFY(!w.isNewPasswordConfirmed());
0042     mNewPasswordLineEdit->setPassword(QStringLiteral("bla"));
0043     // mConfirmPasswordLineEdit is Empty => not a new password
0044     QVERIFY(!w.isNewPasswordConfirmed());
0045 
0046     mConfirmPasswordLineEdit->setPassword(QStringLiteral("bli"));
0047     QVERIFY(!w.isNewPasswordConfirmed());
0048 
0049     mConfirmPasswordLineEdit->setPassword(QStringLiteral("bla"));
0050     QVERIFY(w.isNewPasswordConfirmed());
0051 }
0052 
0053 #include "moc_passwordconfirmwidgettest.cpp"