summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorChristian Mollekopf <chrigi_1@fastmail.fm>2018-01-10 17:10:10 +0100
committerChristian Mollekopf <chrigi_1@fastmail.fm>2018-01-10 17:10:10 +0100
commit107e60448ec89883e60905f5a1cef507c0bf9fc2 (patch)
tree36fe3ba8226bb2bba594de8a3d574bfa2e28ce36
parent4e0369c1ca779576998c27dc4f06c018c5a22202 (diff)
downloadkube-107e60448ec89883e60905f5a1cef507c0bf9fc2.tar.gz
kube-107e60448ec89883e60905f5a1cef507c0bf9fc2.zip
Run views with a test dataset using TestStore.
This allows us to start the view using qmlscene with a testdata set that is created in a test datastore (isolated from the regular data).
-rw-r--r--tests/CMakeLists.txt10
-rw-r--r--tests/kubetestrunner.cpp11
-rw-r--r--tests/qmldir3
-rw-r--r--tests/testplugin.cpp50
-rw-r--r--tests/teststore.cpp17
-rw-r--r--views/conversation/main.qml75
6 files changed, 153 insertions, 13 deletions
diff --git a/tests/CMakeLists.txt b/tests/CMakeLists.txt
index b5eb2a96..35b28559 100644
--- a/tests/CMakeLists.txt
+++ b/tests/CMakeLists.txt
@@ -2,10 +2,18 @@ find_package(Qt5 REQUIRED NO_MODULE COMPONENTS QuickTest Network Quick)
2find_package(Sink CONFIG REQUIRED) 2find_package(Sink CONFIG REQUIRED)
3find_package(KAsync CONFIG REQUIRED) 3find_package(KAsync CONFIG REQUIRED)
4 4
5add_executable(kubetestrunner kubetestrunner.cpp teststore.cpp) 5add_executable(kubetestrunner kubetestrunner.cpp)
6target_link_libraries(kubetestrunner 6target_link_libraries(kubetestrunner
7 Qt5::QuickTest 7 Qt5::QuickTest
8 Qt5::Quick 8 Qt5::Quick
9 sink 9 sink
10 kubeframework 10 kubeframework
11) 11)
12
13install(FILES qmldir DESTINATION ${QML_INSTALL_DIR}/org/kube/test)
14
15add_library(testplugin SHARED testplugin.cpp teststore.cpp)
16target_link_libraries(testplugin
17 kubeframework
18)
19install(TARGETS testplugin DESTINATION ${QML_INSTALL_DIR}/org/kube/test)
diff --git a/tests/kubetestrunner.cpp b/tests/kubetestrunner.cpp
index dd022091..99017a43 100644
--- a/tests/kubetestrunner.cpp
+++ b/tests/kubetestrunner.cpp
@@ -19,21 +19,10 @@
19#include <QtQuickTest/quicktest.h> 19#include <QtQuickTest/quicktest.h>
20#include <QQmlEngine> 20#include <QQmlEngine>
21#include <sink/test.h> 21#include <sink/test.h>
22#include "teststore.h"
23
24static QObject *teststore(QQmlEngine *engine, QJSEngine *scriptEngine)
25{
26 Q_UNUSED(engine)
27 Q_UNUSED(scriptEngine)
28 return new Kube::TestStore;
29}
30 22
31int main(int argc, char **argv) 23int main(int argc, char **argv)
32{ 24{
33 QCoreApplication::setAttribute(Qt::AA_ShareOpenGLContexts, true); 25 QCoreApplication::setAttribute(Qt::AA_ShareOpenGLContexts, true);
34 Sink::Test::initTest();
35
36 qmlRegisterSingletonType<Kube::TestStore>("org.kube.test", 1, 0, "TestStore", teststore);
37 26
38 QTEST_ADD_GPU_BLACKLIST_SUPPORT 27 QTEST_ADD_GPU_BLACKLIST_SUPPORT
39 QTEST_SET_MAIN_SOURCE_PATH 28 QTEST_SET_MAIN_SOURCE_PATH
diff --git a/tests/qmldir b/tests/qmldir
new file mode 100644
index 00000000..2ccb630a
--- /dev/null
+++ b/tests/qmldir
@@ -0,0 +1,3 @@
1module org.kube.test
2
3plugin testplugin
diff --git a/tests/testplugin.cpp b/tests/testplugin.cpp
new file mode 100644
index 00000000..35889c13
--- /dev/null
+++ b/tests/testplugin.cpp
@@ -0,0 +1,50 @@
1/*
2 Copyright (c) 2018 Christian Mollekopf <mollekopf@kolabsys.com>
3
4 This library is free software; you can redistribute it and/or modify it
5 under the terms of the GNU Library General Public License as published by
6 the Free Software Foundation; either version 2 of the License, or (at your
7 option) any later version.
8
9 This library is distributed in the hope that it will be useful, but WITHOUT
10 ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
11 FITNESS FOR A PARTICULAR PURPOSE. See the GNU Library General Public
12 License for more details.
13
14 You should have received a copy of the GNU Library General Public License
15 along with this library; see the file COPYING.LIB. If not, write to the
16 Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
17 02110-1301, USA.
18*/
19
20#include <QtQml>
21#include <QQmlEngine>
22#include <QQmlExtensionPlugin>
23#include <sink/test.h>
24
25#include "teststore.h"
26
27class TestPlugin : public QQmlExtensionPlugin
28{
29 Q_OBJECT
30 Q_PLUGIN_METADATA(IID "org.qt-project.Qt.QQmlExtensionInterface")
31
32public:
33 void initializeEngine(QQmlEngine *engine, const char *uri) Q_DECL_OVERRIDE
34 {
35 Q_UNUSED(engine);
36 Q_UNUSED(uri);
37 Sink::Test::initTest();
38 }
39
40 void registerTypes (const char *uri) Q_DECL_OVERRIDE
41 {
42 qmlRegisterSingletonType<Kube::TestStore>(uri, 1, 0, "TestStore", [] (QQmlEngine *, QJSEngine *) -> QObject* {
43 return new Kube::TestStore;
44 });
45 }
46};
47
48
49
50#include "testplugin.moc"
diff --git a/tests/teststore.cpp b/tests/teststore.cpp
index 728af885..ef243b14 100644
--- a/tests/teststore.cpp
+++ b/tests/teststore.cpp
@@ -71,11 +71,25 @@ static void createMail(const QVariantMap &object)
71 71
72 auto mail = ApplicationDomainType::createEntity<Mail>(object["resource"].toByteArray()); 72 auto mail = ApplicationDomainType::createEntity<Mail>(object["resource"].toByteArray());
73 mail.setMimeMessage(msg->encodedContent(true)); 73 mail.setMimeMessage(msg->encodedContent(true));
74 Sink::Store::create<Mail>(mail).exec().waitForFinished(); 74 Sink::Store::create(mail).exec().waitForFinished();
75}
76
77static void createFolder(const QVariantMap &object)
78{
79 using namespace Sink::ApplicationDomain;
80 auto folder = ApplicationDomainType::createEntity<Folder>(object["resource"].toByteArray());
81 folder.setName(object["name"].toString());
82 Sink::Store::create(folder).exec().waitForFinished();
75} 83}
76 84
77void TestStore::setup(const QVariantMap &map) 85void TestStore::setup(const QVariantMap &map)
78{ 86{
87 using namespace Sink::ApplicationDomain;
88 iterateOverObjects(map.value("accounts").toList(), [&] (const QVariantMap &object) {
89 auto account = ApplicationDomainType::createEntity<SinkAccount>("", object["id"].toByteArray());
90 account.setName(object["name"].toString());
91 Sink::Store::create(account).exec().waitForFinished();
92 });
79 QByteArrayList resources; 93 QByteArrayList resources;
80 iterateOverObjects(map.value("resources").toList(), [&] (const QVariantMap &object) { 94 iterateOverObjects(map.value("resources").toList(), [&] (const QVariantMap &object) {
81 resources << object["id"].toByteArray(); 95 resources << object["id"].toByteArray();
@@ -104,6 +118,7 @@ void TestStore::setup(const QVariantMap &map)
104 Sink::Store::create(identity).exec().waitForFinished(); 118 Sink::Store::create(identity).exec().waitForFinished();
105 }); 119 });
106 120
121 iterateOverObjects(map.value("folders").toList(), createFolder);
107 iterateOverObjects(map.value("mails").toList(), createMail); 122 iterateOverObjects(map.value("mails").toList(), createMail);
108 123
109 Sink::ResourceControl::flushMessageQueue(resources).exec().waitForFinished(); 124 Sink::ResourceControl::flushMessageQueue(resources).exec().waitForFinished();
diff --git a/views/conversation/main.qml b/views/conversation/main.qml
new file mode 100644
index 00000000..15360d22
--- /dev/null
+++ b/views/conversation/main.qml
@@ -0,0 +1,75 @@
1/*
2 * Copyright (C) 2018 Christian Mollekopf, <mollekopf@kolabsys.com>
3 *
4 * This program is free software; you can redistribute it and/or modify
5 * it under the terms of the GNU General Public License as published by
6 * the Free Software Foundation; either version 2 of the License, or
7 * (at your option) any later version.
8 *
9 * This program is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 * GNU General Public License for more details.
13 *
14 * You should have received a copy of the GNU General Public License along
15 * with this program; if not, write to the Free Software Foundation, Inc.,
16 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
17 */
18
19import QtQuick 2.7
20import QtQuick.Controls 2.0
21import QtQuick.Window 2.0
22
23import org.kube.framework 1.0 as Kube
24import org.kube.test 1.0
25import "qml"
26
27ApplicationWindow {
28 id: app
29 height: Screen.desktopAvailableHeight * 0.8
30 width: Screen.desktopAvailableWidth * 0.8
31
32 Component.onCompleted: {
33 var initialState = {
34 accounts: [{
35 id: "account1",
36 name: "Test Account"
37 }],
38 identities: [{
39 account: "account1",
40 name: "Test Identity",
41 address: "identity@example.org"
42 }],
43 resources: [{
44 id: "resource1",
45 account: "account1",
46 type: "dummy"
47 },
48 {
49 id: "resource2",
50 account: "account1",
51 type: "mailtransport"
52 }],
53 folders: [{
54 id: "folder1",
55 resource: "resource1",
56 name: "Folder 1"
57 }],
58 mails: [{
59 resource: "resource1",
60 folder: "folder1",
61 subject: "subject",
62 body: "body",
63 to: ["to@example.org"],
64 cc: ["cc@example.org"],
65 bcc: ["bcc@example.org"],
66 draft: true
67 }]
68 }
69 TestStore.setup(initialState)
70 }
71
72 View {
73 anchors.fill: parent
74 }
75}