File indexing completed on 2024-12-22 05:05:18

0001 // SPDX-FileCopyrightText: 2023 g10 Code GmbH
0002 // SPDX-FileContributor: Carl Schwan <carl@carlschwan.eu>
0003 // SPDX-License-Identifier: LGPL-2.0-or-later
0004 
0005 #include "../../src/widgets/messagecontainerwidget_p.h"
0006 #include <KMessageWidget>
0007 #include <MimeTreeParserCore/FileOpener>
0008 #include <MimeTreeParserWidgets/MessageViewer>
0009 #include <QTest>
0010 #include <QVBoxLayout>
0011 
0012 using namespace MimeTreeParser::Widgets;
0013 
0014 class MessageViewerTest : public QObject
0015 {
0016     Q_OBJECT
0017 
0018 private Q_SLOTS:
0019 
0020     void messageViewerSMimeEncrypted()
0021     {
0022         auto messages =
0023             MimeTreeParser::Core::FileOpener::openFile(QLatin1StringView(MAIL_DATA_DIR) + QLatin1Char('/') + QLatin1StringView("smime-encrypted.mbox"));
0024         QCOMPARE(messages.count(), 1);
0025         MessageViewer viewer;
0026         viewer.setMessage(messages[0]);
0027 
0028         auto layout = viewer.findChild<QVBoxLayout *>(QStringLiteral("PartLayout"));
0029         QVERIFY(layout);
0030 
0031         QCOMPARE(layout->count(), 2);
0032         auto container = qobject_cast<MessageWidgetContainer *>(layout->itemAt(0)->widget());
0033         QVERIFY(container);
0034 
0035         auto encryptionMessage = container->findChild<KMessageWidget *>(QStringLiteral("EncryptionMessage"));
0036         QCOMPARE(encryptionMessage->messageType(), KMessageWidget::Positive);
0037         QCOMPARE(encryptionMessage->text(), QStringLiteral("This message is encrypted. <a href=\"messageviewer:showDetails\">Details</a>"));
0038 
0039         encryptionMessage->linkActivated(QStringLiteral("messageviewer:showDetails"));
0040 
0041         QCOMPARE(encryptionMessage->text(),
0042                  QStringLiteral("This message is encrypted. The message is encrypted for the following certificates:<ul><li>unittest cert - KDAB (<a "
0043                                 "href=\"messageviewer:showCertificate#gpgsm ### SMIME ### 4CC658E3212B49DC\">4CC6 58E3 212B 49DC</a>)</li></ul>"));
0044 
0045         auto signatureMessage = container->findChild<KMessageWidget *>(QStringLiteral("SignatureMessage"));
0046         QVERIFY(!signatureMessage);
0047     }
0048 };
0049 
0050 QTEST_MAIN(MessageViewerTest)
0051 #include "messageviewertest.moc"