Add SortedActivityListModel test
authorClaudio Cambra <claudio.cambra@nextcloud.com>
Wed, 1 Mar 2023 11:26:29 +0000 (12:26 +0100)
committerClaudio Cambra <claudio.cambra@nextcloud.com>
Tue, 25 Jul 2023 00:40:27 +0000 (08:40 +0800)
Signed-off-by: Claudio Cambra <claudio.cambra@nextcloud.com>
test/CMakeLists.txt
test/testsortedactivitylistmodel.cpp [new file with mode: 0644]

index 8a9d245b4c0186633e2c927a908249a92b80824a..69ebc08d518b469638e09cd4796e5277d98c9090 100644 (file)
@@ -64,6 +64,7 @@ nextcloud_add_test(IconUtils)
 nextcloud_add_test(SetUserStatusDialog)
 nextcloud_add_test(UnifiedSearchListmodel)
 nextcloud_add_test(ActivityListModel)
+nextcloud_add_test(SortedActivityListModel)
 nextcloud_add_test(ActivityData)
 nextcloud_add_test(TalkReply)
 nextcloud_add_test(LockFile)
diff --git a/test/testsortedactivitylistmodel.cpp b/test/testsortedactivitylistmodel.cpp
new file mode 100644 (file)
index 0000000..7a3f6b1
--- /dev/null
@@ -0,0 +1,89 @@
+/*
+ * Copyright (C) by Claudio Cambra <claudio.cambra@nextcloud.com>
+ *
+ * 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.
+ */
+
+#include "activitylistmodeltestutils.h"
+#include "syncenginetestutils.h"
+#include "syncresult.h"
+#include "tray/sortedactivitylistmodel.h"
+
+#include <QAbstractItemModelTester>
+#include <QDesktopServices>
+#include <QSignalSpy>
+#include <QTest>
+
+using namespace ActivityListModelTestUtils;
+
+class TestSortedActivityListModel : public QObject
+{
+    Q_OBJECT
+
+public:
+    TestSortedActivityListModel() = default;
+    ~TestSortedActivityListModel() override
+    {
+        OCC::AccountManager::instance()->deleteAccount(accountState.data());
+    }
+
+    QScopedPointer<FakeQNAM> fakeQnam;
+    OCC::AccountPtr account;
+    QScopedPointer<OCC::AccountState> accountState;
+
+    OCC::Activity testNotificationActivity;
+    OCC::Activity testSyncResultErrorActivity;
+    OCC::Activity testSyncFileItemActivity;
+    OCC::Activity testFileIgnoredActivity;
+
+    QSharedPointer<OCC::SortedActivityListModel> testingSortedALM() {
+        const auto model = new TestingALM;
+        model->setAccountState(accountState.data());
+
+        QSharedPointer<OCC::SortedActivityListModel> sortedModel(new OCC::SortedActivityListModel);
+        QAbstractItemModelTester sortedModelTester(sortedModel.data());
+
+        return sortedModel;
+    }
+
+private slots:
+    void initTestCase()
+    {
+        fakeQnam.reset(new FakeQNAM({}));
+        account = OCC::Account::create();
+        account->setCredentials(new FakeCredentials{fakeQnam.data()});
+        account->setUrl(QUrl(("http://example.de")));
+
+        accountState.reset(new OCC::AccountState(account));
+
+        fakeQnam->setOverride([this](QNetworkAccessManager::Operation op, const QNetworkRequest &req, QIODevice *device) {
+            Q_UNUSED(device)
+            return almTestQnamOverride(fakeQnam.data(),
+                                       op,
+                                       req,
+                                       accountState->account()->url().toString(),
+                                       this);
+        });
+
+        OCC::AccountManager::instance()->addAccount(account);
+
+        const auto accName = accountState->account()->displayName();
+        const auto accUrl = accountState->account()->url();
+
+        testNotificationActivity = exampleNotificationActivity(accName);
+        testSyncResultErrorActivity = exampleSyncResultErrorActivity(accName);
+        testSyncFileItemActivity = exampleSyncFileItemActivity(accName, accUrl);
+        testFileIgnoredActivity = exampleFileIgnoredActivity(accName, accUrl);
+    };
+};
+
+QTEST_MAIN(TestSortedActivityListModel)
+#include "testsortedactivitylistmodel.moc"