File indexing completed on 2024-11-10 04:49:59

0001 /*
0002   SPDX-FileCopyrightText: 2015-2024 Laurent Montel <montel@kde.org>
0003 
0004   SPDX-License-Identifier: GPL-2.0-only
0005 */
0006 
0007 #include "filteractionaddtoaddressbooktest.h"
0008 #include "../filteractions/filteractionaddtoaddressbook.h"
0009 #include <QComboBox>
0010 #include <QLabel>
0011 #include <QTest>
0012 #include <QWidget>
0013 
0014 #include <Akonadi/CollectionComboBox>
0015 #include <Akonadi/TagWidget>
0016 
0017 FilterActionAddToAddressBookTest::FilterActionAddToAddressBookTest(QObject *parent)
0018     : QObject(parent)
0019 {
0020 }
0021 
0022 FilterActionAddToAddressBookTest::~FilterActionAddToAddressBookTest() = default;
0023 
0024 void FilterActionAddToAddressBookTest::shouldHaveDefaultValue()
0025 {
0026     MailCommon::FilterActionAddToAddressBook filter;
0027     QWidget *w = filter.createParamWidget(nullptr);
0028 
0029     auto headerCombo = w->findChild<QComboBox *>(QStringLiteral("HeaderComboBox"));
0030     QVERIFY(headerCombo);
0031 
0032     auto label = w->findChild<QLabel *>(QStringLiteral("label_with_category"));
0033     QVERIFY(label);
0034 
0035     auto categoryEdit = w->findChild<Akonadi::TagWidget *>(QStringLiteral("CategoryEdit"));
0036     QVERIFY(categoryEdit);
0037 
0038     label = w->findChild<QLabel *>(QStringLiteral("label_in_addressbook"));
0039     QVERIFY(label);
0040 
0041     auto collectionComboBox = w->findChild<Akonadi::CollectionComboBox *>(QStringLiteral("AddressBookComboBox"));
0042     QVERIFY(collectionComboBox);
0043 }
0044 
0045 void FilterActionAddToAddressBookTest::shouldReportErrorWhenArgumentIsEmpty()
0046 {
0047     MailCommon::FilterActionAddToAddressBook filter;
0048     KMime::Message::Ptr msgPtr = KMime::Message::Ptr(new KMime::Message());
0049     Akonadi::Item item;
0050     item.setPayload<KMime::Message::Ptr>(msgPtr);
0051     MailCommon::ItemContext context(item, false);
0052 
0053     filter.argsFromString(QString());
0054     QVERIFY(filter.isEmpty());
0055     QCOMPARE(filter.process(context, false), MailCommon::FilterAction::ErrorButGoOn);
0056     QCOMPARE(context.needsPayloadStore(), false);
0057     QCOMPARE(context.needsFlagStore(), false);
0058     QCOMPARE(context.needsFullPayload(), false);
0059 }
0060 
0061 void FilterActionAddToAddressBookTest::shouldReportErrorWhenCollectionIsInvalid()
0062 {
0063     MailCommon::FilterActionAddToAddressBook filter;
0064     KMime::Message::Ptr msgPtr = KMime::Message::Ptr(new KMime::Message());
0065     Akonadi::Item item;
0066     item.setPayload<KMime::Message::Ptr>(msgPtr);
0067     MailCommon::ItemContext context(item, false);
0068 
0069     filter.argsFromString(QStringLiteral("foo\t-1\tddd"));
0070     QVERIFY(filter.isEmpty());
0071     QCOMPARE(filter.process(context, false), MailCommon::FilterAction::ErrorButGoOn);
0072     QCOMPARE(context.needsPayloadStore(), false);
0073     QCOMPARE(context.needsFlagStore(), false);
0074     QCOMPARE(context.needsFullPayload(), false);
0075 }
0076 
0077 void FilterActionAddToAddressBookTest::shouldRequiresPart()
0078 {
0079     MailCommon::FilterActionAddToAddressBook filter;
0080     QCOMPARE(filter.requiredPart(), MailCommon::SearchRule::Envelope);
0081 }
0082 
0083 QTEST_MAIN(FilterActionAddToAddressBookTest)
0084 
0085 #include "moc_filteractionaddtoaddressbooktest.cpp"