Commit 0988f456 authored by Sandro Knauß's avatar Sandro Knauß 🐝 Committed by Laurent Montel
Browse files

Add more tests for ComposerViewBase

parent 17f8c44c
Pipeline #88076 passed with stage
in 44 minutes and 29 seconds
......@@ -11,7 +11,9 @@ macro( add_messagecomposer_test _source )
ecm_add_test(${ARGV}
TEST_NAME ${_name}
NAME_PREFIX "messagecomposer-"
LINK_LIBRARIES
LINK_LIBRARIES
KF5::I18n
KF5::MailTransport
KF5::Mime
KF5::MessageComposer
KF5::MessageViewer
......@@ -81,7 +83,7 @@ add_messagecomposer_cryptotest( cryptocomposertest.cpp )
add_messagecomposer_test( infoparttest.cpp )
add_messagecomposer_test( textparttest.cpp )
add_messagecomposer_test( globalparttest.cpp )
add_messagecomposer_test( composerviewbasetest.cpp )
add_messagecomposer_test( composerviewbasetest.cpp setupenv.cpp )
add_messagecomposer_test( recipientseditortest.cpp )
......
......@@ -5,21 +5,56 @@
*/
#include "composerviewbasetest.h"
#include "../src/composer/composerviewbase.h"
#include "qtest_messagecomposer.h"
#include "setupenv.h"
#include <MessageComposer/Composer>
#include <MessageComposer/ComposerViewBase>
#include <MessageComposer/RichTextComposerNg>
#include <MessageComposer/RecipientsEditor>
#include <KIdentityManagement/KIdentityManagement/Identity>
#include <KIdentityManagement/KIdentityManagement/IdentityCombo>
#include <KIdentityManagement/KIdentityManagement/IdentityManager>
#include <MailTransport/TransportComboBox>
#include <QStandardPaths>
#include <QTest>
using namespace MessageComposer;
ComposerViewBaseTest::ComposerViewBaseTest(QObject *parent)
: QObject(parent)
{
QStandardPaths::setTestModeEnabled(true);
}
ComposerViewBaseTest::~ComposerViewBaseTest()
{
}
void ComposerViewBaseTest::cleanupTestCase()
{
delete mIdentMan;
mIdentMan = nullptr;
delete mIdentCombo;
mIdentCombo = nullptr;
}
void ComposerViewBaseTest::initTestCase()
{
mIdentMan = new KIdentityManagement::IdentityManager;
KIdentityManagement::Identity &ident = mIdentMan->modifyIdentityForUoid(mIdentMan->defaultIdentity().uoid());
ident.setAutocryptEnabled(true);
mIdentMan->commit();
mIdentCombo = new KIdentityManagement::IdentityCombo(mIdentMan);
}
void ComposerViewBaseTest::shouldHaveDefaultValue()
{
MessageComposer::ComposerViewBase composerViewBase;
ComposerViewBase composerViewBase;
QVERIFY(!composerViewBase.attachmentModel());
QVERIFY(!composerViewBase.attachmentController());
QVERIFY(!composerViewBase.recipientsEditor());
......@@ -36,6 +71,76 @@ void ComposerViewBaseTest::shouldHaveDefaultValue()
QVERIFY(composerViewBase.from().isEmpty());
QVERIFY(composerViewBase.replyTo().isEmpty());
QVERIFY(composerViewBase.subject().isEmpty());
QCOMPARE(composerViewBase.autoSaveInterval(), 60000);
}
void ComposerViewBaseTest::testAutoSaveMessage()
{
QString fileName(QStringLiteral("testfile"));
MessageComposer::RichTextComposerNg editor;
MessageComposer::RecipientsEditor recipientsEditor;
MailTransport::TransportComboBox transpCombo;
ComposerViewBase composerViewBase;
composerViewBase.setAutoSaveInterval(0);
composerViewBase.setAutoSaveFileName(fileName);
composerViewBase.setIdentityCombo(mIdentCombo);
composerViewBase.setIdentityManager(mIdentMan);
composerViewBase.setEditor(&editor);
composerViewBase.setTransportCombo(&transpCombo);
composerViewBase.setRecipientsEditor(&recipientsEditor);
composerViewBase.setFrom(QStringLiteral("me@me.example"));
KMime::Types::Mailbox mb;
mb.from7BitString("to@to.example");
recipientsEditor.setRecipientString({mb}, Recipient::To);
editor.setPlainText(QStringLiteral("Hello,\n\nThis is a test message\n\nGreez"));
composerViewBase.autoSaveMessage();
const QString autosavePath = QStandardPaths::writableLocation(QStandardPaths::GenericDataLocation) + QLatin1String("/kmail2/autosave/");
auto msg = Test::loadMessage(autosavePath + fileName);
msg->messageID()->from7BitString("<test@autotest.example>");
msg->date()->from7BitString("Tue, 22 Jan 2019 12:56:25 +0100");
msg->assemble();
Test::compareFile(msg.data(), QStringLiteral(MAIL_DATA_DIR "/autosave.mbox"));
}
void ComposerViewBaseTest::testGenerateCryptoMessages()
{
MessageComposer::RichTextComposerNg editor;
MessageComposer::RecipientsEditor recipientsEditor;
MailTransport::TransportComboBox transpCombo;
ComposerViewBase composerViewBase;
composerViewBase.setIdentityCombo(mIdentCombo);
composerViewBase.setIdentityManager(mIdentMan);
composerViewBase.setEditor(&editor);
composerViewBase.setTransportCombo(&transpCombo);
composerViewBase.setRecipientsEditor(&recipientsEditor);
composerViewBase.setFrom(QStringLiteral("me@me.example"));
KMime::Types::Mailbox mb;
mb.from7BitString("to@to.example");
recipientsEditor.setRecipientString({mb}, Recipient::To);
editor.setPlainText(QStringLiteral("Hello,\n\nThis is a test message\n\nGreez"));
bool wasCanceled;
auto composers = composerViewBase.generateCryptoMessages(wasCanceled);
QCOMPARE(wasCanceled, false);
QCOMPARE(composers.size(), 1); // No additional composers are created
auto composer = composers.first();
composerViewBase.fillComposer(composer);
VERIFYEXEC(composer);
QCOMPARE(composer->resultMessages().size(), 1);
auto msg = composer->resultMessages().first();
msg->messageID()->from7BitString("<test@autotest.example>");
msg->date()->from7BitString("Tue, 22 Jan 2019 12:56:25 +0100");
msg->assemble();
Test::compareFile(msg.data(), QStringLiteral(MAIL_DATA_DIR "/autosave.mbox"));
}
QTEST_MAIN(ComposerViewBaseTest)
......@@ -7,6 +7,11 @@
#pragma once
#include <QObject>
namespace KIdentityManagement
{
class IdentityManager;
class IdentityCombo;
}
class ComposerViewBaseTest : public QObject
{
......@@ -15,6 +20,13 @@ public:
explicit ComposerViewBaseTest(QObject *parent = nullptr);
~ComposerViewBaseTest();
private Q_SLOTS:
void cleanupTestCase();
void initTestCase();
void shouldHaveDefaultValue();
void testGenerateCryptoMessages();
void testAutoSaveMessage();
private:
KIdentityManagement::IdentityManager *mIdentMan = nullptr;
KIdentityManagement::IdentityCombo *mIdentCombo = nullptr;
};
From: me@me.example
To: to@to.example
Date: Tue, 22 Jan 2019 12:56:25 +0100
Message-ID: <test@autotest.example>
MIME-Version: 1.0
Content-Transfer-Encoding: 7Bit
Content-Type: text/plain; charset="utf-8"
Hello,
This is a test message
Greez
......@@ -23,6 +23,8 @@ class QTimer;
class KJob;
class QWidget;
class ComposerViewBaseTest;
namespace Sonnet
{
class DictionaryComboBox;
......@@ -374,6 +376,8 @@ private:
Akonadi::Collection mFollowUpCollection;
std::unique_ptr<SendLaterInfo> mSendLaterInfo;
friend ComposerViewBaseTest;
};
} // namespace
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment