|
| 1 | +/* |
| 2 | + * |
| 3 | + * Nextcloud Android client application |
| 4 | + * |
| 5 | + * @author Tobias Kaminsky |
| 6 | + * Copyright (C) 2023 Tobias Kaminsky |
| 7 | + * Copyright (C) 2023 Nextcloud GmbH |
| 8 | + * |
| 9 | + * This program is free software: you can redistribute it and/or modify |
| 10 | + * it under the terms of the GNU Affero General Public License as published by |
| 11 | + * the Free Software Foundation, either version 3 of the License, or |
| 12 | + * (at your option) any later version. |
| 13 | + * |
| 14 | + * This program is distributed in the hope that it will be useful, |
| 15 | + * but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 16 | + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 17 | + * GNU Affero General Public License for more details. |
| 18 | + * |
| 19 | + * You should have received a copy of the GNU Affero General Public License |
| 20 | + * along with this program. If not, see <https://www.gnu.org/licenses/>. |
| 21 | + */ |
| 22 | + |
| 23 | +package com.owncloud.android.ui.fragment |
| 24 | + |
| 25 | +import android.view.View |
| 26 | +import androidx.test.espresso.intent.rule.IntentsTestRule |
| 27 | +import com.nextcloud.test.GrantStoragePermissionRule |
| 28 | +import com.nextcloud.test.TestActivity |
| 29 | +import com.owncloud.android.AbstractIT |
| 30 | +import com.owncloud.android.datamodel.OCFile |
| 31 | +import com.owncloud.android.lib.resources.shares.OCShare |
| 32 | +import com.owncloud.android.lib.resources.shares.ShareType |
| 33 | +import com.owncloud.android.utils.ScreenshotTest |
| 34 | +import org.junit.Before |
| 35 | +import org.junit.Rule |
| 36 | +import org.junit.Test |
| 37 | + |
| 38 | +internal class SharedListFragmentIT : AbstractIT() { |
| 39 | + @get:Rule |
| 40 | + val testActivityRule = IntentsTestRule(TestActivity::class.java, true, false) |
| 41 | + |
| 42 | + @get:Rule |
| 43 | + val permissionRule = GrantStoragePermissionRule.grant() |
| 44 | + |
| 45 | + lateinit var sut: TestActivity |
| 46 | + |
| 47 | + @Before |
| 48 | + fun before() { |
| 49 | + sut = testActivityRule.launchActivity(null) |
| 50 | + } |
| 51 | + |
| 52 | + @Test |
| 53 | + @ScreenshotTest |
| 54 | + fun showSharedFiles() { |
| 55 | + val fragment = SharedListFragment() |
| 56 | + |
| 57 | + val file = OCFile("/shared to admin.png").apply { |
| 58 | + remoteId = "00000001" |
| 59 | + parentId = sut.storageManager.getFileByEncryptedRemotePath("/").fileId |
| 60 | + mimeType = "image/png" |
| 61 | + fileLength = 1024000 |
| 62 | + modificationTimestamp = 1188206955 |
| 63 | + permissions = OCFile.PERMISSION_CAN_RESHARE |
| 64 | + sut.storageManager.saveFile(this) |
| 65 | + } |
| 66 | + |
| 67 | + val file1 = OCFile("/shared to group.png").apply { |
| 68 | + remoteId = "00000001" |
| 69 | + parentId = sut.storageManager.getFileByEncryptedRemotePath("/").fileId |
| 70 | + mimeType = "image/png" |
| 71 | + fileLength = 1024000 |
| 72 | + modificationTimestamp = 1188206955 |
| 73 | + permissions = OCFile.PERMISSION_CAN_RESHARE |
| 74 | + sut.storageManager.saveFile(this) |
| 75 | + } |
| 76 | + |
| 77 | + val file2 = OCFile("/shared via public link.png").apply { |
| 78 | + remoteId = "00000001" |
| 79 | + parentId = sut.storageManager.getFileByEncryptedRemotePath("/").fileId |
| 80 | + mimeType = "image/png" |
| 81 | + fileLength = 1024000 |
| 82 | + modificationTimestamp = 1188206955 |
| 83 | + permissions = OCFile.PERMISSION_CAN_RESHARE |
| 84 | + sut.storageManager.saveFile(this) |
| 85 | + } |
| 86 | + |
| 87 | + val file3 = OCFile("/shared to personal circle.png").apply { |
| 88 | + remoteId = "00000001" |
| 89 | + parentId = sut.storageManager.getFileByEncryptedRemotePath("/").fileId |
| 90 | + mimeType = "image/png" |
| 91 | + fileLength = 1024000 |
| 92 | + modificationTimestamp = 1188206955 |
| 93 | + permissions = OCFile.PERMISSION_CAN_RESHARE |
| 94 | + sut.storageManager.saveFile(this) |
| 95 | + } |
| 96 | + |
| 97 | + val file4 = OCFile("/shared to talk.png").apply { |
| 98 | + remoteId = "00000001" |
| 99 | + parentId = sut.storageManager.getFileByEncryptedRemotePath("/").fileId |
| 100 | + mimeType = "image/png" |
| 101 | + fileLength = 1024000 |
| 102 | + modificationTimestamp = 1188206955 |
| 103 | + permissions = OCFile.PERMISSION_CAN_RESHARE |
| 104 | + sut.storageManager.saveFile(this) |
| 105 | + } |
| 106 | + |
| 107 | + val shares = listOf( |
| 108 | + OCShare(file.decryptedRemotePath).apply { |
| 109 | + remoteId = 1 |
| 110 | + shareType = ShareType.USER |
| 111 | + sharedWithDisplayName = "Admin" |
| 112 | + permissions = OCShare.MAXIMUM_PERMISSIONS_FOR_FILE |
| 113 | + userId = getUserId(user) |
| 114 | + sharedDate = 1188206955 |
| 115 | + mimetype = "image/png" |
| 116 | + sut.storageManager.saveShare(this) |
| 117 | + }, |
| 118 | + |
| 119 | + OCShare(file1.decryptedRemotePath).apply { |
| 120 | + remoteId = 2 |
| 121 | + shareType = ShareType.GROUP |
| 122 | + sharedWithDisplayName = "Group" |
| 123 | + permissions = OCShare.MAXIMUM_PERMISSIONS_FOR_FILE |
| 124 | + userId = getUserId(user) |
| 125 | + sharedDate = 1188206955 |
| 126 | + mimetype = "image/png" |
| 127 | + sut.storageManager.saveShare(this) |
| 128 | + }, |
| 129 | + |
| 130 | + OCShare(file2.decryptedRemotePath).apply { |
| 131 | + remoteId = 3 |
| 132 | + shareType = ShareType.PUBLIC_LINK |
| 133 | + label = "Customer" |
| 134 | + sharedDate = 1188206955 |
| 135 | + mimetype = "image/png" |
| 136 | + sut.storageManager.saveShare(this) |
| 137 | + }, |
| 138 | + |
| 139 | + OCShare(file3.decryptedRemotePath).apply { |
| 140 | + remoteId = 4 |
| 141 | + shareType = ShareType.CIRCLE |
| 142 | + sharedWithDisplayName = "Personal circle" |
| 143 | + permissions = OCShare.SHARE_PERMISSION_FLAG |
| 144 | + userId = getUserId(user) |
| 145 | + sharedDate = 1188206955 |
| 146 | + mimetype = "image/png" |
| 147 | + sut.storageManager.saveShare(this) |
| 148 | + }, |
| 149 | + |
| 150 | + OCShare(file4.decryptedRemotePath).apply { |
| 151 | + remoteId = 11 |
| 152 | + shareType = ShareType.ROOM |
| 153 | + sharedWithDisplayName = "Admin" |
| 154 | + permissions = OCShare.SHARE_PERMISSION_FLAG |
| 155 | + userId = getUserId(user) |
| 156 | + sharedDate = 1188206955 |
| 157 | + mimetype = "image/png" |
| 158 | + sut.storageManager.saveShare(this) |
| 159 | + } |
| 160 | + ) |
| 161 | + |
| 162 | + sut.addFragment(fragment) |
| 163 | + |
| 164 | + shortSleep() |
| 165 | + |
| 166 | + sut.runOnUiThread { |
| 167 | + fragment.isLoading = false |
| 168 | + fragment.mEmptyListContainer.visibility = View.GONE |
| 169 | + fragment.adapter.setData( |
| 170 | + shares, |
| 171 | + SearchType.SHARED_FILTER, |
| 172 | + storageManager, |
| 173 | + null, |
| 174 | + true |
| 175 | + ) |
| 176 | + } |
| 177 | + |
| 178 | + waitForIdleSync() |
| 179 | + shortSleep() |
| 180 | + shortSleep() |
| 181 | + shortSleep() |
| 182 | + |
| 183 | + screenshot(sut) |
| 184 | + } |
| 185 | +} |
0 commit comments