summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--components/kube/tests/tst_composerview.qml34
-rw-r--r--tests/CMakeLists.txt5
-rw-r--r--tests/kubetestrunner.cpp22
-rw-r--r--tests/teststore.cpp59
-rw-r--r--tests/teststore.h31
5 files changed, 134 insertions, 17 deletions
diff --git a/components/kube/tests/tst_composerview.qml b/components/kube/tests/tst_composerview.qml
index b7b6b3df..d9cd2dfb 100644
--- a/components/kube/tests/tst_composerview.qml
+++ b/components/kube/tests/tst_composerview.qml
@@ -21,6 +21,7 @@ import QtQuick 2.7
21import QtTest 1.0 21import QtTest 1.0
22import "../qml" 22import "../qml"
23import org.kube.framework 1.0 as Kube 23import org.kube.framework 1.0 as Kube
24import org.kube.test 1.0
24 25
25TestCase { 26TestCase {
26 id: testCase 27 id: testCase
@@ -29,16 +30,20 @@ TestCase {
29 name: "ComposerView" 30 name: "ComposerView"
30 when: windowShown 31 when: windowShown
31 32
32 ComposerView { 33 Component {
33 id: composer 34 id:composerComponent
34 focus: true 35 ComposerView {
36 focus: true
37 }
35 } 38 }
36 39
37 function test_1start() { 40 function test_1start() {
41 var composer = createTemporaryObject(composerComponent, testCase, {})
38 verify(composer) 42 verify(composer)
39 } 43 }
40 44
41 function test_2verifyInitialFocus() { 45 function test_2verifyInitialFocus() {
46 var composer = createTemporaryObject(composerComponent, testCase, {})
42 var newMailButton = findChild(composer, "newMailButton"); 47 var newMailButton = findChild(composer, "newMailButton");
43 verify(newMailButton) 48 verify(newMailButton)
44 verify(newMailButton.activeFocus) 49 verify(newMailButton.activeFocus)
@@ -55,6 +60,29 @@ TestCase {
55 } 60 }
56 61
57 function test_3sendMessage() { 62 function test_3sendMessage() {
63 var initialState = {
64 accounts: [{
65 id: "account1",
66 }],
67 identities: [{
68 account: "account1",
69 name: "Test Identity",
70 address: "identity@example.org"
71 }],
72 resources: [{
73 id: "resource1",
74 account: "account1",
75 type: "dummy"
76 },
77 {
78 id: "resource2",
79 account: "account1",
80 type: "mailtransport"
81 }]
82 }
83 TestStore.setup(initialState)
84 var composer = createTemporaryObject(composerComponent, testCase, {})
85
58 var domainObjectController = controllerComponent.createObject(null, {blocking: true}) 86 var domainObjectController = controllerComponent.createObject(null, {blocking: true})
59 var mail = { 87 var mail = {
60 type: "mail", 88 type: "mail",
diff --git a/tests/CMakeLists.txt b/tests/CMakeLists.txt
index 9ce7915c..ca394d9e 100644
--- a/tests/CMakeLists.txt
+++ b/tests/CMakeLists.txt
@@ -1,9 +1,10 @@
1find_package(Qt5 REQUIRED NO_MODULE COMPONENTS QuickTest Network) 1find_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) 5add_executable(kubetestrunner kubetestrunner.cpp teststore.cpp)
6target_link_libraries(kubetestrunner 6target_link_libraries(kubetestrunner
7 Qt5::QuickTest 7 Qt5::QuickTest
8 Qt5::Quick
8 sink 9 sink
9) 10)
diff --git a/tests/kubetestrunner.cpp b/tests/kubetestrunner.cpp
index 3bf06d44..dd022091 100644
--- a/tests/kubetestrunner.cpp
+++ b/tests/kubetestrunner.cpp
@@ -17,25 +17,23 @@
17 02110-1301, USA. 17 02110-1301, USA.
18*/ 18*/
19#include <QtQuickTest/quicktest.h> 19#include <QtQuickTest/quicktest.h>
20#include <QQmlEngine>
20#include <sink/test.h> 21#include <sink/test.h>
21#include <sink/store.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}
22 30
23int main(int argc, char **argv) 31int main(int argc, char **argv)
24{ 32{
25 QCoreApplication::setAttribute(Qt::AA_ShareOpenGLContexts, true); 33 QCoreApplication::setAttribute(Qt::AA_ShareOpenGLContexts, true);
26 Sink::Test::initTest(); 34 Sink::Test::initTest();
27 35
28 auto resource = Sink::ApplicationDomain::DummyResource::create("account1"); 36 qmlRegisterSingletonType<Kube::TestStore>("org.kube.test", 1, 0, "TestStore", teststore);
29 Sink::Store::create(resource).exec().waitForFinished();
30
31 auto transportResource = Sink::ApplicationDomain::MailtransportResource::create("account1");
32 Sink::Store::create(transportResource).exec().waitForFinished();
33
34 auto identity = Sink::ApplicationDomain::Identity{};
35 identity.setAccount("account1");
36 identity.setAddress("identity@example.org");
37 identity.setName("Identity Name");
38 Sink::Store::create(identity).exec().waitForFinished();
39 37
40 QTEST_ADD_GPU_BLACKLIST_SUPPORT 38 QTEST_ADD_GPU_BLACKLIST_SUPPORT
41 QTEST_SET_MAIN_SOURCE_PATH 39 QTEST_SET_MAIN_SOURCE_PATH
diff --git a/tests/teststore.cpp b/tests/teststore.cpp
new file mode 100644
index 00000000..a8cd0b2d
--- /dev/null
+++ b/tests/teststore.cpp
@@ -0,0 +1,59 @@
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#include "teststore.h"
20
21#include <sink/store.h>
22
23#include <QDebug>
24#include <QVariant>
25
26using namespace Kube;
27
28static void iterateOverObjects(const QVariantList &list, std::function<void(const QVariantMap &)> callback)
29{
30 for (const auto &entry : list) {
31 auto object = entry.toMap();
32 callback(object);
33 }
34}
35
36void TestStore::setup(const QVariantMap &map)
37{
38 iterateOverObjects(map.value("resources").toList(), [] (const QVariantMap &object) {
39 auto resource = [&] {
40 if (object["type"] == "dummy") {
41 return Sink::ApplicationDomain::DummyResource::create(object["account"].toByteArray());
42 }
43 if (object["type"] == "mailtransport") {
44 return Sink::ApplicationDomain::MailtransportResource::create(object["account"].toByteArray());
45 }
46 Q_ASSERT(false);
47 return Sink::ApplicationDomain::SinkResource{};
48 }();
49 Sink::Store::create(resource).exec().waitForFinished();
50 });
51
52 iterateOverObjects(map.value("identities").toList(), [] (const QVariantMap &object) {
53 auto identity = Sink::ApplicationDomain::Identity{};
54 identity.setAccount(object["account"].toByteArray());
55 identity.setAddress(object["address"].toString());
56 identity.setName(object["name"].toString());
57 Sink::Store::create(identity).exec().waitForFinished();
58 });
59}
diff --git a/tests/teststore.h b/tests/teststore.h
new file mode 100644
index 00000000..f0578ca5
--- /dev/null
+++ b/tests/teststore.h
@@ -0,0 +1,31 @@
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#pragma once
20
21#include <QObject>
22
23namespace Kube {
24
25class TestStore : public QObject {
26 Q_OBJECT
27public:
28 Q_INVOKABLE void setup(const QVariantMap &);
29};
30
31}