Browse Source

new tests for avatars, shares in OCFileList

Signed-off-by: tobiasKaminsky <tobias@kaminsky.me>
tobiasKaminsky 4 years ago
parent
commit
e0700c376c

BIN
screenshots/gplay/debug/com.owncloud.android.ui.fragment.AvatarIT_showAvatars.png


BIN
screenshots/gplay/debug/com.owncloud.android.ui.fragment.OCFileListFragmentStaticServerIT_showSharedFiles.png


+ 62 - 0
src/androidTest/java/com/owncloud/android/ui/fragment/AvatarIT.kt

@@ -0,0 +1,62 @@
+/*
+ *
+ * Nextcloud Android client application
+ *
+ * @author Tobias Kaminsky
+ * Copyright (C) 2020 Tobias Kaminsky
+ * Copyright (C) 2020 Nextcloud GmbH
+ *
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU Affero General Public License as published by
+ * the Free Software Foundation, either version 3 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 Affero General Public License for more details.
+ *
+ * You should have received a copy of the GNU Affero General Public License
+ * along with this program. If not, see <https://www.gnu.org/licenses/>.
+ */
+
+package com.owncloud.android.ui.fragment
+
+import androidx.test.espresso.intent.rule.IntentsTestRule
+import androidx.test.internal.runner.junit4.statement.UiThreadStatement.runOnUiThread
+import com.nextcloud.client.TestActivity
+import com.owncloud.android.AbstractIT
+import com.owncloud.android.R
+import com.owncloud.android.utils.DisplayUtils
+import com.owncloud.android.utils.ScreenshotTest
+import org.junit.Rule
+import org.junit.Test
+
+class AvatarIT : AbstractIT() {
+    @get:Rule
+    val testActivityRule = IntentsTestRule(TestActivity::class.java, true, false)
+
+    @Test
+    @ScreenshotTest
+    fun showAvatars() {
+        val avatarRadius = targetContext.resources.getDimension(R.dimen.list_item_avatar_icon_radius)
+        val width = DisplayUtils.convertDpToPixel(40f, targetContext)
+        val sut = testActivityRule.launchActivity(null)
+        val fragment = AvatarTestFragment()
+
+        sut.addFragment(fragment)
+
+        runOnUiThread {
+            fragment.addAvatar("Admin", avatarRadius, width, targetContext)
+            fragment.addAvatar("Test Server Admin", avatarRadius, width, targetContext)
+            fragment.addAvatar("Cormier Paulette", avatarRadius, width, targetContext)
+            fragment.addAvatar("winston brent", avatarRadius, width, targetContext)
+            fragment.addAvatar("Baker James Lorena", avatarRadius, width, targetContext)
+            fragment.addAvatar("Baker  James   Lorena", avatarRadius, width, targetContext)
+            fragment.addAvatar("email@server.com", avatarRadius, width, targetContext)
+        }
+
+        waitForIdleSync()
+        screenshot(sut)
+    }
+}

+ 59 - 0
src/androidTest/java/com/owncloud/android/ui/fragment/AvatarTestFragment.kt

@@ -0,0 +1,59 @@
+/*
+ *
+ * Nextcloud Android client application
+ *
+ * @author Tobias Kaminsky
+ * Copyright (C) 2020 Tobias Kaminsky
+ * Copyright (C) 2020 Nextcloud GmbH
+ *
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU Affero General Public License as published by
+ * the Free Software Foundation, either version 3 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 Affero General Public License for more details.
+ *
+ * You should have received a copy of the GNU Affero General Public License
+ * along with this program. If not, see <https://www.gnu.org/licenses/>.
+ */
+package com.owncloud.android.ui.fragment
+
+import android.content.Context
+import android.os.Bundle
+import android.view.LayoutInflater
+import android.view.View
+import android.view.ViewGroup
+import android.widget.ImageView
+import android.widget.LinearLayout
+import android.widget.RelativeLayout
+import androidx.fragment.app.Fragment
+import com.owncloud.android.R
+import com.owncloud.android.ui.TextDrawable
+
+internal class AvatarTestFragment : Fragment() {
+    lateinit var list: LinearLayout
+
+    override fun onCreateView(inflater: LayoutInflater, container: ViewGroup?, savedInstanceState: Bundle?): View? {
+        val view: View = inflater.inflate(R.layout.avatar_fragment, null)
+
+        list = view.findViewById(R.id.avatar_list)
+
+        return view
+    }
+
+    fun addAvatar(name: String, avatarRadius: Float, width: Int, targetContext: Context) {
+        val margin = 10
+        val imageView = ImageView(targetContext)
+        imageView.setImageDrawable(TextDrawable.createNamedAvatar(name, avatarRadius))
+
+        val layoutParams: RelativeLayout.LayoutParams = RelativeLayout.LayoutParams(width, width)
+        layoutParams.addRule(RelativeLayout.ALIGN_PARENT_RIGHT)
+        layoutParams.setMargins(margin, margin, margin, margin)
+        imageView.layoutParams = layoutParams
+
+        list.addView(imageView)
+    }
+}

+ 0 - 133
src/androidTest/java/com/owncloud/android/ui/fragment/OCFileListFragmentIT.kt

@@ -24,7 +24,6 @@ package com.owncloud.android.ui.fragment
 
 import android.Manifest
 import androidx.test.espresso.intent.rule.IntentsTestRule
-import androidx.test.platform.app.InstrumentationRegistry
 import androidx.test.rule.GrantPermissionRule
 import com.nextcloud.client.device.BatteryStatus
 import com.nextcloud.client.device.PowerManagementService
@@ -32,12 +31,7 @@ import com.nextcloud.client.network.Connectivity
 import com.nextcloud.client.network.ConnectivityService
 import com.owncloud.android.AbstractOnServerIT
 import com.owncloud.android.datamodel.OCFile
-import com.owncloud.android.lib.resources.shares.CreateShareRemoteOperation
-import com.owncloud.android.lib.resources.shares.OCShare
-import com.owncloud.android.lib.resources.shares.ShareType
-import com.owncloud.android.operations.CreateFolderOperation
 import com.owncloud.android.ui.activity.FileDisplayActivity
-import junit.framework.TestCase
 import org.junit.Assert.assertFalse
 import org.junit.Assert.assertTrue
 import org.junit.Rule
@@ -77,133 +71,6 @@ class OCFileListFragmentIT : AbstractOnServerIT() {
             get() = BatteryStatus()
     }
 
-    @Test
-    // @ScreenshotTest // todo run without real server
-    fun createAndShowShareToUser() {
-        val path = "/shareToAdmin/"
-        TestCase.assertTrue(
-            CreateFolderOperation(path, user, targetContext)
-                .execute(client, storageManager)
-                .isSuccess
-        )
-
-        // share folder to user "admin"
-        TestCase.assertTrue(
-            CreateShareRemoteOperation(
-                path,
-                ShareType.USER,
-                "admin",
-                false,
-                "",
-                OCShare.MAXIMUM_PERMISSIONS_FOR_FOLDER
-            )
-                .execute(client).isSuccess
-        )
-
-        val sut: FileDisplayActivity = activityRule.launchActivity(null)
-        sut.startSyncFolderOperation(storageManager.getFileByPath("/"), true)
-
-        shortSleep()
-        InstrumentationRegistry.getInstrumentation().waitForIdleSync()
-//        Screenshot.snapActivity(sut).record()
-    }
-
-    @Test
-    // @ScreenshotTest // todo run without real server
-    fun createAndShowShareToGroup() {
-        val path = "/shareToGroup/"
-        TestCase.assertTrue(
-            CreateFolderOperation(path, user, targetContext)
-                .execute(client, storageManager)
-                .isSuccess
-        )
-
-        // share folder to group
-        assertTrue(
-            CreateShareRemoteOperation(
-                "/shareToGroup/",
-                ShareType.GROUP,
-                "users",
-                false,
-                "",
-                OCShare.DEFAULT_PERMISSION
-            )
-                .execute(client)
-                .isSuccess
-        )
-
-        val sut: FileDisplayActivity = activityRule.launchActivity(null)
-        sut.startSyncFolderOperation(storageManager.getFileByPath("/"), true)
-
-        shortSleep()
-        InstrumentationRegistry.getInstrumentation().waitForIdleSync()
-//        Screenshot.snapActivity(sut).record()
-    }
-
-//    @Test
-//    @ScreenshotTest
-//    fun createAndShowShareToCircle() {
-//        val path = "/shareToCircle/"
-//        TestCase.assertTrue(CreateFolderOperation(path, account, targetContext)
-//            .execute(client, storageManager)
-//            .isSuccess)
-//
-//        // share folder to circle
-//        // get circleId
-//        val searchResult = GetShareesRemoteOperation("publicCircle", 1, RESULT_PER_PAGE).execute(client)
-//        assertTrue(searchResult.logMessage, searchResult.isSuccess)
-//
-//        val resultJson: JSONObject = searchResult.data[0] as JSONObject
-//        val circleId: String = resultJson.getJSONObject("value").getString("shareWith")
-//
-//        assertTrue(CreateShareRemoteOperation("/shareToCircle/",
-//            ShareType.CIRCLE,
-//            circleId,
-//            false,
-//            "",
-//            OCShare.DEFAULT_PERMISSION)
-//            .execute(client).isSuccess)
-//
-//        val sut: FileDisplayActivity = activityRule.launchActivity(null)
-//        sut.startSyncFolderOperation(storageManager.getFileByPath("/"), true)
-//
-//        shortSleep()
-//        InstrumentationRegistry.getInstrumentation().waitForIdleSync()
-//        Screenshot.snapActivity(sut).record()
-//    }
-
-    @Test
-    // @ScreenshotTest // todo run without real server
-    fun createAndShowShareViaLink() {
-        val path = "/shareViaLink/"
-        TestCase.assertTrue(
-            CreateFolderOperation(path, user, targetContext)
-                .execute(client, storageManager)
-                .isSuccess
-        )
-
-        // share folder via public link
-        TestCase.assertTrue(
-            CreateShareRemoteOperation(
-                "/shareViaLink/",
-                ShareType.PUBLIC_LINK,
-                "",
-                true,
-                "",
-                OCShare.READ_PERMISSION_FLAG
-            )
-                .execute(client)
-                .isSuccess
-        )
-
-        val sut: FileDisplayActivity = activityRule.launchActivity(null)
-        sut.startSyncFolderOperation(storageManager.getFileByPath("/"), true)
-
-        shortSleep()
-        InstrumentationRegistry.getInstrumentation().waitForIdleSync()
-//        Screenshot.snapActivity(sut).record()
-    }
-
     @Test
     @SuppressWarnings("MagicNumber")
     fun testEnoughSpaceWithoutLocalFile() {

+ 100 - 0
src/androidTest/java/com/owncloud/android/ui/fragment/OCFileListFragmentStaticServerIT.kt

@@ -28,7 +28,10 @@ import androidx.test.rule.GrantPermissionRule
 import com.nextcloud.client.TestActivity
 import com.owncloud.android.AbstractIT
 import com.owncloud.android.datamodel.OCFile
+import com.owncloud.android.lib.resources.shares.ShareType
+import com.owncloud.android.lib.resources.shares.ShareeUser
 import com.owncloud.android.utils.ScreenshotTest
+import org.junit.After
 import org.junit.Rule
 import org.junit.Test
 
@@ -76,6 +79,103 @@ class OCFileListFragmentStaticServerIT : AbstractIT() {
 
     @Test
     @ScreenshotTest
+    fun showSharedFiles() {
+        val sut = testActivityRule.launchActivity(null)
+        val fragment = OCFileListFragment()
+
+        val groupShare = OCFile("/sharedToGroup.jpg").apply {
+            parentId = sut.storageManager.getFileByEncryptedRemotePath("/").fileId
+            isSharedWithSharee = true
+            sharees = listOf(ShareeUser("group", "Group", ShareType.GROUP))
+        }
+        sut.storageManager.saveFile(groupShare)
+
+        val roomShare = OCFile("/sharedToRoom.jpg").apply {
+            parentId = sut.storageManager.getFileByEncryptedRemotePath("/").fileId
+            isSharedWithSharee = true
+            sharees = listOf(ShareeUser("Conversation", "Meeting", ShareType.ROOM))
+        }
+        sut.storageManager.saveFile(roomShare)
+
+        val circleShare = OCFile("/sharedToCircle.jpg").apply {
+            parentId = sut.storageManager.getFileByEncryptedRemotePath("/").fileId
+            isSharedWithSharee = true
+            sharees = listOf(ShareeUser("circle", "Circle (Public circle)", ShareType.CIRCLE))
+        }
+        sut.storageManager.saveFile(circleShare)
+
+        val userShare = OCFile("/sharedToUser.jpg").apply {
+            parentId = sut.storageManager.getFileByEncryptedRemotePath("/").fileId
+            isSharedWithSharee = true
+            sharees = listOf(ShareeUser("Admin", "Server Admin", ShareType.USER))
+        }
+        sut.storageManager.saveFile(userShare)
+
+        val federatedUserShare = OCFile("/sharedToFederatedUser.jpg").apply {
+            parentId = sut.storageManager.getFileByEncryptedRemotePath("/").fileId
+            isSharedWithSharee = true
+            sharees = listOf(
+                ShareeUser("admin@remote.nextcloud.com", "admin@remote.nextcloud.com (remote)", ShareType.FEDERATED)
+            )
+        }
+        sut.storageManager.saveFile(federatedUserShare)
+
+        val emailShare = OCFile("/sharedToEmail.jpg").apply {
+            parentId = sut.storageManager.getFileByEncryptedRemotePath("/").fileId
+            isSharedWithSharee = true
+            sharees = listOf(ShareeUser("test@remote.nextcloud.com", "test@remote.nextcloud.com", ShareType.EMAIL))
+        }
+        sut.storageManager.saveFile(emailShare)
+
+        val publicLink = OCFile("/publicLink.jpg").apply {
+            parentId = sut.storageManager.getFileByEncryptedRemotePath("/").fileId
+            isSharedViaLink = true
+        }
+        sut.storageManager.saveFile(publicLink)
+
+        val noShare = OCFile("/notShared.jpg").apply {
+            parentId = sut.storageManager.getFileByEncryptedRemotePath("/").fileId
+        }
+        sut.storageManager.saveFile(noShare)
+
+        val usersShare = OCFile("/sharedToUser.jpg").apply {
+            parentId = sut.storageManager.getFileByEncryptedRemotePath("/").fileId
+            isSharedWithSharee = true
+            sharees = listOf(
+                ShareeUser("Admin", "Server Admin", ShareType.USER),
+                ShareeUser("User", "User", ShareType.USER),
+                ShareeUser("Christine", "Christine Scott", ShareType.USER)
+            )
+        }
+        sut.storageManager.saveFile(usersShare)
+
+        sut.addFragment(fragment)
+
+        shortSleep()
+
+        val root = sut.storageManager.getFileByEncryptedRemotePath("/")
+
+        sut.runOnUiThread {
+            fragment.listDirectory(root, false, false)
+            fragment.adapter.setShowShareAvatar(true)
+        }
+
+        waitForIdleSync()
+        shortSleep()
+        shortSleep()
+        shortSleep()
+
+        screenshot(sut)
+    }
+
+    @After
+    fun after() {
+        fileDataStorageManager.deleteAllFiles()
+    }
+
+    @Test
+    @ScreenshotTest
+    @Suppress("MagicNumber")
     fun showRichWorkspace() {
         val sut = testActivityRule.launchActivity(null)
         val fragment = OCFileListFragment()

+ 27 - 0
src/debug/res/layout/avatar_fragment.xml

@@ -0,0 +1,27 @@
+<?xml version="1.0" encoding="utf-8"?><!--
+  Nextcloud Android client application
+
+  @author Tobias Kaminsky
+  Copyright (C) 2020 Tobias Kaminsky
+  Copyright (C) 2020 Nextcloud GmbH
+
+  This program is free software: you can redistribute it and/or modify
+  it under the terms of the GNU Affero General Public License as published by
+  the Free Software Foundation, either version 3 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 Affero General Public License for more details.
+
+  You should have received a copy of the GNU Affero General Public License
+  along with this program. If not, see <https://www.gnu.org/licenses/>.
+-->
+<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
+    android:id="@+id/avatar_list"
+    android:layout_width="match_parent"
+    android:layout_height="match_parent"
+    android:orientation="vertical">
+
+</LinearLayout>

+ 6 - 0
src/main/java/com/owncloud/android/ui/adapter/OCFileListAdapter.java

@@ -96,6 +96,7 @@ import java.util.Vector;
 
 import androidx.annotation.NonNull;
 import androidx.annotation.Nullable;
+import androidx.annotation.VisibleForTesting;
 import androidx.core.content.res.ResourcesCompat;
 import androidx.core.graphics.drawable.RoundedBitmapDrawable;
 import androidx.core.graphics.drawable.RoundedBitmapDrawableFactory;
@@ -1282,6 +1283,11 @@ public class OCFileListAdapter extends RecyclerView.Adapter<RecyclerView.ViewHol
         gridView = bool;
     }
 
+    @VisibleForTesting
+    public void setShowShareAvatar(boolean bool) {
+        showShareAvatar = bool;
+    }
+
     static class OCFileListItemViewHolder extends OCFileListGridItemViewHolder {
         @BindView(R.id.file_size)
         public TextView fileSize;