File indexing completed on 2024-11-24 04:43:03

0001 /*
0002    SPDX-FileCopyrightText: 2014-2024 Laurent Montel <montel@kde.org>
0003 
0004    SPDX-License-Identifier: GPL-2.0-or-later
0005 */
0006 
0007 #include "searchandmergecontactduplicatecontactdialogtest.h"
0008 
0009 #include "../searchduplicate/searchandmergecontactduplicatecontactdialog.h"
0010 
0011 #include <QStandardPaths>
0012 #include <QTest>
0013 
0014 #include <QStackedWidget>
0015 using namespace KABMergeContacts;
0016 
0017 SearchAndMergeContactDuplicateContactDialogTest::SearchAndMergeContactDuplicateContactDialogTest(QObject *parent)
0018     : QObject(parent)
0019 {
0020 }
0021 
0022 void SearchAndMergeContactDuplicateContactDialogTest::initTestCase()
0023 {
0024     QStandardPaths::setTestModeEnabled(true);
0025 }
0026 
0027 void SearchAndMergeContactDuplicateContactDialogTest::shouldHaveDefaultValueOnCreation()
0028 {
0029     SearchAndMergeContactDuplicateContactDialog dlg;
0030     dlg.show();
0031     auto stackedWidget = dlg.findChild<QStackedWidget *>(QStringLiteral("stackedwidget"));
0032     QVERIFY(stackedWidget);
0033     QCOMPARE(stackedWidget->currentWidget()->objectName(), QStringLiteral("nocontactselected"));
0034 
0035     for (int i = 0; i < stackedWidget->count(); ++i) {
0036         QWidget *w = stackedWidget->widget(i);
0037         const QString objName = w->objectName();
0038         const bool hasGoodNamePage = (objName == QLatin1StringView("mergecontact") || objName == QLatin1StringView("nocontactselected")
0039                                       || objName == QLatin1StringView("nocontactduplicatesfound") || objName == QLatin1StringView("noenoughcontactselected")
0040                                       || objName == QLatin1StringView("mergecontactresult") || objName == QLatin1StringView("selectioninformation"));
0041         QVERIFY(hasGoodNamePage);
0042     }
0043 }
0044 
0045 void SearchAndMergeContactDuplicateContactDialogTest::shouldShowNoEnoughPageWhenSelectOneContact()
0046 {
0047     SearchAndMergeContactDuplicateContactDialog dlg;
0048     Akonadi::Item::List lst;
0049     lst << Akonadi::Item(42);
0050     dlg.searchPotentialDuplicateContacts(lst);
0051     dlg.show();
0052     auto stackedWidget = dlg.findChild<QStackedWidget *>(QStringLiteral("stackedwidget"));
0053     QVERIFY(stackedWidget);
0054     QCOMPARE(stackedWidget->currentWidget()->objectName(), QStringLiteral("noenoughcontactselected"));
0055 }
0056 
0057 void SearchAndMergeContactDuplicateContactDialogTest::shouldShowNoContactWhenListIsEmpty()
0058 {
0059     SearchAndMergeContactDuplicateContactDialog dlg;
0060     Akonadi::Item::List lst;
0061     dlg.searchPotentialDuplicateContacts(lst);
0062     dlg.show();
0063     auto stackedWidget = dlg.findChild<QStackedWidget *>(QStringLiteral("stackedwidget"));
0064     QVERIFY(stackedWidget);
0065     QCOMPARE(stackedWidget->currentWidget()->objectName(), QStringLiteral("nocontactselected"));
0066 }
0067 
0068 QTEST_MAIN(SearchAndMergeContactDuplicateContactDialogTest)
0069 
0070 #include "moc_searchandmergecontactduplicatecontactdialogtest.cpp"