зеркало из https://github.com/nextcloud/desktop.git
Move TestingALM to activitylistmodeltestutils
Signed-off-by: Claudio Cambra <claudio.cambra@nextcloud.com>
This commit is contained in:
Родитель
00ac5a4568
Коммит
1c16728cb0
|
@ -6,13 +6,13 @@ set(CMAKE_AUTOMOC TRUE)
|
|||
|
||||
add_library(testutils
|
||||
STATIC
|
||||
activitylistmodeltestutils.cpp
|
||||
syncenginetestutils.cpp
|
||||
pushnotificationstestutils.cpp
|
||||
themeutils.cpp
|
||||
testhelper.cpp
|
||||
sharetestutils.cpp
|
||||
endtoendtestutils.cpp
|
||||
activitylistmodeltestutils.cpp
|
||||
)
|
||||
|
||||
target_link_libraries(testutils PUBLIC Nextcloud::sync Qt5::Test)
|
||||
|
|
|
@ -323,3 +323,50 @@ int FakeRemoteActivityStorage::startingIdLast() const
|
|||
{
|
||||
return _startingId;
|
||||
}
|
||||
|
||||
|
||||
void TestingALM::startFetchJob()
|
||||
{
|
||||
auto *job = new OCC::JsonApiJob(
|
||||
accountState()->account(), QLatin1String("ocs/v2.php/apps/activity/api/v2/activity"), this);
|
||||
QObject::connect(this, &TestingALM::activityJobStatusCode, this, &TestingALM::slotProcessReceivedActivities);
|
||||
QObject::connect(job, &OCC::JsonApiJob::jsonReceived, this, &TestingALM::activitiesReceived);
|
||||
|
||||
QUrlQuery params;
|
||||
params.addQueryItem(QLatin1String("since"), QString::number(currentItem()));
|
||||
params.addQueryItem(QLatin1String("limit"), QString::number(50));
|
||||
job->addQueryParams(params);
|
||||
|
||||
setAndRefreshCurrentlyFetching(true);
|
||||
job->start();
|
||||
}
|
||||
|
||||
void TestingALM::slotProcessReceivedActivities()
|
||||
{
|
||||
if (rowCount() > _numRowsPrev) {
|
||||
auto finalListCopy = finalList();
|
||||
for (int i = _numRowsPrev; i < rowCount(); ++i) {
|
||||
const auto modelIndex = index(i, 0);
|
||||
auto activity = finalListCopy.at(modelIndex.row());
|
||||
if (activity._links.isEmpty()) {
|
||||
const auto activityJsonObject = FakeRemoteActivityStorage::instance()->activityById(activity._id);
|
||||
|
||||
if (!activityJsonObject.isNull()) {
|
||||
// because "_links" are normally populated within the notificationhandler.cpp, which we don't run as part of this unit test, we have to fill them here
|
||||
// TODO: move the logic to populate "_links" to "activitylistmodel.cpp"
|
||||
auto actions = activityJsonObject.toObject().value("actions").toArray();
|
||||
foreach (auto action, actions) {
|
||||
activity._links.append(OCC::ActivityLink::createFomJsonObject(action.toObject()));
|
||||
}
|
||||
|
||||
finalListCopy[modelIndex.row()] = activity;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
setFinalList(finalListCopy);
|
||||
}
|
||||
_numRowsPrev = rowCount();
|
||||
setAndRefreshCurrentlyFetching(false);
|
||||
emit activitiesProcessed();
|
||||
}
|
||||
|
|
|
@ -15,6 +15,12 @@
|
|||
#include <QJsonArray>
|
||||
#include <QVariantMap>
|
||||
|
||||
#include "gui/tray/activitylistmodel.h"
|
||||
|
||||
#include "libsync/account.h"
|
||||
#include "gui/accountstate.h"
|
||||
#include "gui/accountmanager.h"
|
||||
|
||||
#pragma once
|
||||
|
||||
class QByteArray;
|
||||
|
@ -46,3 +52,22 @@ private:
|
|||
|
||||
static FakeRemoteActivityStorage *_instance;
|
||||
};
|
||||
|
||||
class TestingALM : public OCC::ActivityListModel
|
||||
{
|
||||
Q_OBJECT
|
||||
|
||||
public:
|
||||
TestingALM() = default;
|
||||
|
||||
void startFetchJob() override;
|
||||
|
||||
public slots:
|
||||
void slotProcessReceivedActivities();
|
||||
|
||||
signals:
|
||||
void activitiesProcessed();
|
||||
|
||||
private:
|
||||
int _numRowsPrev = 0;
|
||||
};
|
||||
|
|
|
@ -12,11 +12,6 @@
|
|||
* for more details.
|
||||
*/
|
||||
|
||||
#include "gui/tray/activitylistmodel.h"
|
||||
|
||||
#include "account.h"
|
||||
#include "accountstate.h"
|
||||
#include "accountmanager.h"
|
||||
#include "activitylistmodeltestutils.h"
|
||||
#include "syncenginetestutils.h"
|
||||
#include "syncresult.h"
|
||||
|
@ -38,66 +33,6 @@ static QByteArray fake500Response = R"(
|
|||
{"ocs":{"meta":{"status":"failure","statuscode":500,"message":"Internal Server Error.\n"},"data":[]}}
|
||||
)";
|
||||
|
||||
class TestingALM : public OCC::ActivityListModel
|
||||
{
|
||||
Q_OBJECT
|
||||
|
||||
public:
|
||||
TestingALM() = default;
|
||||
|
||||
void startFetchJob() override
|
||||
{
|
||||
auto *job = new OCC::JsonApiJob(
|
||||
accountState()->account(), QLatin1String("ocs/v2.php/apps/activity/api/v2/activity"), this);
|
||||
QObject::connect(this, &TestingALM::activityJobStatusCode, this, &TestingALM::slotProcessReceivedActivities);
|
||||
QObject::connect(job, &OCC::JsonApiJob::jsonReceived, this, &TestingALM::activitiesReceived);
|
||||
|
||||
QUrlQuery params;
|
||||
params.addQueryItem(QLatin1String("since"), QString::number(currentItem()));
|
||||
params.addQueryItem(QLatin1String("limit"), QString::number(50));
|
||||
job->addQueryParams(params);
|
||||
|
||||
setAndRefreshCurrentlyFetching(true);
|
||||
job->start();
|
||||
}
|
||||
|
||||
public slots:
|
||||
void slotProcessReceivedActivities()
|
||||
{
|
||||
if (rowCount() > _numRowsPrev) {
|
||||
auto finalListCopy = finalList();
|
||||
for (int i = _numRowsPrev; i < rowCount(); ++i) {
|
||||
const auto modelIndex = index(i, 0);
|
||||
auto activity = finalListCopy.at(modelIndex.row());
|
||||
if (activity._links.isEmpty()) {
|
||||
const auto activityJsonObject = FakeRemoteActivityStorage::instance()->activityById(activity._id);
|
||||
|
||||
if (!activityJsonObject.isNull()) {
|
||||
// because "_links" are normally populated within the notificationhandler.cpp, which we don't run as part of this unit test, we have to fill them here
|
||||
// TODO: move the logic to populate "_links" to "activitylistmodel.cpp"
|
||||
auto actions = activityJsonObject.toObject().value("actions").toArray();
|
||||
foreach (auto action, actions) {
|
||||
activity._links.append(OCC::ActivityLink::createFomJsonObject(action.toObject()));
|
||||
}
|
||||
|
||||
finalListCopy[modelIndex.row()] = activity;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
setFinalList(finalListCopy);
|
||||
}
|
||||
_numRowsPrev = rowCount();
|
||||
setAndRefreshCurrentlyFetching(false);
|
||||
emit activitiesProcessed();
|
||||
}
|
||||
signals:
|
||||
void activitiesProcessed();
|
||||
|
||||
private:
|
||||
int _numRowsPrev = 0;
|
||||
};
|
||||
|
||||
class TestActivityListModel : public QObject
|
||||
{
|
||||
Q_OBJECT
|
||||
|
|
Загрузка…
Ссылка в новой задаче