File indexing completed on 2025-02-16 04:57:40
0001 /* 0002 SPDX-FileCopyrightText: 2017-2024 Laurent Montel <montel@kde.org> 0003 0004 SPDX-License-Identifier: LGPL-2.0-or-later 0005 */ 0006 0007 #include "templateextracthtmlelementfrommailtest.h" 0008 #include "templateextracthtmlelementfrommail.h" 0009 #include <QSignalSpy> 0010 #include <QTest> 0011 0012 TemplateExtractHtmlElementFromMailTest::TemplateExtractHtmlElementFromMailTest(QObject *parent) 0013 : QObject(parent) 0014 { 0015 } 0016 0017 void TemplateExtractHtmlElementFromMailTest::shouldHaveDefaultValue() 0018 { 0019 TemplateParser::TemplateExtractHtmlElementFromMail w; 0020 QVERIFY(w.bodyElement().isEmpty()); 0021 QVERIFY(w.headerElement().isEmpty()); 0022 QVERIFY(w.htmlElement().isEmpty()); 0023 } 0024 0025 void TemplateExtractHtmlElementFromMailTest::shouldExtractHtml_data() 0026 { 0027 QTest::addColumn<QString>("html"); 0028 QTest::addColumn<QString>("body"); 0029 QTest::addColumn<QString>("header"); 0030 QTest::newRow("test1") << QStringLiteral("<html><head></head><body>HTML Text</body></html>") << QStringLiteral("HTML Text") << QString(); 0031 QTest::newRow("empty") << QString() << QString() << QString(); 0032 } 0033 0034 void TemplateExtractHtmlElementFromMailTest::shouldExtractHtml() 0035 { 0036 QFETCH(QString, html); 0037 QFETCH(QString, body); 0038 QFETCH(QString, header); 0039 TemplateParser::TemplateExtractHtmlElementFromMail w; 0040 QVERIFY(w.htmlElement().isEmpty()); 0041 QSignalSpy spy(&w, &TemplateParser::TemplateExtractHtmlElementFromMail::loadContentDone); 0042 w.setHtmlContent(html); 0043 QVERIFY(spy.wait()); 0044 QCOMPARE(spy.count(), 1); 0045 const bool result = spy.at(0).at(0).toBool(); 0046 QVERIFY(result); 0047 QCOMPARE(w.htmlElement(), html); 0048 QCOMPARE(w.headerElement(), header); 0049 QCOMPARE(w.bodyElement(), body); 0050 } 0051 0052 QTEST_MAIN(TemplateExtractHtmlElementFromMailTest) 0053 0054 #include "moc_templateextracthtmlelementfrommailtest.cpp"