From af2e92982b722ed0ea8f465649b843cb5ed4fda7 Mon Sep 17 00:00:00 2001 From: Christian Mollekopf Date: Wed, 24 Jan 2018 09:46:42 +0100 Subject: Tested account setup --- accounts/kolabnow/qml/AccountSettings.qml | 2 ++ components/accounts/qml/AccountWizard.qml | 1 + components/accounts/qml/AccountWizardPage.qml | 1 + tests/teststore.cpp | 51 +++++++++++++++++---------- tests/teststore.h | 1 + views/accounts/tests/tst_accountsview.qml | 38 +++++++++++++++++++- 6 files changed, 75 insertions(+), 19 deletions(-) diff --git a/accounts/kolabnow/qml/AccountSettings.qml b/accounts/kolabnow/qml/AccountSettings.qml index 4161bc49..35493bd1 100644 --- a/accounts/kolabnow/qml/AccountSettings.qml +++ b/accounts/kolabnow/qml/AccountSettings.qml @@ -56,6 +56,7 @@ Item { } Kube.RequiredTextField { id: nameField + objectName: "nameTextField" focus: true Layout.fillWidth: true placeholderText: qsTr("Your name") @@ -71,6 +72,7 @@ Item { } Kube.RequiredTextField { id: emailField + objectName: "emailTextField" Layout.fillWidth: true text: kolabnowSettings.emailAddress diff --git a/components/accounts/qml/AccountWizard.qml b/components/accounts/qml/AccountWizard.qml index 58ef4509..b928fd8b 100644 --- a/components/accounts/qml/AccountWizard.qml +++ b/components/accounts/qml/AccountWizard.qml @@ -70,6 +70,7 @@ Kube.Popup { Repeater { model: root.availableAccountPlugins delegate: Kube.Button { + objectName: "accountTypeButton" + modelData Layout.fillWidth: true text: modelData onClicked: stack.push(wizardPage.createObject(stack, {accountType:modelData})) diff --git a/components/accounts/qml/AccountWizardPage.qml b/components/accounts/qml/AccountWizardPage.qml index 9f11ac36..99bad388 100644 --- a/components/accounts/qml/AccountWizardPage.qml +++ b/components/accounts/qml/AccountWizardPage.qml @@ -146,6 +146,7 @@ FocusScope { right: parent.right bottom: parent.bottom } + objectName: "saveButton" text: qsTr("Save") onClicked: save() diff --git a/tests/teststore.cpp b/tests/teststore.cpp index 4716fa2e..07310640 100644 --- a/tests/teststore.cpp +++ b/tests/teststore.cpp @@ -157,27 +157,42 @@ void TestStore::setup(const QVariantMap &map) QVariant TestStore::load(const QByteArray &type, const QVariantMap &filter) { using namespace Sink::ApplicationDomain; + const auto list = loadList(type, filter); + if (!list.isEmpty()) { + return list.first(); + } + return {}; +} + +template +QVariantList toVariantList(const QList &list) +{ + QVariantList result; + std::transform(list.constBegin(), list.constEnd(), std::back_inserter(result), [] (const T &m) { + return QVariant::fromValue(T::Ptr::create(m)); + }); + Q_ASSERT(list.size() == result.size()); + return result; +} + +QVariantList TestStore::loadList(const QByteArray &type, const QVariantMap &filter) +{ + using namespace Sink::ApplicationDomain; + Sink::Query query; + if (filter.contains("resource")) { + query.resourceFilter(filter.value("resource").toByteArray()); + } if (type == "mail") { - Sink::Query query; - if (filter.contains("resource")) { - query.resourceFilter(filter.value("resource").toByteArray()); - } - auto list = Sink::Store::read(query); - if (!list.isEmpty()) { - return QVariant::fromValue(Mail::Ptr::create(list.first())); - } - return {}; + return toVariantList(Sink::Store::read(query)); } if (type == "folder") { - Sink::Query query; - if (filter.contains("resource")) { - query.resourceFilter(filter.value("resource").toByteArray()); - } - auto list = Sink::Store::read(query); - if (!list.isEmpty()) { - return QVariant::fromValue(Folder::Ptr::create(list.first())); - } - return {}; + return toVariantList(Sink::Store::read(query)); + } + if (type == "resource") { + return toVariantList(Sink::Store::read(query)); + } + if (type == "account") { + return toVariantList(Sink::Store::read(query)); } Q_ASSERT(false); diff --git a/tests/teststore.h b/tests/teststore.h index 5df20416..1a6a2563 100644 --- a/tests/teststore.h +++ b/tests/teststore.h @@ -28,6 +28,7 @@ class TestStore : public QObject { public: Q_INVOKABLE void setup(const QVariantMap &); Q_INVOKABLE QVariant load(const QByteArray &type, const QVariantMap &); + Q_INVOKABLE QVariantList loadList(const QByteArray &type, const QVariantMap &); Q_INVOKABLE QVariantMap read(const QVariant &); }; diff --git a/views/accounts/tests/tst_accountsview.qml b/views/accounts/tests/tst_accountsview.qml index c278136f..c280ea54 100644 --- a/views/accounts/tests/tst_accountsview.qml +++ b/views/accounts/tests/tst_accountsview.qml @@ -29,14 +29,50 @@ TestCase { name: "AccountsView" when: windowShown + function visitChildren(item) { + console.warn(item) + for (var i = 0; i < item.children.length; i++) { + visitChildren(item.children[i]) + } + } + Component { id: accountsComponent View { } } - function test_start() { + function test_1start() { + var accountsView = createTemporaryObject(accountsComponent, testCase, {}) + verify(accountsView) + } + + function test_2createAccount() { var accountsView = createTemporaryObject(accountsComponent, testCase, {}) verify(accountsView) + + var accountWizard = findChild(accountsView, "accountWizard"); + verify(accountWizard) + + var typeButton = findChild(accountWizard.contentItem, "accountTypeButton" + "kolabnow") + verify(typeButton) + typeButton.clicked() + + var name = findChild(accountWizard.contentItem, "nameTextField") + verify(name) + name.text = "Name" + + var email = findChild(accountWizard.contentItem, "emailTextField") + verify(email) + email.text = "email@test.com" + + var save = findChild(accountWizard.contentItem, "saveButton") + verify(save) + save.clicked() + + var accounts = TestStore.loadList("account", {}) + compare(accounts.length, 1) + var resources = TestStore.loadList("resource", {}) + compare(resources.length, 3) } } -- cgit v1.2.3