summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--tests/CMakeLists.txt2
-rw-r--r--tests/teststore.cpp63
-rw-r--r--views/calendar/main.qml41
3 files changed, 98 insertions, 8 deletions
diff --git a/tests/CMakeLists.txt b/tests/CMakeLists.txt
index 35b28559..d7dfe81d 100644
--- a/tests/CMakeLists.txt
+++ b/tests/CMakeLists.txt
@@ -1,6 +1,7 @@
1find_package(Qt5 REQUIRED NO_MODULE COMPONENTS QuickTest Network Quick) 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)
4find_package(KF5CalendarCore CONFIG REQUIRED)
4 5
5add_executable(kubetestrunner kubetestrunner.cpp) 6add_executable(kubetestrunner kubetestrunner.cpp)
6target_link_libraries(kubetestrunner 7target_link_libraries(kubetestrunner
@@ -15,5 +16,6 @@ install(FILES qmldir DESTINATION ${QML_INSTALL_DIR}/org/kube/test)
15add_library(testplugin SHARED testplugin.cpp teststore.cpp) 16add_library(testplugin SHARED testplugin.cpp teststore.cpp)
16target_link_libraries(testplugin 17target_link_libraries(testplugin
17 kubeframework 18 kubeframework
19 KF5::CalendarCore
18) 20)
19install(TARGETS testplugin DESTINATION ${QML_INSTALL_DIR}/org/kube/test) 21install(TARGETS testplugin DESTINATION ${QML_INSTALL_DIR}/org/kube/test)
diff --git a/tests/teststore.cpp b/tests/teststore.cpp
index 6a5304ad..3a60676d 100644
--- a/tests/teststore.cpp
+++ b/tests/teststore.cpp
@@ -21,9 +21,14 @@
21#include <sink/store.h> 21#include <sink/store.h>
22#include <sink/resourcecontrol.h> 22#include <sink/resourcecontrol.h>
23#include <sink/secretstore.h> 23#include <sink/secretstore.h>
24
24#include <kmime/kmime_message.h> 25#include <kmime/kmime_message.h>
25 26
27#include <KCalCore/Event>
28#include <KCalCore/ICalFormat>
29
26#include <QDebug> 30#include <QDebug>
31#include <QUuid>
27#include <QVariant> 32#include <QVariant>
28 33
29#include "framework/src/domain/mime/mailtemplates.h" 34#include "framework/src/domain/mime/mailtemplates.h"
@@ -124,6 +129,59 @@ static void createFolder(const QVariantMap &object)
124 }); 129 });
125} 130}
126 131
132static void createEvent(const QVariantMap &object, const QByteArray &calendarId = {})
133{
134 using Sink::ApplicationDomain::ApplicationDomainType;
135 using Sink::ApplicationDomain::Event;
136
137 auto sinkEvent = ApplicationDomainType::createEntity<Event>(object["resource"].toByteArray());
138
139 auto calcoreEvent = QSharedPointer<KCalCore::Event>::create();
140
141 QString uid;
142 if (object.contains("uid")) {
143 uid = object["uid"].toString();
144 } else {
145 uid = QUuid::createUuid().toString();
146 }
147 calcoreEvent->setUid(uid);
148
149 auto summary = object["summary"].toString();
150 calcoreEvent->setSummary(summary);
151
152 if (object.contains("description")) {
153 auto description = object["description"].toString();
154 calcoreEvent->setDescription(description);
155 }
156
157 auto startTime = object["starts"].toDateTime();
158 auto endTime = object["ends"].toDateTime();
159
160 calcoreEvent->setDtStart(startTime);
161 calcoreEvent->setDtEnd(endTime);
162
163 auto ical = KCalCore::ICalFormat().toICalString(calcoreEvent);
164 sinkEvent.setIcal(ical.toUtf8());
165
166 sinkEvent.setCalendar(calendarId);
167
168 Sink::Store::create(sinkEvent).exec().waitForFinished();
169}
170
171static void createCalendar(const QVariantMap &object)
172{
173 using Sink::ApplicationDomain::Calendar;
174 using Sink::ApplicationDomain::ApplicationDomainType;
175
176 auto calendar = ApplicationDomainType::createEntity<Calendar>(object["resource"].toByteArray());
177 calendar.setName(object["name"].toString());
178 Sink::Store::create(calendar).exec().waitForFinished();
179
180 auto calendarId = calendar.identifier();
181 iterateOverObjects(object.value("events").toList(),
182 [calendarId](const QVariantMap &object) { createEvent(object, calendarId); });
183}
184
127void TestStore::setup(const QVariantMap &map) 185void TestStore::setup(const QVariantMap &map)
128{ 186{
129 using namespace Sink::ApplicationDomain; 187 using namespace Sink::ApplicationDomain;
@@ -143,6 +201,9 @@ void TestStore::setup(const QVariantMap &map)
143 } else if (object["type"] == "mailtransport") { 201 } else if (object["type"] == "mailtransport") {
144 resource.setResourceType("sink.mailtransport"); 202 resource.setResourceType("sink.mailtransport");
145 resource.setProperty("testmode", true); 203 resource.setProperty("testmode", true);
204 } else if (object["type"] == "caldav") {
205 resource.setResourceType("sink.caldav");
206 resource.setProperty("testmode", true);
146 } else { 207 } else {
147 Q_ASSERT(false); 208 Q_ASSERT(false);
148 } 209 }
@@ -166,6 +227,8 @@ void TestStore::setup(const QVariantMap &map)
166 createMail(map); 227 createMail(map);
167 }); 228 });
168 229
230 iterateOverObjects(map.value("calendars").toList(), createCalendar);
231
169 Sink::ResourceControl::flushMessageQueue(resources).exec().waitForFinished(); 232 Sink::ResourceControl::flushMessageQueue(resources).exec().waitForFinished();
170} 233}
171 234
diff --git a/views/calendar/main.qml b/views/calendar/main.qml
index 3cce9adf..672e3e21 100644
--- a/views/calendar/main.qml
+++ b/views/calendar/main.qml
@@ -32,15 +32,40 @@ ApplicationWindow {
32 Component.onCompleted: { 32 Component.onCompleted: {
33 var initialState = { 33 var initialState = {
34 accounts: [{ 34 accounts: [{
35 id: "account1", 35 id: "account1",
36 name: "Test Account" 36 name: "Test Account"
37 }], 37 }],
38 identities: [{ 38 identities: [{
39 account: "account1", 39 account: "account1",
40 name: "Test Identity", 40 name: "Test Identity",
41 address: "identity@example.org" 41 address: "identity@example.org"
42 }], 42 }],
43 resources: [] 43 resources: [{
44 id: "caldavresource",
45 account: "account1",
46 type: "caldav",
47 }],
48 calendars: [{
49 id: "calendar1",
50 resource: "caldavresource",
51 name: "Test Calendar",
52 events: [
53 {
54 resource: "caldavresource",
55 summary: "Test Event1",
56 description: "This is test event #1",
57 starts: "2018-04-10T14:03:00",
58 ends: "2018-04-10T17:03:00",
59 },
60 {
61 resource: "caldavresource",
62 summary: "Test Event2",
63 description: "This is test event #2",
64 starts: "2018-04-11T09:03:00",
65 ends: "2018-04-11T14:03:00",
66 },
67 ],
68 }],
44 } 69 }
45 TestStore.setup(initialState) 70 TestStore.setup(initialState)
46 } 71 }