From 107e60448ec89883e60905f5a1cef507c0bf9fc2 Mon Sep 17 00:00:00 2001 From: Christian Mollekopf Date: Wed, 10 Jan 2018 17:10:10 +0100 Subject: 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). --- tests/CMakeLists.txt | 10 +++++- tests/kubetestrunner.cpp | 11 ------- tests/qmldir | 3 ++ tests/testplugin.cpp | 50 ++++++++++++++++++++++++++++++ tests/teststore.cpp | 17 +++++++++- views/conversation/main.qml | 75 +++++++++++++++++++++++++++++++++++++++++++++ 6 files changed, 153 insertions(+), 13 deletions(-) create mode 100644 tests/qmldir create mode 100644 tests/testplugin.cpp create mode 100644 views/conversation/main.qml 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) find_package(Sink CONFIG REQUIRED) find_package(KAsync CONFIG REQUIRED) -add_executable(kubetestrunner kubetestrunner.cpp teststore.cpp) +add_executable(kubetestrunner kubetestrunner.cpp) target_link_libraries(kubetestrunner Qt5::QuickTest Qt5::Quick sink kubeframework ) + +install(FILES qmldir DESTINATION ${QML_INSTALL_DIR}/org/kube/test) + +add_library(testplugin SHARED testplugin.cpp teststore.cpp) +target_link_libraries(testplugin + kubeframework +) +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 @@ #include #include #include -#include "teststore.h" - -static QObject *teststore(QQmlEngine *engine, QJSEngine *scriptEngine) -{ - Q_UNUSED(engine) - Q_UNUSED(scriptEngine) - return new Kube::TestStore; -} int main(int argc, char **argv) { QCoreApplication::setAttribute(Qt::AA_ShareOpenGLContexts, true); - Sink::Test::initTest(); - - qmlRegisterSingletonType("org.kube.test", 1, 0, "TestStore", teststore); QTEST_ADD_GPU_BLACKLIST_SUPPORT 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 @@ +module org.kube.test + +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 @@ +/* + Copyright (c) 2018 Christian Mollekopf + + This library is free software; you can redistribute it and/or modify it + under the terms of the GNU Library General Public License as published by + the Free Software Foundation; either version 2 of the License, or (at your + option) any later version. + + This library is distributed in the hope that it will be useful, but WITHOUT + ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + FITNESS FOR A PARTICULAR PURPOSE. See the GNU Library General Public + License for more details. + + You should have received a copy of the GNU Library General Public License + along with this library; see the file COPYING.LIB. If not, write to the + Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA + 02110-1301, USA. +*/ + +#include +#include +#include +#include + +#include "teststore.h" + +class TestPlugin : public QQmlExtensionPlugin +{ + Q_OBJECT + Q_PLUGIN_METADATA(IID "org.qt-project.Qt.QQmlExtensionInterface") + +public: + void initializeEngine(QQmlEngine *engine, const char *uri) Q_DECL_OVERRIDE + { + Q_UNUSED(engine); + Q_UNUSED(uri); + Sink::Test::initTest(); + } + + void registerTypes (const char *uri) Q_DECL_OVERRIDE + { + qmlRegisterSingletonType(uri, 1, 0, "TestStore", [] (QQmlEngine *, QJSEngine *) -> QObject* { + return new Kube::TestStore; + }); + } +}; + + + +#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) auto mail = ApplicationDomainType::createEntity(object["resource"].toByteArray()); mail.setMimeMessage(msg->encodedContent(true)); - Sink::Store::create(mail).exec().waitForFinished(); + Sink::Store::create(mail).exec().waitForFinished(); +} + +static void createFolder(const QVariantMap &object) +{ + using namespace Sink::ApplicationDomain; + auto folder = ApplicationDomainType::createEntity(object["resource"].toByteArray()); + folder.setName(object["name"].toString()); + Sink::Store::create(folder).exec().waitForFinished(); } void TestStore::setup(const QVariantMap &map) { + using namespace Sink::ApplicationDomain; + iterateOverObjects(map.value("accounts").toList(), [&] (const QVariantMap &object) { + auto account = ApplicationDomainType::createEntity("", object["id"].toByteArray()); + account.setName(object["name"].toString()); + Sink::Store::create(account).exec().waitForFinished(); + }); QByteArrayList resources; iterateOverObjects(map.value("resources").toList(), [&] (const QVariantMap &object) { resources << object["id"].toByteArray(); @@ -104,6 +118,7 @@ void TestStore::setup(const QVariantMap &map) Sink::Store::create(identity).exec().waitForFinished(); }); + iterateOverObjects(map.value("folders").toList(), createFolder); iterateOverObjects(map.value("mails").toList(), createMail); 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 @@ +/* + * Copyright (C) 2018 Christian Mollekopf, + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License along + * with this program; if not, write to the Free Software Foundation, Inc., + * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. + */ + +import QtQuick 2.7 +import QtQuick.Controls 2.0 +import QtQuick.Window 2.0 + +import org.kube.framework 1.0 as Kube +import org.kube.test 1.0 +import "qml" + +ApplicationWindow { + id: app + height: Screen.desktopAvailableHeight * 0.8 + width: Screen.desktopAvailableWidth * 0.8 + + Component.onCompleted: { + var initialState = { + accounts: [{ + id: "account1", + name: "Test Account" + }], + identities: [{ + account: "account1", + name: "Test Identity", + address: "identity@example.org" + }], + resources: [{ + id: "resource1", + account: "account1", + type: "dummy" + }, + { + id: "resource2", + account: "account1", + type: "mailtransport" + }], + folders: [{ + id: "folder1", + resource: "resource1", + name: "Folder 1" + }], + mails: [{ + resource: "resource1", + folder: "folder1", + subject: "subject", + body: "body", + to: ["to@example.org"], + cc: ["cc@example.org"], + bcc: ["bcc@example.org"], + draft: true + }] + } + TestStore.setup(initialState) + } + + View { + anchors.fill: parent + } +} -- cgit v1.2.3