diff options
author | Christian Mollekopf <chrigi_1@fastmail.fm> | 2018-01-10 17:10:10 +0100 |
---|---|---|
committer | Christian Mollekopf <chrigi_1@fastmail.fm> | 2018-01-10 17:10:10 +0100 |
commit | 107e60448ec89883e60905f5a1cef507c0bf9fc2 (patch) | |
tree | 36fe3ba8226bb2bba594de8a3d574bfa2e28ce36 | |
parent | 4e0369c1ca779576998c27dc4f06c018c5a22202 (diff) | |
download | kube-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.txt | 10 | ||||
-rw-r--r-- | tests/kubetestrunner.cpp | 11 | ||||
-rw-r--r-- | tests/qmldir | 3 | ||||
-rw-r--r-- | tests/testplugin.cpp | 50 | ||||
-rw-r--r-- | tests/teststore.cpp | 17 | ||||
-rw-r--r-- | views/conversation/main.qml | 75 |
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) | |||
2 | find_package(Sink CONFIG REQUIRED) | 2 | find_package(Sink CONFIG REQUIRED) |
3 | find_package(KAsync CONFIG REQUIRED) | 3 | find_package(KAsync CONFIG REQUIRED) |
4 | 4 | ||
5 | add_executable(kubetestrunner kubetestrunner.cpp teststore.cpp) | 5 | add_executable(kubetestrunner kubetestrunner.cpp) |
6 | target_link_libraries(kubetestrunner | 6 | target_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 | |||
13 | install(FILES qmldir DESTINATION ${QML_INSTALL_DIR}/org/kube/test) | ||
14 | |||
15 | add_library(testplugin SHARED testplugin.cpp teststore.cpp) | ||
16 | target_link_libraries(testplugin | ||
17 | kubeframework | ||
18 | ) | ||
19 | install(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 | |||
24 | static QObject *teststore(QQmlEngine *engine, QJSEngine *scriptEngine) | ||
25 | { | ||
26 | Q_UNUSED(engine) | ||
27 | Q_UNUSED(scriptEngine) | ||
28 | return new Kube::TestStore; | ||
29 | } | ||
30 | 22 | ||
31 | int main(int argc, char **argv) | 23 | int 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 @@ | |||
1 | module org.kube.test | ||
2 | |||
3 | plugin 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 | |||
27 | class TestPlugin : public QQmlExtensionPlugin | ||
28 | { | ||
29 | Q_OBJECT | ||
30 | Q_PLUGIN_METADATA(IID "org.qt-project.Qt.QQmlExtensionInterface") | ||
31 | |||
32 | public: | ||
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 | |||
77 | static 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 | ||
77 | void TestStore::setup(const QVariantMap &map) | 85 | void 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 | |||
19 | import QtQuick 2.7 | ||
20 | import QtQuick.Controls 2.0 | ||
21 | import QtQuick.Window 2.0 | ||
22 | |||
23 | import org.kube.framework 1.0 as Kube | ||
24 | import org.kube.test 1.0 | ||
25 | import "qml" | ||
26 | |||
27 | ApplicationWindow { | ||
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 | } | ||