Make accountstate fakeable for tests
authorClaudio Cambra <claudio.cambra@nextcloud.com>
Wed, 16 Nov 2022 19:55:53 +0000 (20:55 +0100)
committerClaudio Cambra <claudio.cambra@nextcloud.com>
Tue, 24 Jan 2023 16:00:14 +0000 (17:00 +0100)
Signed-off-by: Claudio Cambra <claudio.cambra@nextcloud.com>
src/gui/accountstate.h
test/testhelper.h

index 4e0621e3336e3a2dfe59f12f1ba4c3c27d81783e..2f46f9a8618e490241ed8444ffc218182f984055 100644 (file)
@@ -27,6 +27,7 @@
 #include <memory>
 
 class QSettings;
+class FakeAccountState;
 
 namespace OCC {
 
@@ -182,10 +183,10 @@ public:
 public slots:
     /// Triggers a ping to the server to update state and
     /// connection status and errors.
-    void checkConnectivity();
+    virtual void checkConnectivity();
 
 private:
-    void setState(State state);
+    virtual void setState(State state);
     void fetchNavigationApps();
 
     int retryCount() const;
@@ -261,6 +262,9 @@ private:
     QTimer _checkConnectionTimer;
     QElapsedTimer _lastCheckConnectionTimer;
 
+    explicit AccountState() = default;
+
+    friend class ::FakeAccountState;
 };
 
 class AccountApp : public QObject
index 2ddb859e599d4fe9f0faf4a57725f1ce2ac65d74..24a89c29854d16cf6c0a6d4c8b92a88fe24dae98 100644 (file)
@@ -1,6 +1,7 @@
 #ifndef TESTHELPER_H
 #define TESTHELPER_H
 
+#include "gui/accountstate.h"
 #include "gui/folder.h"
 #include "creds/httpcredentials.h"
 
@@ -18,6 +19,26 @@ public:
 
 OCC::FolderDefinition folderDefinition(const QString &path);
 
+class FakeAccountState : public OCC::AccountState
+{
+    Q_OBJECT
+
+public:
+    explicit FakeAccountState(OCC::AccountPtr account)
+        : OCC::AccountState()
+    {
+        _account = account;
+        _state = Connected;
+    }
+
+public slots:
+    void checkConnectivity() override {};
+
+private slots:
+    void setState(OCC::AccountState::State state) override { Q_UNUSED(state) };
+};
+
+
 const QByteArray jsonValueToOccReply(const QJsonValue &jsonValue);
 
 #endif // TESTHELPER_H