summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMontel Laurent <montel@kde.org>2016-09-05 05:57:51 (GMT)
committerMontel Laurent <montel@kde.org>2016-09-05 05:57:51 (GMT)
commit3123bf27f973f14855db158a53f799e3cd98d145 (patch)
tree1f3ecb52dc272ca16c60115f30fdddd8baa3f5a5
parentdf496ed80059612b7f69b47615aa4d3d1eb75599 (diff)
Add autotest on signature which loads contain from file
-rw-r--r--messagecomposer/src/composer-ng/autotests/CMakeLists.txt2
-rw-r--r--messagecomposer/src/composer-ng/autotests/data/signature1.txt3
-rw-r--r--messagecomposer/src/composer-ng/autotests/richtextcomposerngtest.cpp71
-rw-r--r--messagecomposer/src/composer-ng/autotests/richtextcomposerngtest.h3
4 files changed, 79 insertions, 0 deletions
diff --git a/messagecomposer/src/composer-ng/autotests/CMakeLists.txt b/messagecomposer/src/composer-ng/autotests/CMakeLists.txt
index 97ecb5f..233c195 100644
--- a/messagecomposer/src/composer-ng/autotests/CMakeLists.txt
+++ b/messagecomposer/src/composer-ng/autotests/CMakeLists.txt
@@ -1,3 +1,5 @@
+add_definitions( -DSIGNATURE_DATA_DIR="${CMAKE_CURRENT_SOURCE_DIR}/data" )
+
macro(add_composerng_autocorrect_unittest _source)
ecm_add_test(${_source}
NAME_PREFIX "messagecomposer-composerng-"
diff --git a/messagecomposer/src/composer-ng/autotests/data/signature1.txt b/messagecomposer/src/composer-ng/autotests/data/signature1.txt
new file mode 100644
index 0000000..25ffb4c
--- /dev/null
+++ b/messagecomposer/src/composer-ng/autotests/data/signature1.txt
@@ -0,0 +1,3 @@
+Signature bla bla
+Blo bli
+foo
diff --git a/messagecomposer/src/composer-ng/autotests/richtextcomposerngtest.cpp b/messagecomposer/src/composer-ng/autotests/richtextcomposerngtest.cpp
index a5d3bed..52c6002 100644
--- a/messagecomposer/src/composer-ng/autotests/richtextcomposerngtest.cpp
+++ b/messagecomposer/src/composer-ng/autotests/richtextcomposerngtest.cpp
@@ -371,4 +371,75 @@ void RichTextComposerNgTest::shouldReplaceSignature()
QCOMPARE(richtextComposerNg.toPlainText(), expected);
}
+void RichTextComposerNgTest::shouldLoadSignatureFromFile_data()
+{
+ QTest::addColumn<QString>("signatureFile");
+ QTest::addColumn<QString>("bodytext");
+ QTest::addColumn<KIdentityManagement::Signature::Placement>("signatureplacement");
+ QTest::addColumn<KIdentityManagement::Signature::AddedTextFlag>("signatureaddtext");
+
+ QTest::newRow("newlinebody") << QStringLiteral("signature1.txt") << QStringLiteral("\n")
+ << KIdentityManagement::Signature::End << KIdentityManagement::Signature::AddSeparator;
+
+}
+
+void RichTextComposerNgTest::shouldLoadSignatureFromFile()
+{
+ QFETCH(QString, signatureFile);
+ QFETCH(QString, bodytext);
+ QFETCH(KIdentityManagement::Signature::Placement, signatureplacement);
+ QFETCH(KIdentityManagement::Signature::AddedTextFlag, signatureaddtext);
+
+ MessageComposer::RichTextComposerNg richtextComposerNg;
+ richtextComposerNg.createActions(new KActionCollection(this));
+ const QString original(bodytext);
+ richtextComposerNg.setPlainText(original);
+
+ KIdentityManagement::Signature newSignature(QLatin1String(SIGNATURE_DATA_DIR) + QLatin1Char('/') + signatureFile, false);
+ newSignature.setEnabledSignature(true);
+ newSignature.setInlinedHtml(false);
+
+ QString addText;
+ switch (signatureaddtext) {
+ case KIdentityManagement::Signature::AddNothing:
+ break;
+ case KIdentityManagement::Signature::AddSeparator:
+ addText = QStringLiteral("-- \n");
+ break;
+ case KIdentityManagement::Signature::AddNewLines:
+ addText = QStringLiteral("\n");
+ break;
+ }
+
+ QString expected;
+ QString signatureText = newSignature.toPlainText();
+ switch (signatureplacement) {
+ case KIdentityManagement::Signature::Start:
+ expected = addText + signatureText + bodytext;
+ break;
+ case KIdentityManagement::Signature::End:
+ expected = bodytext + addText + signatureText;
+ break;
+ case KIdentityManagement::Signature::AtCursor:
+ break;
+ }
+
+ richtextComposerNg.insertSignature(newSignature, signatureplacement, signatureaddtext);
+ QCOMPARE(richtextComposerNg.toPlainText(), expected);
+
+ KIdentityManagement::Signature emptySignature;
+
+ bool replaceSignature = richtextComposerNg.composerSignature()->replaceSignature(newSignature, emptySignature);
+ QVERIFY(replaceSignature);
+ QCOMPARE(richtextComposerNg.toPlainText(), original);
+
+ replaceSignature = richtextComposerNg.composerSignature()->replaceSignature(emptySignature, newSignature);
+ QVERIFY(!replaceSignature);
+ //When signature is empty we can't replace it.=> we need to insertSignature
+
+ //=> insertSignature(signature, KIdentityManagement::Signature::End, addedText);
+ richtextComposerNg.insertSignature(newSignature, signatureplacement, signatureaddtext);
+ QCOMPARE(richtextComposerNg.toPlainText(), expected);
+}
+
QTEST_MAIN(RichTextComposerNgTest)
diff --git a/messagecomposer/src/composer-ng/autotests/richtextcomposerngtest.h b/messagecomposer/src/composer-ng/autotests/richtextcomposerngtest.h
index 17e1acf..b46b0b5 100644
--- a/messagecomposer/src/composer-ng/autotests/richtextcomposerngtest.h
+++ b/messagecomposer/src/composer-ng/autotests/richtextcomposerngtest.h
@@ -47,6 +47,9 @@ private Q_SLOTS:
void shouldReplaceSignature_data();
void shouldReplaceSignature();
+ void shouldLoadSignatureFromFile_data();
+ void shouldLoadSignatureFromFile();
+
};
#endif // RICHTEXTCOMPOSERNGTEST_H