summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorChristian Mollekopf <chrigi_1@fastmail.fm>2018-01-05 16:17:51 +0100
committerChristian Mollekopf <chrigi_1@fastmail.fm>2018-01-08 16:26:38 +0100
commit0dc0b4be6e9ba07774efedee102a23e89eef8e85 (patch)
tree2d6c3a9388c5dde159ffbc72fdd6d0bd285741ed
parent772eeaa715551cbb4693ab221ea8fc6dad7e1bb6 (diff)
downloadkube-0dc0b4be6e9ba07774efedee102a23e89eef8e85.tar.gz
kube-0dc0b4be6e9ba07774efedee102a23e89eef8e85.zip
Composer test
-rw-r--r--components/kube/tests/tst_composerview.qml41
-rw-r--r--framework/src/CMakeLists.txt1
-rw-r--r--framework/src/domainobjectcontroller.cpp109
-rw-r--r--framework/src/domainobjectcontroller.h48
-rw-r--r--framework/src/frameworkplugin.cpp2
-rw-r--r--tests/kubetestrunner.cpp32
6 files changed, 226 insertions, 7 deletions
diff --git a/components/kube/tests/tst_composerview.qml b/components/kube/tests/tst_composerview.qml
index 4b0362a7..b7b6b3df 100644
--- a/components/kube/tests/tst_composerview.qml
+++ b/components/kube/tests/tst_composerview.qml
@@ -20,6 +20,7 @@
20import QtQuick 2.7 20import QtQuick 2.7
21import QtTest 1.0 21import QtTest 1.0
22import "../qml" 22import "../qml"
23import org.kube.framework 1.0 as Kube
23 24
24TestCase { 25TestCase {
25 id: testCase 26 id: testCase
@@ -33,24 +34,50 @@ TestCase {
33 focus: true 34 focus: true
34 } 35 }
35 36
36 function test_start() { 37 function test_1start() {
37 verify(composer) 38 verify(composer)
38 } 39 }
39 40
40 function test_verifyInitialFocus() { 41 function test_2verifyInitialFocus() {
41 var newMailButton = findChild(composer, "newMailButton"); 42 var newMailButton = findChild(composer, "newMailButton");
42 verify(newMailButton) 43 verify(newMailButton)
43 verify(newMailButton.activeFocus) 44 verify(newMailButton.activeFocus)
44 } 45 }
45 46
46 function test_sendMessage() { 47 Component {
47 var mail = null 48 id: controllerComponent
49 Kube.DomainObjectController {}
50 }
51
52 Component {
53 id: outboxComponent
54 Kube.OutboxModel {}
55 }
56
57 function test_3sendMessage() {
58 var domainObjectController = controllerComponent.createObject(null, {blocking: true})
59 var mail = {
60 type: "mail",
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 domainObjectController.create(mail)
69
70 tryVerify(function(){ return domainObjectController.currentObject })
71 var createdMail = domainObjectController.currentObject
72 verify(createdMail)
73
48 var loadAsDraft = true 74 var loadAsDraft = true
49 composer.loadMessage(mail, loadAsDraft) 75 composer.loadMessage(createdMail, loadAsDraft)
50 var sendMailButton = findChild(composer, "sendButton") 76 var sendMailButton = findChild(composer, "sendButton")
51 verify(sendMailButton) 77 verify(sendMailButton)
52 verify(sendMailButton.enabled) 78 tryVerify(function(){ return sendMailButton.enabled })
53 sendMailButton.clicked() 79 sendMailButton.clicked()
54 //TODO verify the mail is sent 80 var outbox = outboxComponent.createObject(null, {})
81 tryCompare(outbox, "count", 1)
55 } 82 }
56} 83}
diff --git a/framework/src/CMakeLists.txt b/framework/src/CMakeLists.txt
index a5b2f6bc..526fbefe 100644
--- a/framework/src/CMakeLists.txt
+++ b/framework/src/CMakeLists.txt
@@ -46,6 +46,7 @@ add_library(kubeframework SHARED
46 webengineprofile.cpp 46 webengineprofile.cpp
47 startupcheck.cpp 47 startupcheck.cpp
48 keyring.cpp 48 keyring.cpp
49 domainobjectcontroller.cpp
49 ) 50 )
50target_link_libraries(kubeframework 51target_link_libraries(kubeframework
51 sink 52 sink
diff --git a/framework/src/domainobjectcontroller.cpp b/framework/src/domainobjectcontroller.cpp
new file mode 100644
index 00000000..eb1fd417
--- /dev/null
+++ b/framework/src/domainobjectcontroller.cpp
@@ -0,0 +1,109 @@
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 "domainobjectcontroller.h"
20
21#include <sink/store.h>
22#include <sink/applicationdomaintype.h>
23#include <kmime/kmime_message.h>
24#include <mailtemplates.h>
25
26using namespace Kube;
27
28DomainObjectController::DomainObjectController(QObject *parent)
29 : QObject(parent)
30{
31
32}
33
34QStringList toStringList(const QVariantList &list)
35{
36 QStringList s;
37 for (const auto &e : list) {
38 s << e.toString();
39 }
40 return s;
41}
42
43void DomainObjectController::create(const QVariantMap &object)
44{
45 using namespace Sink::ApplicationDomain;
46 qWarning() << "Creating " << object;
47 auto type = object["type"].toString();
48 if (type == getTypeName<Mail>()) {
49 auto toAddresses = toStringList(object["to"].toList());
50 auto ccAddresses = toStringList(object["cc"].toList());
51 auto bccAddresses = toStringList(object["bcc"].toList());
52
53 KMime::Types::Mailbox mb;
54 mb.fromUnicodeString("identity@example.org");
55 auto msg = MailTemplates::createMessage({},
56 toAddresses,
57 ccAddresses,
58 bccAddresses,
59 mb,
60 object["subject"].toString(),
61 object["body"].toString(),
62 {},
63 {},
64 {},
65 {});
66
67 Sink::Query query;
68 query.containsFilter<SinkResource::Capabilities>(ResourceCapabilities::Mail::storage);
69 query.filter<SinkResource::Account>("account1");
70 Sink::Store::fetchAll<SinkResource>(query)
71 .then([=](const QList<SinkResource::Ptr> &resources) {
72 if (!resources.isEmpty()) {
73 auto resourceId = resources[0]->identifier();
74 qWarning() << "Using resource " << resourceId << " from account " << resources[0]->getAccount();
75 auto mail = ApplicationDomainType::createEntity<Mail>(resourceId);
76 mail.setMimeMessage(msg->encodedContent(true));
77 Sink::Store::create<Mail>(mail).exec();
78 monitor(QVariant::fromValue(Mail::Ptr::create(mail)));
79 } else {
80 qWarning() << "No resources found.";
81 }
82 }).exec();
83 }
84
85}
86
87void DomainObjectController::monitor(const QVariant &object)
88{
89 using namespace Sink::ApplicationDomain;
90 qWarning() << "Monitoring " << object;
91 auto mail = object.value<Mail::Ptr>();
92 Q_ASSERT(mail);
93 Sink::Query query{*mail};
94 query.setFlags(Sink::Query::LiveQuery);
95 mModel = Sink::Store::loadModel<Mail>(query);
96 QObject::connect(mModel.data(), &QAbstractItemModel::rowsInserted, [=](const QModelIndex &index, int start, int end) {
97 for (int i = start; i <= end; i++) {
98 auto mail = mModel->index(i, 0, QModelIndex()).data(Sink::Store::DomainObjectRole).value<Mail::Ptr>();
99 mCurrentObject = QVariant::fromValue(mail);
100 emit currentObjectChanged();
101 break;
102 }
103 });
104}
105
106QVariant DomainObjectController::currentObject() const
107{
108 return mCurrentObject;
109}
diff --git a/framework/src/domainobjectcontroller.h b/framework/src/domainobjectcontroller.h
new file mode 100644
index 00000000..5805c5a8
--- /dev/null
+++ b/framework/src/domainobjectcontroller.h
@@ -0,0 +1,48 @@
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#include <QVariant>
23#include <QAbstractItemModel>
24#include <QSharedPointer>
25
26namespace Kube {
27
28class DomainObjectController : public QObject
29{
30 Q_OBJECT
31 Q_PROPERTY(QVariant currentObject READ currentObject NOTIFY currentObjectChanged)
32public:
33 explicit DomainObjectController(QObject *parent = 0);
34
35 QVariant currentObject() const;
36
37 Q_INVOKABLE void create(const QVariantMap &object);
38 Q_INVOKABLE void monitor(const QVariant &object);
39
40signals:
41 void currentObjectChanged();
42
43private:
44 QVariant mCurrentObject;
45 QSharedPointer<QAbstractItemModel> mModel;
46};
47
48}
diff --git a/framework/src/frameworkplugin.cpp b/framework/src/frameworkplugin.cpp
index 1de776a5..f768be1b 100644
--- a/framework/src/frameworkplugin.cpp
+++ b/framework/src/frameworkplugin.cpp
@@ -40,6 +40,7 @@
40#include "startupcheck.h" 40#include "startupcheck.h"
41#include "keyring.h" 41#include "keyring.h"
42#include "controller.h" 42#include "controller.h"
43#include "domainobjectcontroller.h"
43 44
44#include <QtQml> 45#include <QtQml>
45#include <QQuickImageProvider> 46#include <QQuickImageProvider>
@@ -133,6 +134,7 @@ void FrameworkPlugin::registerTypes (const char *uri)
133 qmlRegisterType<Kube::Settings>(uri, 1, 0, "Settings"); 134 qmlRegisterType<Kube::Settings>(uri, 1, 0, "Settings");
134 135
135 qmlRegisterType<Kube::Fabric::Listener>(uri, 1, 0, "Listener"); 136 qmlRegisterType<Kube::Fabric::Listener>(uri, 1, 0, "Listener");
137 qmlRegisterType<Kube::DomainObjectController>(uri, 1, 0, "DomainObjectController");
136 qmlRegisterSingletonType<Kube::Fabric::Fabric>(uri, 1, 0, "Fabric", fabric_singletontype_provider); 138 qmlRegisterSingletonType<Kube::Fabric::Fabric>(uri, 1, 0, "Fabric", fabric_singletontype_provider);
137 139
138 qmlRegisterType<KubeImage>(uri, 1, 0, "KubeImage"); 140 qmlRegisterType<KubeImage>(uri, 1, 0, "KubeImage");
diff --git a/tests/kubetestrunner.cpp b/tests/kubetestrunner.cpp
index b6c88341..3bf06d44 100644
--- a/tests/kubetestrunner.cpp
+++ b/tests/kubetestrunner.cpp
@@ -1,10 +1,42 @@
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*/
1#include <QtQuickTest/quicktest.h> 19#include <QtQuickTest/quicktest.h>
2#include <sink/test.h> 20#include <sink/test.h>
21#include <sink/store.h>
3 22
4int main(int argc, char **argv) 23int main(int argc, char **argv)
5{ 24{
6 QCoreApplication::setAttribute(Qt::AA_ShareOpenGLContexts, true); 25 QCoreApplication::setAttribute(Qt::AA_ShareOpenGLContexts, true);
7 Sink::Test::initTest(); 26 Sink::Test::initTest();
27
28 auto resource = Sink::ApplicationDomain::DummyResource::create("account1");
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
8 QTEST_ADD_GPU_BLACKLIST_SUPPORT 40 QTEST_ADD_GPU_BLACKLIST_SUPPORT
9 QTEST_SET_MAIN_SOURCE_PATH 41 QTEST_SET_MAIN_SOURCE_PATH
10 return quick_test_main(argc, argv, "kubetest", 0); 42 return quick_test_main(argc, argv, "kubetest", 0);