File indexing completed on 2024-11-10 04:50:00
0001 /* 0002 SPDX-FileCopyrightText: 2015-2024 Laurent Montel <montel@kde.org> 0003 0004 SPDX-License-Identifier: GPL-2.0-only 0005 */ 0006 0007 #include "filteractiondeletetest.h" 0008 #include "../filteractions/filteractiondelete.h" 0009 #include <QLabel> 0010 #include <QTest> 0011 FilterActionDeleteTest::FilterActionDeleteTest(QObject *parent) 0012 : QObject(parent) 0013 { 0014 } 0015 0016 FilterActionDeleteTest::~FilterActionDeleteTest() = default; 0017 0018 void FilterActionDeleteTest::shouldHaveDefaultValue() 0019 { 0020 MailCommon::FilterActionDelete filter(nullptr); 0021 QWidget *w = filter.createParamWidget(nullptr); 0022 QVERIFY(w); 0023 0024 auto lab = dynamic_cast<QLabel *>(w); 0025 QVERIFY(lab); 0026 QCOMPARE(lab->objectName(), QStringLiteral("label_delete")); 0027 } 0028 0029 void FilterActionDeleteTest::shouldReturnSieveValue() 0030 { 0031 MailCommon::FilterActionDelete filter(nullptr); 0032 QCOMPARE(filter.sieveCode(), QStringLiteral("discard;")); 0033 } 0034 0035 void FilterActionDeleteTest::shouldBeNotEmpty() 0036 { 0037 MailCommon::FilterActionDelete filter; 0038 QVERIFY(!filter.isEmpty()); 0039 } 0040 0041 void FilterActionDeleteTest::shouldRequiresPart() 0042 { 0043 MailCommon::FilterActionDelete filter; 0044 QCOMPARE(filter.requiredPart(), MailCommon::SearchRule::Envelope); 0045 } 0046 0047 void FilterActionDeleteTest::shouldDeleteItem() 0048 { 0049 MailCommon::FilterActionDelete filter(this); 0050 KMime::Message::Ptr msgPtr = KMime::Message::Ptr(new KMime::Message()); 0051 Akonadi::Item item; 0052 item.setPayload<KMime::Message::Ptr>(msgPtr); 0053 MailCommon::ItemContext context(item, false); 0054 0055 filter.argsFromString(QString()); 0056 QCOMPARE(filter.process(context, false), MailCommon::FilterAction::GoOn); 0057 QCOMPARE(context.needsPayloadStore(), false); 0058 QCOMPARE(context.deleteItem(), true); 0059 QCOMPARE(context.needsFlagStore(), false); 0060 QCOMPARE(context.needsFullPayload(), false); 0061 } 0062 0063 QTEST_MAIN(FilterActionDeleteTest) 0064 0065 #include "moc_filteractiondeletetest.cpp"