File indexing completed on 2024-11-24 04:39:29
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 "customfieldeditorwidgettest.h" 0011 #include "../customfieldeditorwidget.h" 0012 #include <KLineEdit> 0013 #include <QComboBox> 0014 #include <QLabel> 0015 #include <QPushButton> 0016 #include <QTest> 0017 0018 CustomFieldEditorWidgetTest::CustomFieldEditorWidgetTest(QObject *parent) 0019 : QObject(parent) 0020 { 0021 } 0022 0023 CustomFieldEditorWidgetTest::~CustomFieldEditorWidgetTest() = default; 0024 0025 void CustomFieldEditorWidgetTest::shouldHaveDefaultValue() 0026 { 0027 Akonadi::CustomFieldEditorWidget w; 0028 auto fieldname = w.findChild<KLineEdit *>(QStringLiteral("fieldname")); 0029 QVERIFY(fieldname); 0030 QVERIFY(fieldname->text().isEmpty()); 0031 QVERIFY(fieldname->trapReturnKey()); 0032 0033 auto label = w.findChild<QLabel *>(QStringLiteral("labeltitle")); 0034 QVERIFY(label); 0035 auto addfield = w.findChild<QPushButton *>(QStringLiteral("addfield")); 0036 QVERIFY(addfield); 0037 QVERIFY(!addfield->isEnabled()); 0038 0039 auto combobox = w.findChild<QComboBox *>(QStringLiteral("fieldtype")); 0040 QVERIFY(combobox); 0041 QVERIFY(combobox->count() > 0); 0042 QCOMPARE(combobox->currentIndex(), 0); 0043 } 0044 0045 void CustomFieldEditorWidgetTest::shouldEnableAddButtonWhenTextIsNotEmpty() 0046 { 0047 Akonadi::CustomFieldEditorWidget w; 0048 auto fieldname = w.findChild<QLineEdit *>(QStringLiteral("fieldname")); 0049 QVERIFY(fieldname->text().isEmpty()); 0050 auto addfield = w.findChild<QPushButton *>(QStringLiteral("addfield")); 0051 QVERIFY(!addfield->isEnabled()); 0052 0053 fieldname->setText(QStringLiteral("foo")); 0054 QVERIFY(addfield->isEnabled()); 0055 fieldname->clear(); 0056 QVERIFY(!addfield->isEnabled()); 0057 } 0058 0059 void CustomFieldEditorWidgetTest::shouldClearEditorWhenPressAdd() 0060 { 0061 Akonadi::CustomFieldEditorWidget w; 0062 auto fieldname = w.findChild<QLineEdit *>(QStringLiteral("fieldname")); 0063 auto addfield = w.findChild<QPushButton *>(QStringLiteral("addfield")); 0064 auto combobox = w.findChild<QComboBox *>(QStringLiteral("fieldtype")); 0065 combobox->setCurrentIndex(1); 0066 fieldname->setText(QStringLiteral("foo")); 0067 QTest::mouseClick(addfield, Qt::LeftButton); 0068 QVERIFY(fieldname->text().isEmpty()); 0069 QVERIFY(!addfield->isEnabled()); 0070 QCOMPARE(combobox->currentIndex(), 0); 0071 } 0072 0073 QTEST_MAIN(CustomFieldEditorWidgetTest) 0074 0075 #include "moc_customfieldeditorwidgettest.cpp"