File indexing completed on 2024-05-26 05:22:05

0001 /*
0002   SPDX-FileCopyrightText: 2014-2024 Laurent Montel <montel@kde.org>
0003 
0004   SPDX-License-Identifier: GPL-2.0-only
0005 */
0006 
0007 #include "identityaddvcarddialogtest.h"
0008 #include "../identity/identityaddvcarddialog.h"
0009 
0010 #include <KUrlRequester>
0011 #include <QButtonGroup>
0012 #include <QComboBox>
0013 
0014 #include <QTest>
0015 
0016 identityaddvcarddialogtest::identityaddvcarddialogtest(QObject *parent)
0017     : QObject(parent)
0018 {
0019 }
0020 
0021 void identityaddvcarddialogtest::shouldHaveDefaultValue()
0022 {
0023     IdentityAddVcardDialog dlg(QStringList(), nullptr);
0024     auto identityComboBox = dlg.findChild<QComboBox *>(QStringLiteral("identity_combobox"));
0025     QVERIFY(identityComboBox);
0026     QCOMPARE(identityComboBox->isEnabled(), false);
0027 
0028     auto urlRequester = dlg.findChild<KUrlRequester *>(QStringLiteral("kurlrequester_vcardpath"));
0029     QVERIFY(urlRequester);
0030     QCOMPARE(urlRequester->isEnabled(), false);
0031 
0032     auto buttonGroup = dlg.findChild<QButtonGroup *>(QStringLiteral("buttongroup"));
0033     QVERIFY(buttonGroup);
0034     QCOMPARE(dlg.duplicateMode(), IdentityAddVcardDialog::Empty);
0035 
0036     QVERIFY(buttonGroup->button(IdentityAddVcardDialog::Empty));
0037     QVERIFY(buttonGroup->button(IdentityAddVcardDialog::ExistingEntry));
0038     QVERIFY(buttonGroup->button(IdentityAddVcardDialog::FromExistingVCard));
0039 }
0040 
0041 void identityaddvcarddialogtest::shouldEnabledUrlRequesterWhenSelectFromExistingVCard()
0042 {
0043     IdentityAddVcardDialog dlg(QStringList(), nullptr);
0044     auto buttonGroup = dlg.findChild<QButtonGroup *>(QStringLiteral("buttongroup"));
0045     buttonGroup->button(IdentityAddVcardDialog::FromExistingVCard)->toggle();
0046     QCOMPARE(dlg.duplicateMode(), IdentityAddVcardDialog::FromExistingVCard);
0047 
0048     auto identityComboBox = dlg.findChild<QComboBox *>(QStringLiteral("identity_combobox"));
0049     QCOMPARE(identityComboBox->isEnabled(), false);
0050 
0051     auto urlRequester = dlg.findChild<KUrlRequester *>(QStringLiteral("kurlrequester_vcardpath"));
0052     QCOMPARE(urlRequester->isEnabled(), true);
0053 }
0054 
0055 void identityaddvcarddialogtest::shouldEnabledComboboxWhenSelectDuplicateVCard()
0056 {
0057     IdentityAddVcardDialog dlg(QStringList(), nullptr);
0058     auto buttonGroup = dlg.findChild<QButtonGroup *>(QStringLiteral("buttongroup"));
0059     buttonGroup->button(IdentityAddVcardDialog::ExistingEntry)->toggle();
0060     QCOMPARE(dlg.duplicateMode(), IdentityAddVcardDialog::ExistingEntry);
0061 
0062     auto identityComboBox = dlg.findChild<QComboBox *>(QStringLiteral("identity_combobox"));
0063     QCOMPARE(identityComboBox->isEnabled(), true);
0064 
0065     auto urlRequester = dlg.findChild<KUrlRequester *>(QStringLiteral("kurlrequester_vcardpath"));
0066     QCOMPARE(urlRequester->isEnabled(), false);
0067 }
0068 
0069 void identityaddvcarddialogtest::shouldEnabledComboboxWhenSelectFromExistingVCardAndAfterDuplicateVCard()
0070 {
0071     IdentityAddVcardDialog dlg(QStringList(), nullptr);
0072     auto buttonGroup = dlg.findChild<QButtonGroup *>(QStringLiteral("buttongroup"));
0073     buttonGroup->button(IdentityAddVcardDialog::FromExistingVCard)->toggle();
0074     QCOMPARE(dlg.duplicateMode(), IdentityAddVcardDialog::FromExistingVCard);
0075 
0076     auto identityComboBox = dlg.findChild<QComboBox *>(QStringLiteral("identity_combobox"));
0077 
0078     auto urlRequester = dlg.findChild<KUrlRequester *>(QStringLiteral("kurlrequester_vcardpath"));
0079 
0080     buttonGroup->button(IdentityAddVcardDialog::ExistingEntry)->toggle();
0081     QCOMPARE(dlg.duplicateMode(), IdentityAddVcardDialog::ExistingEntry);
0082     QCOMPARE(identityComboBox->isEnabled(), true);
0083     QCOMPARE(urlRequester->isEnabled(), false);
0084 }
0085 
0086 QTEST_MAIN(identityaddvcarddialogtest)
0087 
0088 #include "moc_identityaddvcarddialogtest.cpp"