diff --git a/tests/featurelib/zanshincontext.h b/tests/featurelib/zanshincontext.h --- a/tests/featurelib/zanshincontext.h +++ b/tests/featurelib/zanshincontext.h @@ -28,6 +28,7 @@ #include #include "domain/task.h" +#include "domain/datasource.h" #include "presentation/errorhandler.h" #include "testlib/akonadifakedata.h" @@ -75,7 +76,7 @@ Q_REQUIRED_RESULT bool I_remove_the_item(); Q_REQUIRED_RESULT bool I_promote_the_item(); Q_REQUIRED_RESULT bool I_add_a_project(const QString &projectName, const QString &parentSourceName); - Q_REQUIRED_RESULT bool I_add_a_context(const QString &contextName); + Q_REQUIRED_RESULT bool I_add_a_context(const QString &contextName, const QString &parentSourceName); Q_REQUIRED_RESULT bool I_add_a_task(const QString &taskName); Q_REQUIRED_RESULT bool I_rename_a_page(const QString &path, const QString &oldName, const QString &newName); Q_REQUIRED_RESULT bool I_remove_a_page(const QString &path, const QString &pageName); @@ -110,6 +111,7 @@ QAbstractItemModel *model() const; Domain::Task::Ptr currentTask() const; + Domain::DataSource::Ptr dataSourceFromName(const QString &sourceName); void waitForEmptyJobQueue(); void waitForStableState(); diff --git a/tests/featurelib/zanshincontext.cpp b/tests/featurelib/zanshincontext.cpp --- a/tests/featurelib/zanshincontext.cpp +++ b/tests/featurelib/zanshincontext.cpp @@ -92,6 +92,11 @@ auto loader = Testlib::AkonadiFakeDataXmlLoader(&m_data); loader.load(xmlFile); + // Sanity checks + QVERIFY(m_data.collections().size() > 1); + QVERIFY(m_data.items().size() > 1); + QVERIFY(m_data.contexts().size() > 1); + // Swap regular dependencies for the fake data ones auto &deps = Utils::DependencyManager::globalInstance(); deps.addproperty("availableSources").value(); - VERIFY(availableSources); - auto sourceList = availableSources->property("sourceListModel").value(); - VERIFY(sourceList); - waitForStableState(); - QModelIndex index = Zanshin::findIndex(sourceList, parentSourceName); - VERIFY(index.isValid()); - auto source = index.data(Presentation::QueryTreeModelBase::ObjectRole) - .value(); + auto source = dataSourceFromName(parentSourceName); VERIFY(source); VERIFY(QMetaObject::invokeMethod(m_presentation, "addProject", @@ -449,13 +446,15 @@ return true; } -bool ZanshinContext::I_add_a_context(const QString &contextName) +bool ZanshinContext::I_add_a_context(const QString &contextName, const QString &parentSourceName) { - waitForStableState(); + auto source = dataSourceFromName(parentSourceName); + VERIFY(source); VERIFY(QMetaObject::invokeMethod(m_presentation, "addContext", - Q_ARG(QString, contextName))); + Q_ARG(QString, contextName), + Q_ARG(Domain::DataSource::Ptr, source))); waitForStableState(); return true; @@ -846,3 +845,24 @@ return true; } + +Domain::DataSource::Ptr ZanshinContext::dataSourceFromName(const QString &sourceName) +{ + auto availableSources = m_appModel->property("availableSources").value(); + if (!availableSources) + return nullptr; + auto sourceList = availableSources->property("sourceListModel").value(); + if (!sourceList) + return nullptr; + waitForStableState(); + QModelIndex index = Zanshin::findIndex(sourceList, sourceName); + if (!index.isValid()) { + qWarning() << "source" << sourceName << "not found."; + for (int row = 0; row < sourceList->rowCount(); row++) { + qDebug() << sourceList->index(row, 0).data().toString(); + } + return nullptr; + } + return index.data(Presentation::QueryTreeModelBase::ObjectRole) + .value(); +} diff --git a/tests/features/contexts/contextaddfeature.cpp b/tests/features/contexts/contextaddfeature.cpp --- a/tests/features/contexts/contextaddfeature.cpp +++ b/tests/features/contexts/contextaddfeature.cpp @@ -39,7 +39,7 @@ { ZanshinContext c; Given(c.I_display_the_available_pages()); - When(c.I_add_a_context("Internet")); + When(c.I_add_a_context("Internet", "TestData / Calendar1")); And(c.I_list_the_items()); Then(c.the_list_is({ { "display", "icon" }, diff --git a/tests/features/testenv/data/testdata.xml b/tests/features/testenv/data/testdata.xml --- a/tests/features/testenv/data/testdata.xml +++ b/tests/features/testenv/data/testdata.xml @@ -17,10 +17,10 @@ SUMMARY:Buy kiwis DUE;VALUE=DATE:20150310 PERCENT-COMPLETE:0 +X-KDE-Zanshin-ContextList:errands-context END:VTODO END:VCALENDAR - errands-context BEGIN:VCALENDAR @@ -76,11 +76,11 @@ ACTION:DISPLAY TRIGGER;VALUE=DURATION:-PT15M X-KDE-KCALCORE-ENABLED:TRUE +X-KDE-Zanshin-ContextList:online-context END:VALARM END:VEVENT END:VCALENDAR - online-context BEGIN:VCALENDAR @@ -182,7 +182,6 @@ END:VTODO END:VCALENDAR - philosophy-tag @@ -327,6 +326,37 @@ END:VCALENDAR + + BEGIN:VCALENDAR +PRODID:-//K Desktop Environment//NONSGML libkcal 4.3//EN +VERSION:2.0 +X-KDE-ICAL-IMPLEMENTATION-VERSION:1.0 +BEGIN:VTODO +CREATED:20190317T162551Z +UID:errands-context +X-KDE-Zanshin-Context:1 +LAST-MODIFIED:20140317T162551Z +SUMMARY:Errands +END:VTODO + +END:VCALENDAR + + + BEGIN:VCALENDAR +PRODID:-//K Desktop Environment//NONSGML libkcal 4.3//EN +VERSION:2.0 +X-KDE-ICAL-IMPLEMENTATION-VERSION:1.0 +BEGIN:VTODO +CREATED:20190317T162551Z +UID:online-context +X-KDE-Zanshin-Context:1 +LAST-MODIFIED:20140317T162551Z +SUMMARY:Online +END:VTODO + +END:VCALENDAR + + a false @@ -359,7 +389,6 @@ MIME-Version: 1.0 This is a note - physics-tag Subject: A note about philosophy @@ -370,7 +399,6 @@ MIME-Version: 1.0 This is a smart note - philosophy-tag Subject: A note about nothing interesting @@ -403,8 +431,4 @@ a - - - - diff --git a/tests/testlib/akonadifakedata.cpp b/tests/testlib/akonadifakedata.cpp --- a/tests/testlib/akonadifakedata.cpp +++ b/tests/testlib/akonadifakedata.cpp @@ -323,7 +323,6 @@ const QStringList contextUids = extractContextUids(item); foreach (const auto &contextUid, contextUids) { - Q_ASSERT(m_contexts.contains(contextUid)); m_contextItems[contextUid] << item.id(); } diff --git a/tests/testlib/akonadistoragetestbase.cpp b/tests/testlib/akonadistoragetestbase.cpp --- a/tests/testlib/akonadistoragetestbase.cpp +++ b/tests/testlib/akonadistoragetestbase.cpp @@ -141,7 +141,9 @@ { // GIVEN auto storage = createStorage(); - const QStringList expectedRemoteIds = { "{1d33862f-f274-4c67-ab6c-362d56521ff4}", + const QStringList expectedRemoteIds = { "rid-errands-context", + "rid-online-context", + "{1d33862f-f274-4c67-ab6c-362d56521ff4}", "{1d33862f-f274-4c67-ab6c-362d56521ff5}", "{1d33862f-f274-4c67-ab6c-362d56521ff6}", "{7824df00-2fd6-47a4-8319-52659dc82005}", @@ -158,11 +160,17 @@ QStringList itemRemoteIds; itemRemoteIds.reserve(items.size()); foreach (const auto &item, items) { - itemRemoteIds << item.remoteId(); + const auto rid = item.remoteId(); + itemRemoteIds << rid; QVERIFY(item.loadedPayloadParts().contains(Akonadi::Item::FullPayload)); - QVERIFY(!item.attributes().isEmpty()); QVERIFY(item.modificationTime().isValid()); - QVERIFY(!item.flags().isEmpty()); + if (rid.endsWith("context")) { + QVERIFY2(item.attributes().isEmpty(), qPrintable(rid)); + QVERIFY2(item.flags().isEmpty(), qPrintable(rid)); + } else { + QVERIFY2(!item.attributes().isEmpty(), qPrintable(rid)); + QVERIFY2(!item.flags().isEmpty(), qPrintable(rid)); + } auto parent = item.parentCollection(); while (parent != Akonadi::Collection::root()) { diff --git a/tests/units/akonadi/testenv/data/testdata.xml b/tests/units/akonadi/testenv/data/testdata.xml --- a/tests/units/akonadi/testenv/data/testdata.xml +++ b/tests/units/akonadi/testenv/data/testdata.xml @@ -158,12 +158,12 @@ LAST-MODIFIED:20111214T031148Z SUMMARY:Buy apples PERCENT-COMPLETE:0 +X-KDE-Zanshin-ContextList:errands-context END:VTODO END:VCALENDAR foo \SEEN - errands-context BEGIN:VCALENDAR @@ -176,13 +176,13 @@ UID:144e86e5-a169-4c89-8ad0-fdd0b2a948e1 LAST-MODIFIED:20111214T031148Z SUMMARY:Buy apples +X-KDE-Zanshin-ContextList:errands-context PERCENT-COMPLETE:0 END:VTODO END:VCALENDAR foo \SEEN - philosophy-tag BEGIN:VCALENDAR @@ -202,7 +202,6 @@ END:VCALENDAR bar \SEEN - errands-context BEGIN:VCALENDAR @@ -222,7 +221,6 @@ END:VCALENDAR bar \SEEN - change-me BEGIN:VCALENDAR @@ -243,7 +241,6 @@ END:VCALENDAR bar \SEEN - change-me BEGIN:VCALENDAR @@ -263,8 +260,39 @@ END:VCALENDAR bar \SEEN - change-me + + + BEGIN:VCALENDAR +PRODID:-//K Desktop Environment//NONSGML libkcal 4.3//EN +VERSION:2.0 +X-KDE-ICAL-IMPLEMENTATION-VERSION:1.0 +BEGIN:VTODO +CREATED:20190317T162551Z +UID:errands-context +X-KDE-Zanshin-Context:1 +LAST-MODIFIED:20140317T162551Z +SUMMARY:Errands +END:VTODO + +END:VCALENDAR + + + BEGIN:VCALENDAR +PRODID:-//K Desktop Environment//NONSGML libkcal 4.3//EN +VERSION:2.0 +X-KDE-ICAL-IMPLEMENTATION-VERSION:1.0 +BEGIN:VTODO +CREATED:20190317T162551Z +UID:online-context +X-KDE-Zanshin-Context:1 +LAST-MODIFIED:20140317T162551Z +SUMMARY:Online +END:VTODO + +END:VCALENDAR + + a @@ -317,10 +345,4 @@ - - - - - - diff --git a/tests/units/testlib/akonadifakedataxmlloadertest.cpp b/tests/units/testlib/akonadifakedataxmlloadertest.cpp --- a/tests/units/testlib/akonadifakedataxmlloadertest.cpp +++ b/tests/units/testlib/akonadifakedataxmlloadertest.cpp @@ -24,6 +24,8 @@ #include "testlib/akonadifakedata.h" #include "testlib/akonadifakedataxmlloader.h" +#include + #include class AkonadiFakeDataXmlLoaderTest : public QObject @@ -76,6 +78,13 @@ QCOMPARE(children.at(4).name(), QStringLiteral("Change me!")); QCOMPARE(children.at(4).id(), qint64(7)); QCOMPARE(children.at(4).remoteId(), QStringLiteral("{28ef9f03-4ebc-4e33-970f-f379775894f9}")); + + const auto firstContext = data.contexts().at(0); + QCOMPARE(firstContext.remoteId(), "rid-online-context"); + const auto contextAsTodo = firstContext.payload(); + QCOMPARE(contextAsTodo->uid(), "online-context"); + QCOMPARE(contextAsTodo->summary(), "Online"); + QCOMPARE(contextAsTodo->customProperty("Zanshin", "Context"), "1"); } };