Эх сурвалжийг харах

Implement screenshot test for multiple accounts

Signed-off-by: ZetaTom <70907959+ZetaTom@users.noreply.github.com>
ZetaTom 1 жил өмнө
parent
commit
b264a86dd9

+ 29 - 14
app/src/androidTest/java/com/owncloud/android/AbstractIT.java

@@ -107,20 +107,8 @@ public abstract class AbstractIT {
                 }
             }
 
-            Account temp = new Account("test@https://nextcloud.localhost", MainApp.getAccountType(targetContext));
-            platformAccountManager.addAccountExplicitly(temp, "password", null);
-            platformAccountManager.setUserData(temp, AccountUtils.Constants.KEY_OC_BASE_URL, "https://nextcloud.localhost");
-            platformAccountManager.setUserData(temp, KEY_USER_ID, "test");
-
-            final UserAccountManager userAccountManager = UserAccountManagerImpl.fromContext(targetContext);
-            account = userAccountManager.getAccountByName("test@https://nextcloud.localhost");
-
-            if (account == null) {
-                throw new ActivityNotFoundException();
-            }
-
-            Optional<User> optionalUser = userAccountManager.getUser(account.name);
-            user = optionalUser.orElseThrow(IllegalAccessError::new);
+            account = createAccount("test@https://nextcloud.localhost");
+            user = getUser(account);
 
             client = OwnCloudClientFactory.createOwnCloudClient(account, targetContext);
             nextcloudClient = OwnCloudClientFactory.createNextcloudClient(user, targetContext);
@@ -447,4 +435,31 @@ public abstract class AbstractIT {
     public static String getUserId(User user) {
         return AccountManager.get(targetContext).getUserData(user.toPlatformAccount(), KEY_USER_ID);
     }
+
+    protected static User getUser(Account account) {
+        Optional<User> optionalUser = UserAccountManagerImpl.fromContext(targetContext).getUser(account.name);
+        return optionalUser.orElseThrow(IllegalAccessError::new);
+    }
+
+    protected static Account createAccount(String name) {
+        AccountManager platformAccountManager = AccountManager.get(targetContext);
+
+        Account temp = new Account(name, MainApp.getAccountType(targetContext));
+        int atPos = name.lastIndexOf('@');
+        platformAccountManager.addAccountExplicitly(temp, "password", null);
+        platformAccountManager.setUserData(temp, AccountUtils.Constants.KEY_OC_BASE_URL,
+                                           name.substring(atPos + 1));
+        platformAccountManager.setUserData(temp, KEY_USER_ID, name.substring(0, atPos));
+
+        Account account = UserAccountManagerImpl.fromContext(targetContext).getAccountByName(name);
+        if (account == null) {
+            throw new ActivityNotFoundException();
+        }
+        return account;
+    }
+
+    protected static boolean removeUser(User user) {
+        return UserAccountManagerImpl.fromContext(targetContext).removeUser(user);
+    }
+
 }

+ 8 - 0
app/src/androidTest/java/com/owncloud/android/ui/activity/ReceiveExternalFilesActivityIT.kt

@@ -38,4 +38,12 @@ class ReceiveExternalFilesActivityIT : AbstractIT() {
         val sut: Activity = activityRule.launchActivity(null)
         screenshot(sut)
     }
+
+    @Test
+    @ScreenshotTest
+    fun openMultiAccount() {
+        val secondUser = getUser(createAccount("secondtest@https://nextcloud.localhost"))
+        open()
+        removeUser(secondUser)
+    }
 }