File indexing completed on 2024-11-10 04:50:01

0001 /*
0002   SPDX-FileCopyrightText: 2015-2024 Laurent Montel <montel@kde.org>
0003 
0004   SPDX-License-Identifier: GPL-2.0-only
0005 */
0006 
0007 #include "filteractionwithaddresstest.h"
0008 #include "../filteractions/filteractionwithaddress.h"
0009 #include <Akonadi/EmailAddressRequester>
0010 #include <QTest>
0011 #include <QWidget>
0012 
0013 class TestFilterActionWithAddress : public MailCommon::FilterActionWithAddress
0014 {
0015 public:
0016     TestFilterActionWithAddress()
0017         : MailCommon::FilterActionWithAddress(QStringLiteral("foo"), QStringLiteral("bla"))
0018     {
0019     }
0020 
0021     FilterAction::ReturnCode process(MailCommon::ItemContext &, bool) const override
0022     {
0023         return GoOn;
0024     }
0025 
0026     [[nodiscard]] MailCommon::SearchRule::RequiredPart requiredPart() const override
0027     {
0028         return MailCommon::SearchRule::CompleteMessage;
0029     }
0030 };
0031 
0032 FilterActionWithAddressTest::FilterActionWithAddressTest(QObject *parent)
0033     : QObject(parent)
0034 {
0035 }
0036 
0037 FilterActionWithAddressTest::~FilterActionWithAddressTest() = default;
0038 
0039 void FilterActionWithAddressTest::shouldHaveDefaultValue()
0040 {
0041     TestFilterActionWithAddress filter;
0042     QWidget *w = filter.createParamWidget(nullptr);
0043     QCOMPARE(w->objectName(), QStringLiteral("emailaddressrequester"));
0044     auto requester = dynamic_cast<Akonadi::EmailAddressRequester *>(w);
0045     QVERIFY(requester);
0046     QVERIFY(filter.isEmpty());
0047 }
0048 
0049 void FilterActionWithAddressTest::shouldAssignValue()
0050 {
0051     TestFilterActionWithAddress filter;
0052     QWidget *w = filter.createParamWidget(nullptr);
0053     auto requester = dynamic_cast<Akonadi::EmailAddressRequester *>(w);
0054     filter.argsFromString(QStringLiteral("foo"));
0055     filter.setParamWidgetValue(w);
0056     QVERIFY(!filter.isEmpty());
0057     QVERIFY(!requester->text().isEmpty());
0058 }
0059 
0060 void FilterActionWithAddressTest::shouldRequiresPart()
0061 {
0062     TestFilterActionWithAddress filter;
0063     QCOMPARE(filter.requiredPart(), MailCommon::SearchRule::CompleteMessage);
0064 }
0065 
0066 QTEST_MAIN(FilterActionWithAddressTest)
0067 
0068 #include "moc_filteractionwithaddresstest.cpp"