File indexing completed on 2024-11-24 04:43:02
0001 /* 0002 SPDX-FileCopyrightText: 2015-2024 Laurent Montel <montel@kde.org> 0003 0004 SPDX-License-Identifier: GPL-2.0-or-later 0005 */ 0006 0007 #include "mergecontactsdialogtest.h" 0008 #include "manualmerge/mergecontactsdialog.h" 0009 0010 #include <QStackedWidget> 0011 #include <QTest> 0012 0013 #include <QDialogButtonBox> 0014 #include <QStandardPaths> 0015 0016 MergeContactsDialogTest::MergeContactsDialogTest(QObject *parent) 0017 : QObject(parent) 0018 { 0019 } 0020 0021 MergeContactsDialogTest::~MergeContactsDialogTest() = default; 0022 0023 void MergeContactsDialogTest::initTestCase() 0024 { 0025 QStandardPaths::setTestModeEnabled(true); 0026 } 0027 0028 void MergeContactsDialogTest::shouldHaveDefaultValue() 0029 { 0030 KABMergeContacts::MergeContactsDialog dlg; 0031 dlg.show(); 0032 0033 auto buttonBox = dlg.findChild<QDialogButtonBox *>(QStringLiteral("buttonbox")); 0034 QVERIFY(buttonBox); 0035 0036 auto stackedWidget = dlg.findChild<QStackedWidget *>(QStringLiteral("stackedwidget")); 0037 QVERIFY(stackedWidget); 0038 QCOMPARE(stackedWidget->currentWidget()->objectName(), QStringLiteral("nocontactselected")); 0039 0040 for (int i = 0; i < stackedWidget->count(); ++i) { 0041 QWidget *w = stackedWidget->widget(i); 0042 const QString objName = w->objectName(); 0043 const bool hasGoodNamePage = (objName == QLatin1StringView("notenoughcontactselected") || objName == QLatin1StringView("nocontactselected") 0044 || objName == QLatin1StringView("manualmergeresultwidget") || objName == QLatin1StringView("selectioninformation") 0045 || objName == QLatin1StringView("mergecontactinfowidget")); 0046 QVERIFY(hasGoodNamePage); 0047 } 0048 } 0049 0050 void MergeContactsDialogTest::shouldSwithStackedWidget() 0051 { 0052 KABMergeContacts::MergeContactsDialog dlg; 0053 dlg.show(); 0054 auto stackedWidget = dlg.findChild<QStackedWidget *>(QStringLiteral("stackedwidget")); 0055 Akonadi::Item::List lst; 0056 // Empty 0057 dlg.setContacts(lst); 0058 QCOMPARE(stackedWidget->currentWidget()->objectName(), QStringLiteral("nocontactselected")); 0059 lst << Akonadi::Item(42); 0060 // 1 element 0061 dlg.setContacts(lst); 0062 QCOMPARE(stackedWidget->currentWidget()->objectName(), QStringLiteral("notenoughcontactselected")); 0063 lst.clear(); 0064 // 1 element 0065 lst << Akonadi::Item(42); 0066 dlg.setContacts(lst); 0067 QCOMPARE(stackedWidget->currentWidget()->objectName(), QStringLiteral("notenoughcontactselected")); 0068 // 2 elements 0069 lst.clear(); 0070 lst << Akonadi::Item(42) << Akonadi::Item(42); 0071 dlg.setContacts(lst); 0072 QCOMPARE(stackedWidget->currentWidget()->objectName(), QStringLiteral("manualmergeresultwidget")); 0073 } 0074 0075 QTEST_MAIN(MergeContactsDialogTest) 0076 0077 #include "moc_mergecontactsdialogtest.cpp"