File indexing completed on 2025-01-05 04:49:42

0001 /*
0002    SPDX-FileCopyrightText: 2015-2024 Laurent Montel <montel@kde.org>
0003 
0004    SPDX-License-Identifier: GPL-2.0-or-later
0005 */
0006 
0007 #include "enterpriseheaderstyleplugintest.h"
0008 #include "../enterpriseheaderstyleplugin/enterpriseheaderstyleinterface.h"
0009 #include "../enterpriseheaderstyleplugin/enterpriseheaderstyleplugin.h"
0010 #include "utils.h"
0011 
0012 #include <MessageViewer/HeaderStyle>
0013 
0014 #include <KActionCollection>
0015 #include <KActionMenu>
0016 #include <QActionGroup>
0017 #include <QTest>
0018 
0019 EnterpriseHeaderStylePluginTest::EnterpriseHeaderStylePluginTest(QObject *parent)
0020     : QObject(parent)
0021 {
0022 }
0023 
0024 EnterpriseHeaderStylePluginTest::~EnterpriseHeaderStylePluginTest() = default;
0025 
0026 void EnterpriseHeaderStylePluginTest::shouldHaveDefaultValue()
0027 {
0028     MessageViewer::EnterpriseHeaderStylePlugin plugin;
0029     QVERIFY(plugin.headerStyle());
0030     QVERIFY(plugin.headerStrategy());
0031 }
0032 
0033 void EnterpriseHeaderStylePluginTest::shouldCreateInterface()
0034 {
0035     MessageViewer::EnterpriseHeaderStylePlugin plugin;
0036     auto menu = new KActionMenu(this);
0037     auto act = new QActionGroup(this);
0038 
0039     MessageViewer::HeaderStyleInterface *interface = plugin.createView(menu, act, new KActionCollection(this));
0040     QVERIFY(interface);
0041     QVERIFY(!interface->action().isEmpty());
0042     delete interface;
0043 }
0044 
0045 void EnterpriseHeaderStylePluginTest::testFormatEmpty()
0046 {
0047     MessageViewer::EnterpriseHeaderStylePlugin plugin;
0048     auto style = plugin.headerStyle();
0049     auto strategy = plugin.headerStrategy();
0050     style->setHeaderStrategy(strategy);
0051     QCOMPARE(style->headerStrategy(), strategy);
0052     auto aMsg = new KMime::Message();
0053     QString closedDiv = style->format(aMsg) + QStringLiteral("</div>");
0054     testHeaderFile(closedDiv, QStringLiteral("empty.enterprise"));
0055     delete aMsg;
0056 }
0057 
0058 void EnterpriseHeaderStylePluginTest::testFormat_data()
0059 {
0060     QTest::addColumn<QString>("mailbox");
0061 
0062     QDir dir(QStringLiteral(HEADER_DATA_DIR));
0063     const auto l = dir.entryList(QStringList(QStringLiteral("*.mbox")), QDir::Files | QDir::Readable | QDir::NoSymLinks);
0064     for (const QString &file : l) {
0065         QTest::newRow(file.toLatin1().constData()) << file;
0066     }
0067 }
0068 
0069 void EnterpriseHeaderStylePluginTest::testFormat()
0070 {
0071     QFETCH(QString, mailbox);
0072 
0073     MessageViewer::EnterpriseHeaderStylePlugin plugin;
0074     auto style = plugin.headerStyle();
0075     auto strategy = plugin.headerStrategy();
0076     style->setHeaderStrategy(strategy);
0077     QCOMPARE(style->headerStrategy(), strategy);
0078     auto aMsg = readAndParseMail(mailbox);
0079     QString closedDiv = style->format(aMsg.data()) + QStringLiteral("</div>");
0080     testHeaderFile(closedDiv, mailbox + QStringLiteral(".enterprise"));
0081 }
0082 
0083 QTEST_MAIN(EnterpriseHeaderStylePluginTest)
0084 
0085 #include "moc_enterpriseheaderstyleplugintest.cpp"