File indexing completed on 2024-11-24 04:39:28

0001 /*
0002     This file is part of Contact Editor.
0003 
0004     SPDX-FileCopyrightText: 2016 eyeOS S.L.U., a Telefonica company, sales@eyeos.com
0005     SPDX-FileCopyrightText: 2016-2020 Laurent Montel <montel.org>
0006 
0007     SPDX-License-Identifier: LGPL-2.0-or-later
0008 */
0009 
0010 #include "addresslocationwidgettest.h"
0011 #include "../addresslocationwidget.h"
0012 #include "../selectaddresstypecombobox.h"
0013 #include <KLineEdit>
0014 #include <QCheckBox>
0015 #include <QComboBox>
0016 #include <QLabel>
0017 #include <QPushButton>
0018 #include <QTest>
0019 
0020 using namespace Akonadi;
0021 
0022 AddressLocationWidgetTest::AddressLocationWidgetTest(QObject *parent)
0023     : QObject(parent)
0024 {
0025 }
0026 
0027 AddressLocationWidgetTest::~AddressLocationWidgetTest() = default;
0028 
0029 void AddressLocationWidgetTest::shouldHaveDefaultValue()
0030 {
0031     AddressLocationWidget w;
0032 
0033     auto typeAddress = w.findChild<SelectAddressTypeComboBox *>(QStringLiteral("typeaddress"));
0034     QVERIFY(typeAddress);
0035 
0036     auto streetlabel = w.findChild<QLabel *>(QStringLiteral("streetlabel"));
0037     QVERIFY(streetlabel);
0038     auto mStreetEdit = w.findChild<KLineEdit *>(QStringLiteral("streetlineedit"));
0039     QVERIFY(mStreetEdit);
0040 
0041     auto postofficeboxlabel = w.findChild<QLabel *>(QStringLiteral("postofficeboxlabel"));
0042     QVERIFY(postofficeboxlabel);
0043     auto postofficeboxlineedit = w.findChild<KLineEdit *>(QStringLiteral("postofficeboxlineedit"));
0044     QVERIFY(postofficeboxlineedit);
0045 
0046     auto localitylabel = w.findChild<QLabel *>(QStringLiteral("localitylabel"));
0047     QVERIFY(localitylabel);
0048     auto localitylineedit = w.findChild<KLineEdit *>(QStringLiteral("localitylineedit"));
0049     QVERIFY(localitylineedit);
0050 
0051     auto regionlabel = w.findChild<QLabel *>(QStringLiteral("regionlabel"));
0052     QVERIFY(regionlabel);
0053     auto regionlineedit = w.findChild<KLineEdit *>(QStringLiteral("regionlineedit"));
0054     QVERIFY(regionlineedit);
0055 
0056     auto postalcodelabel = w.findChild<QLabel *>(QStringLiteral("postalcodelabel"));
0057     QVERIFY(postalcodelabel);
0058     auto postalcodelineedit = w.findChild<KLineEdit *>(QStringLiteral("postalcodelineedit"));
0059     QVERIFY(postalcodelineedit);
0060 
0061     auto countrylabel = w.findChild<QLabel *>(QStringLiteral("countrylabel"));
0062     QVERIFY(countrylabel);
0063     auto countrycombobox = w.findChild<QComboBox *>(QStringLiteral("countrycombobox"));
0064     QVERIFY(countrycombobox);
0065 
0066     auto preferredcheckbox = w.findChild<QCheckBox *>(QStringLiteral("preferredcheckbox"));
0067     QVERIFY(preferredcheckbox);
0068 
0069     auto addbuttonaddress = w.findChild<QPushButton *>(QStringLiteral("addbuttonaddress"));
0070     QVERIFY(addbuttonaddress);
0071 
0072     auto modifybuttonaddress = w.findChild<QPushButton *>(QStringLiteral("modifybuttonaddress"));
0073     QVERIFY(modifybuttonaddress);
0074 
0075     auto cancelbuttonaddress = w.findChild<QPushButton *>(QStringLiteral("cancelbuttonaddress"));
0076     QVERIFY(cancelbuttonaddress);
0077 }
0078 
0079 void AddressLocationWidgetTest::shouldChangeReadOnlyStatus()
0080 {
0081     AddressLocationWidget w;
0082 
0083     w.setReadOnly(true);
0084     auto typeAddress = w.findChild<SelectAddressTypeComboBox *>(QStringLiteral("typeaddress"));
0085     QCOMPARE(typeAddress->isEnabled(), false);
0086     auto mStreetEdit = w.findChild<KLineEdit *>(QStringLiteral("streetlineedit"));
0087     QCOMPARE(mStreetEdit->isReadOnly(), true);
0088     auto postofficeboxlineedit = w.findChild<KLineEdit *>(QStringLiteral("postofficeboxlineedit"));
0089     QCOMPARE(postofficeboxlineedit->isReadOnly(), true);
0090     auto localitylineedit = w.findChild<KLineEdit *>(QStringLiteral("localitylineedit"));
0091     QCOMPARE(localitylineedit->isReadOnly(), true);
0092     auto regionlineedit = w.findChild<KLineEdit *>(QStringLiteral("regionlineedit"));
0093     QCOMPARE(regionlineedit->isReadOnly(), true);
0094     auto postalcodelineedit = w.findChild<KLineEdit *>(QStringLiteral("postalcodelineedit"));
0095     QCOMPARE(postalcodelineedit->isReadOnly(), true);
0096     auto countrycombobox = w.findChild<QComboBox *>(QStringLiteral("countrycombobox"));
0097     QCOMPARE(countrycombobox->isEnabled(), false);
0098     auto preferredcheckbox = w.findChild<QCheckBox *>(QStringLiteral("preferredcheckbox"));
0099     QCOMPARE(preferredcheckbox->isEnabled(), false);
0100     auto addbuttonaddress = w.findChild<QPushButton *>(QStringLiteral("addbuttonaddress"));
0101     QCOMPARE(addbuttonaddress->isEnabled(), false);
0102     auto modifybuttonaddress = w.findChild<QPushButton *>(QStringLiteral("modifybuttonaddress"));
0103     QCOMPARE(modifybuttonaddress->isEnabled(), false);
0104     auto cancelbuttonaddress = w.findChild<QPushButton *>(QStringLiteral("cancelbuttonaddress"));
0105     QCOMPARE(cancelbuttonaddress->isEnabled(), false);
0106 }
0107 
0108 QTEST_MAIN(AddressLocationWidgetTest)
0109 
0110 #include "moc_addresslocationwidgettest.cpp"