Skip to content

Commit

Permalink
[#215] Add initial integration test for HtmlTemplate class
Browse files Browse the repository at this point in the history
  • Loading branch information
cloose committed Mar 22, 2015
1 parent 2a27c13 commit 5d9ead7
Show file tree
Hide file tree
Showing 6 changed files with 77 additions and 1 deletion.
5 changes: 5 additions & 0 deletions app-static/template/htmltemplate.cpp
Expand Up @@ -41,6 +41,11 @@ HtmlTemplate::HtmlTemplate()
}
}

HtmlTemplate::HtmlTemplate(const QString &templateString) :
htmlTemplate(templateString)
{
}

QString HtmlTemplate::render(const QString &body, RenderOptions options) const
{
// add scrollbar synchronization
Expand Down
1 change: 1 addition & 0 deletions app-static/template/htmltemplate.h
Expand Up @@ -38,6 +38,7 @@ class HtmlTemplate : public Template
{
public:
HtmlTemplate();
explicit HtmlTemplate(const QString &templateString);

virtual QString render(const QString &body, RenderOptions options) const;
virtual QString exportAsHtml(const QString &header, const QString &body, RenderOptions options) const;
Expand Down
33 changes: 33 additions & 0 deletions test/integration/htmltemplatetest.cpp
@@ -0,0 +1,33 @@
/*
* Copyright 2015 Christian Loose <christian.loose@hamburg.de>
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
#include "htmltemplatetest.h"

#include <QtTest>

#include <template/htmltemplate.h>
#include "loremipsumtestdata.h"

static const QString HTML_TEMPLATE = QStringLiteral("<html><head><!--__HTML_HEADER__--></head><body><!--__HTML_CONTENT__--></body></html>");

void HtmlTemplateTest::rendersContentInsideBodyTags()
{
HtmlTemplate htmlTemplate(HTML_TEMPLATE);

QString html = htmlTemplate.render("<p>TEST</p>", 0);

QCOMPARE(html, QStringLiteral("<html><head><script type=\"text/javascript\">window.onscroll = function() { synchronizer.webViewScrolled(); }; </script>\n</head><body><p>TEST</p></body></html>"));
}
31 changes: 31 additions & 0 deletions test/integration/htmltemplatetest.h
@@ -0,0 +1,31 @@
#pragma once
/*
* Copyright 2015 Christian Loose <christian.loose@hamburg.de>
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
#ifndef HTMLTEMPLATETEST_H
#define HTMLTEMPLATETEST_H

#include <QObject>

class HtmlTemplateTest : public QObject
{
Q_OBJECT

private slots:
void rendersContentInsideBodyTags();
};

#endif // HTMLTEMPLATETEST_H
2 changes: 2 additions & 0 deletions test/integration/integration.pro
Expand Up @@ -13,6 +13,7 @@ CONFIG += console testcase
SOURCES += \
discountmarkdownconvertertest.cpp \
htmlpreviewcontrollertest.cpp \
htmltemplatetest.cpp \
jsonsnippetfiletest.cpp \
main.cpp \
pmhmarkdownparsertest.cpp \
Expand All @@ -21,6 +22,7 @@ SOURCES += \
HEADERS += \
discountmarkdownconvertertest.h \
htmlpreviewcontrollertest.h \
htmltemplatetest.h \
jsonsnippetfiletest.h \
pmhmarkdownparsertest.h \
revealmarkdownconvertertest.h
Expand Down
6 changes: 5 additions & 1 deletion test/integration/main.cpp
@@ -1,5 +1,5 @@
/*
* Copyright 2013 Christian Loose <christian.loose@hamburg.de>
* Copyright 2013-2015 Christian Loose <christian.loose@hamburg.de>
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
Expand All @@ -20,6 +20,7 @@

#include "discountmarkdownconvertertest.h"
#include "htmlpreviewcontrollertest.h"
#include "htmltemplatetest.h"
#include "jsonsnippetfiletest.h"
#include "pmhmarkdownparsertest.h"
#include "revealmarkdownconvertertest.h"
Expand Down Expand Up @@ -54,6 +55,9 @@ int main(int argc, char *argv[])
HtmlPreviewControllerTest test6;
ret += QTest::qExec(&test6, argc, argv);

HtmlTemplateTest test7;
ret += QTest::qExec(&test7, argc, argv);

return ret;
}

0 comments on commit 5d9ead7

Please sign in to comment.