File indexing completed on 2025-03-09 04:46:44
0001 /* 0002 SPDX-FileCopyrightText: 2016-2024 Laurent Montel <montel@kde.org> 0003 0004 SPDX-License-Identifier: GPL-2.0-or-later 0005 */ 0006 0007 #include "automaticaddcontactstabwidgettest.h" 0008 #include "../automaticaddcontactstabwidget.h" 0009 #include <Akonadi/CollectionComboBox> 0010 #include <Akonadi/EntityTreeModel> 0011 #include <KContacts/Addressee> 0012 #include <QCheckBox> 0013 #include <QLabel> 0014 #include <QStandardItemModel> 0015 #include <QStandardPaths> 0016 #include <QTest> 0017 #include <QVBoxLayout> 0018 0019 AutomaticAddContactsTabWidgetTest::AutomaticAddContactsTabWidgetTest(QObject *parent) 0020 : QObject(parent) 0021 { 0022 QStandardPaths::setTestModeEnabled(true); 0023 mComboboxModel = new QStandardItemModel; 0024 for (int id = 42; id < 51; ++id) { 0025 Akonadi::Collection collection(id); 0026 collection.setRights(Akonadi::Collection::AllRights); 0027 collection.setName(QString::number(id)); 0028 collection.setContentMimeTypes(QStringList() << KContacts::Addressee::mimeType()); 0029 0030 auto item = new QStandardItem(collection.name()); 0031 item->setData(QVariant::fromValue(collection), Akonadi::EntityTreeModel::CollectionRole); 0032 item->setData(QVariant::fromValue(collection.id()), Akonadi::EntityTreeModel::CollectionIdRole); 0033 0034 mComboboxModel->appendRow(item); 0035 } 0036 } 0037 0038 AutomaticAddContactsTabWidgetTest::~AutomaticAddContactsTabWidgetTest() = default; 0039 0040 AutomaticAddContactsTabWidget *AutomaticAddContactsTabWidgetTest::createContactWidget() 0041 { 0042 auto w = new AutomaticAddContactsTabWidget(nullptr, mComboboxModel); 0043 return w; 0044 } 0045 0046 void AutomaticAddContactsTabWidgetTest::shouldHaveDefaultValue() 0047 { 0048 auto w = new AutomaticAddContactsTabWidget(createContactWidget()); 0049 auto vboxlayout = w->findChild<QVBoxLayout *>(QStringLiteral("mainlayout")); 0050 QVERIFY(vboxlayout); 0051 0052 auto mEnabled = w->findChild<QCheckBox *>(QStringLiteral("enabled")); 0053 QVERIFY(mEnabled); 0054 QVERIFY(!mEnabled->text().isEmpty()); 0055 QVERIFY(!mEnabled->isChecked()); 0056 0057 auto hlay = w->findChild<QHBoxLayout *>(QStringLiteral("folderlayout")); 0058 QVERIFY(hlay); 0059 QCOMPARE(hlay->contentsMargins(), QMargins()); 0060 0061 auto lab = w->findChild<QLabel *>(QStringLiteral("labelfolder")); 0062 QVERIFY(lab); 0063 QVERIFY(!lab->text().isEmpty()); 0064 0065 auto mCollectionCombobox = w->findChild<Akonadi::CollectionComboBox *>(QStringLiteral("akonadicombobox")); 0066 QVERIFY(mCollectionCombobox); 0067 delete w; 0068 } 0069 0070 void AutomaticAddContactsTabWidgetTest::shouldResetValue() 0071 { 0072 auto w = new AutomaticAddContactsTabWidget(createContactWidget()); 0073 auto mEnabled = w->findChild<QCheckBox *>(QStringLiteral("enabled")); 0074 QVERIFY(!mEnabled->isChecked()); 0075 mEnabled->setChecked(true); 0076 QVERIFY(mEnabled->isChecked()); 0077 0078 w->resetSettings(); 0079 QVERIFY(!mEnabled->isChecked()); 0080 delete w; 0081 } 0082 0083 QTEST_MAIN(AutomaticAddContactsTabWidgetTest) 0084 0085 #include "moc_automaticaddcontactstabwidgettest.cpp"