File indexing completed on 2025-01-05 04:58:20

0001 /*
0002   SPDX-FileCopyrightText: 2015-2024 Laurent Montel <montel@kde.org>
0003 
0004   SPDX-License-Identifier: LGPL-2.0-or-later
0005 
0006 */
0007 
0008 #include "blacklistbalooemailcompletionwidgettest.h"
0009 #include "../blacklistbalooemailcompletionwidget.h"
0010 #include "../blacklistbalooemaillist.h"
0011 #include "addressline/blacklistbaloocompletion/blacklistbalooemailwarning.h"
0012 #include <KListWidgetSearchLine>
0013 #include <QLabel>
0014 #include <QLineEdit>
0015 #include <QPushButton>
0016 #include <QTest>
0017 
0018 BlackListBalooEmailCompletionWidgetTest::BlackListBalooEmailCompletionWidgetTest(QObject *parent)
0019     : QObject(parent)
0020 {
0021 }
0022 
0023 BlackListBalooEmailCompletionWidgetTest::~BlackListBalooEmailCompletionWidgetTest() = default;
0024 
0025 void BlackListBalooEmailCompletionWidgetTest::shouldHaveDefaultValue()
0026 {
0027     PimCommon::BlackListBalooEmailCompletionWidget widget;
0028     widget.show();
0029     QVERIFY(QTest::qWaitForWindowExposed(&widget));
0030     auto searchLabel = widget.findChild<QLabel *>(QStringLiteral("search_label"));
0031     QVERIFY(searchLabel);
0032 
0033     auto searchLineEdit = widget.findChild<QLineEdit *>(QStringLiteral("search_lineedit"));
0034     QVERIFY(searchLineEdit);
0035     QVERIFY(searchLineEdit->isClearButtonEnabled());
0036     QVERIFY(searchLineEdit->text().isEmpty());
0037 
0038     auto seachButton = widget.findChild<QPushButton *>(QStringLiteral("search_button"));
0039     QVERIFY(seachButton);
0040     QVERIFY(!seachButton->isEnabled());
0041 
0042     auto moreResult = widget.findChild<QLabel *>(QStringLiteral("moreresultlabel"));
0043     QVERIFY(moreResult);
0044     QVERIFY(!moreResult->isVisible());
0045 
0046     auto mNumberOfEmailsFound = widget.findChild<QLabel *>(QStringLiteral("numberofemailsfound"));
0047     QVERIFY(mNumberOfEmailsFound);
0048     QVERIFY(mNumberOfEmailsFound->text().isEmpty());
0049 
0050     auto showAllBlackListedEmails = widget.findChild<QPushButton *>(QStringLiteral("show_blacklisted_email_button"));
0051     QVERIFY(showAllBlackListedEmails);
0052 
0053     auto emailList = widget.findChild<PimCommon::BlackListBalooEmailList *>(QStringLiteral("email_list"));
0054     QVERIFY(emailList);
0055 
0056     auto selectButton = widget.findChild<QPushButton *>(QStringLiteral("select_email"));
0057     QVERIFY(selectButton);
0058     QVERIFY(!selectButton->isEnabled());
0059     auto unselectButton = widget.findChild<QPushButton *>(QStringLiteral("unselect_email"));
0060     QVERIFY(unselectButton);
0061     QVERIFY(!unselectButton->isEnabled());
0062 
0063     auto excludeDomainLabel = widget.findChild<QLabel *>(QStringLiteral("domain_label"));
0064     QVERIFY(excludeDomainLabel);
0065 
0066     auto excludeDomainLineEdit = widget.findChild<QLineEdit *>(QStringLiteral("domain_lineedit"));
0067     QVERIFY(excludeDomainLineEdit);
0068     QVERIFY(excludeDomainLineEdit->text().isEmpty());
0069     QVERIFY(excludeDomainLineEdit->isClearButtonEnabled());
0070     QVERIFY(!excludeDomainLineEdit->placeholderText().isEmpty());
0071 
0072     auto searchInResult = widget.findChild<KListWidgetSearchLine *>(QStringLiteral("searchinresultlineedit"));
0073     QVERIFY(searchInResult);
0074     QVERIFY(!searchInResult->placeholderText().isEmpty());
0075     QVERIFY(searchInResult->text().isEmpty());
0076     QVERIFY(searchInResult->isClearButtonEnabled());
0077 
0078     auto blackListWarning = widget.findChild<PimCommon::BlackListBalooEmailWarning *>(QStringLiteral("backlistwarning"));
0079     QVERIFY(blackListWarning);
0080 }
0081 
0082 void BlackListBalooEmailCompletionWidgetTest::shouldEnablePushButtonWhenTestSizeSupperiorToTwo()
0083 {
0084     PimCommon::BlackListBalooEmailCompletionWidget widget;
0085     auto searchLineEdit = widget.findChild<QLineEdit *>(QStringLiteral("search_lineedit"));
0086     auto seachButton = widget.findChild<QPushButton *>(QStringLiteral("search_button"));
0087     QVERIFY(!seachButton->isEnabled());
0088     searchLineEdit->setText(QStringLiteral("fo"));
0089     QVERIFY(!seachButton->isEnabled());
0090     searchLineEdit->setText(QStringLiteral("foo"));
0091     QVERIFY(seachButton->isEnabled());
0092 
0093     searchLineEdit->setText(QStringLiteral("o  "));
0094     QVERIFY(!seachButton->isEnabled());
0095     searchLineEdit->setText(QStringLiteral(" o "));
0096     QVERIFY(!seachButton->isEnabled());
0097 }
0098 
0099 void BlackListBalooEmailCompletionWidgetTest::shouldChangeEnableSelectUnSelectButton()
0100 {
0101     PimCommon::BlackListBalooEmailCompletionWidget widget;
0102 
0103     auto selectButton = widget.findChild<QPushButton *>(QStringLiteral("select_email"));
0104     QVERIFY(!selectButton->isEnabled());
0105 
0106     auto unselectButton = widget.findChild<QPushButton *>(QStringLiteral("unselect_email"));
0107     QVERIFY(!unselectButton->isEnabled());
0108 
0109     auto emailList = widget.findChild<PimCommon::BlackListBalooEmailList *>(QStringLiteral("email_list"));
0110     QVERIFY((emailList->setEmailFound(QStringList() << QStringLiteral("foo") << QStringLiteral("bla") << QStringLiteral("bli")) > 0));
0111 
0112     emailList->selectAll();
0113     QVERIFY(unselectButton->isEnabled());
0114     QVERIFY(selectButton->isEnabled());
0115 
0116     emailList->clearSelection();
0117     QVERIFY(!unselectButton->isEnabled());
0118     QVERIFY(!selectButton->isEnabled());
0119 }
0120 
0121 QTEST_MAIN(BlackListBalooEmailCompletionWidgetTest)
0122 
0123 #include "moc_blacklistbalooemailcompletionwidgettest.cpp"