Skip to content

Commit 9910a08

Browse files
committed
Test cases added.
1 parent d54aad7 commit 9910a08

File tree

2 files changed

+473
-0
lines changed

2 files changed

+473
-0
lines changed
Lines changed: 392 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,392 @@
1+
package com.nmc.android.ui
2+
3+
import androidx.recyclerview.widget.RecyclerView
4+
import androidx.test.espresso.Espresso.onView
5+
import androidx.test.espresso.Espresso.pressBack
6+
import androidx.test.espresso.assertion.ViewAssertions.matches
7+
import androidx.test.espresso.contrib.RecyclerViewActions
8+
import androidx.test.espresso.contrib.RecyclerViewActions.actionOnItemAtPosition
9+
import androidx.test.espresso.matcher.ViewMatchers.isCompletelyDisplayed
10+
import androidx.test.espresso.matcher.ViewMatchers.isDisplayed
11+
import androidx.test.espresso.matcher.ViewMatchers.withId
12+
import androidx.test.espresso.matcher.ViewMatchers.withText
13+
import androidx.test.ext.junit.rules.ActivityScenarioRule
14+
import com.nextcloud.test.RetryTestRule
15+
import com.nextcloud.test.TestActivity
16+
import com.nmc.android.ui.RecyclerViewAssertions.clickChildViewWithId
17+
import com.nmc.android.ui.RecyclerViewAssertions.withRecyclerView
18+
import com.owncloud.android.AbstractIT
19+
import com.owncloud.android.R
20+
import com.owncloud.android.datamodel.OCFile
21+
import com.owncloud.android.lib.resources.shares.OCShare
22+
import com.owncloud.android.lib.resources.shares.ShareType
23+
import com.owncloud.android.ui.fragment.FileDetailFragment
24+
import com.owncloud.android.ui.fragment.FileDetailSharingFragment
25+
import com.owncloud.android.ui.fragment.util.SharingMenuHelper
26+
import org.hamcrest.Matchers.not
27+
import org.junit.After
28+
import org.junit.Assert.assertEquals
29+
import org.junit.Before
30+
import org.junit.Rule
31+
import org.junit.Test
32+
33+
class FileSharingIT : AbstractIT() {
34+
@get:Rule
35+
val activityScenarioRule = ActivityScenarioRule(TestActivity::class.java)
36+
37+
@get:Rule
38+
val retryRule = RetryTestRule()
39+
40+
lateinit var file: OCFile
41+
lateinit var folder: OCFile
42+
43+
@Before
44+
fun before() {
45+
activityScenarioRule.scenario.onActivity {
46+
file = OCFile("/test.md").apply {
47+
remoteId = "00000001"
48+
parentId = it.storageManager.getFileByEncryptedRemotePath("/").fileId
49+
permissions = OCFile.PERMISSION_CAN_RESHARE
50+
}
51+
52+
folder = OCFile("/test").apply {
53+
setFolder()
54+
remoteId = "00000002"
55+
parentId = it.storageManager.getFileByEncryptedRemotePath("/").fileId
56+
permissions = OCFile.PERMISSION_CAN_RESHARE
57+
}
58+
}
59+
}
60+
61+
private fun show(file: OCFile) {
62+
val fragment = FileDetailFragment.newInstance(file, user, 0)
63+
64+
activityScenarioRule.scenario.onActivity {
65+
it.addFragment(fragment)
66+
}
67+
68+
waitForIdleSync()
69+
70+
shortSleep()
71+
}
72+
73+
private fun getFragment(): FileDetailSharingFragment? {
74+
var fragment: FileDetailSharingFragment? = null
75+
activityScenarioRule.scenario.onActivity {
76+
fragment =
77+
it.supportFragmentManager.findFragmentByTag("SHARING_DETAILS_FRAGMENT") as FileDetailSharingFragment
78+
}
79+
return fragment
80+
}
81+
82+
@Test
83+
fun validateUiOfFileDetailFragment() {
84+
show(file)
85+
86+
onView(withId(R.id.filename)).check(matches(isCompletelyDisplayed()))
87+
onView(withId(R.id.filename)).check(matches(withText("test.md")))
88+
onView(withId(R.id.favorite)).check(matches(isCompletelyDisplayed()))
89+
onView(withId(R.id.size)).check(matches(isCompletelyDisplayed()))
90+
onView(withId(R.id.file_separator)).check(matches(isCompletelyDisplayed()))
91+
onView(withId(R.id.last_modification_timestamp)).check(matches(isCompletelyDisplayed()))
92+
}
93+
94+
@Test
95+
fun validateUiForEmptyShares() {
96+
show(file)
97+
98+
onView(withId(R.id.shared_with_you_container)).check(matches(not(isCompletelyDisplayed())))
99+
onView(withId(R.id.tv_sharing_details_message)).check(matches(isCompletelyDisplayed()))
100+
onView(withId(R.id.tv_sharing_details_message)).check(matches(withText("You can create links or send shares by mail. If you invite MagentaCLOUD users, you have more opportunities for collaboration.")))
101+
onView(withId(R.id.searchView)).check(matches(isCompletelyDisplayed()))
102+
onView(withId(R.id.label_personal_share)).check(matches(isCompletelyDisplayed()))
103+
onView(withId(R.id.label_personal_share)).check(matches(withText("Personal share by mail")))
104+
105+
onView(withId(R.id.share_create_new_link)).check(matches(isCompletelyDisplayed()))
106+
onView(withId(R.id.share_create_new_link)).check(matches(withText("Add link")))
107+
108+
onView(withId(R.id.tv_your_shares)).check(matches(not(isDisplayed())))
109+
onView(withId(R.id.sharesList)).check(matches(not(isDisplayed())))
110+
onView(withId(R.id.tv_empty_shares)).check(matches(isCompletelyDisplayed()))
111+
onView(withId(R.id.tv_empty_shares)).check(matches(withText("No shares created yet.")))
112+
}
113+
114+
@Test
115+
fun validateUiForFileWithShares() {
116+
activityScenarioRule.scenario.onActivity {
117+
OCShare(file.decryptedRemotePath).apply {
118+
remoteId = 1
119+
shareType = ShareType.USER
120+
sharedWithDisplayName = "Admin"
121+
permissions = OCShare.READ_PERMISSION_FLAG
122+
userId = getUserId(user)
123+
it.storageManager.saveShare(this)
124+
}
125+
126+
OCShare(file.decryptedRemotePath).apply {
127+
remoteId = 3
128+
shareType = ShareType.EMAIL
129+
permissions = SharingMenuHelper.CAN_EDIT_PERMISSIONS_FOR_FILE
130+
sharedWithDisplayName = "[email protected]"
131+
userId = getUserId(user)
132+
it.storageManager.saveShare(this)
133+
}
134+
135+
OCShare(file.decryptedRemotePath).apply {
136+
remoteId = 4
137+
shareType = ShareType.PUBLIC_LINK
138+
permissions = OCShare.READ_PERMISSION_FLAG
139+
label = "Customer"
140+
it.storageManager.saveShare(this)
141+
}
142+
143+
OCShare(file.decryptedRemotePath).apply {
144+
remoteId = 5
145+
shareType = ShareType.PUBLIC_LINK
146+
permissions = SharingMenuHelper.CAN_EDIT_PERMISSIONS_FOR_FILE
147+
label = "Colleagues"
148+
it.storageManager.saveShare(this)
149+
}
150+
151+
}
152+
show(file)
153+
154+
onView(withId(R.id.shared_with_you_container)).check(matches(not(isCompletelyDisplayed())))
155+
onView(withId(R.id.tv_sharing_details_message)).check(matches(isCompletelyDisplayed()))
156+
onView(withId(R.id.tv_sharing_details_message)).check(matches(withText("You can create links or send shares by mail. If you invite MagentaCLOUD users, you have more opportunities for collaboration.")))
157+
onView(withId(R.id.searchView)).check(matches(isCompletelyDisplayed()))
158+
onView(withId(R.id.label_personal_share)).check(matches(isCompletelyDisplayed()))
159+
onView(withId(R.id.label_personal_share)).check(matches(withText("Personal share by mail")))
160+
161+
onView(withId(R.id.share_create_new_link)).check(matches(isCompletelyDisplayed()))
162+
onView(withId(R.id.share_create_new_link)).check(matches(withText("Add link")))
163+
164+
onView(withId(R.id.tv_your_shares)).check(matches(isCompletelyDisplayed()))
165+
onView(withId(R.id.tv_your_shares)).check(matches(withText("Your Shares")))
166+
onView(withId(R.id.sharesList)).check(matches(isCompletelyDisplayed()))
167+
onView(withId(R.id.tv_empty_shares)).check(matches(not(isDisplayed())))
168+
}
169+
170+
@Test
171+
fun validateUiWithResharingNotAllowed() {
172+
file = file.apply {
173+
permissions = ""
174+
ownerDisplayName = "John Doe"
175+
ownerId = "JohnDoe"
176+
note = "Shared for testing purpose."
177+
}
178+
show(file)
179+
180+
onView(withId(R.id.shared_with_you_container)).check(matches(isCompletelyDisplayed()))
181+
onView(withId(R.id.tv_sharing_details_message)).check(matches(isCompletelyDisplayed()))
182+
onView(withId(R.id.tv_sharing_details_message)).check(matches(withText("Resharing is not allowed.")))
183+
onView(withId(R.id.shared_with_you_username)).check(matches(withText("Shared with you by John Doe")))
184+
onView(withId(R.id.shared_with_you_note)).check(matches(withText("Shared for testing purpose.")))
185+
onView(withId(R.id.shared_with_you_avatar)).check(matches(isCompletelyDisplayed()))
186+
187+
onView(withId(R.id.searchView)).check(matches(not(isDisplayed())))
188+
onView(withId(R.id.label_personal_share)).check(matches(not(isDisplayed())))
189+
onView(withId(R.id.share_create_new_link)).check(matches(not(isDisplayed())))
190+
onView(withId(R.id.tv_your_shares)).check(matches(not(isDisplayed())))
191+
onView(withId(R.id.sharesList)).check(matches(not(isDisplayed())))
192+
onView(withId(R.id.tv_empty_shares)).check(matches(not(isDisplayed())))
193+
}
194+
195+
@Test
196+
fun validateUiWithResharingAllowed() {
197+
file = file.apply {
198+
ownerDisplayName = "John Doe"
199+
ownerId = "JohnDoe"
200+
}
201+
show(file)
202+
203+
onView(withId(R.id.shared_with_you_container)).check(matches(isCompletelyDisplayed()))
204+
onView(withId(R.id.tv_sharing_details_message)).check(matches(isCompletelyDisplayed()))
205+
onView(withId(R.id.tv_sharing_details_message)).check(matches(withText("Resharing is allowed. You can create links or send shares by mail. If you invite MagentaCLOUD users, you have more opportunities for collaboration.")))
206+
onView(withId(R.id.shared_with_you_username)).check(matches(withText("Shared with you by John Doe")))
207+
onView(withId(R.id.shared_with_you_avatar)).check(matches(isCompletelyDisplayed()))
208+
onView(withId(R.id.shared_with_you_note_container)).check(matches(not(isDisplayed())))
209+
210+
onView(withId(R.id.searchView)).check(matches(isCompletelyDisplayed()))
211+
onView(withId(R.id.label_personal_share)).check(matches(isCompletelyDisplayed()))
212+
onView(withId(R.id.share_create_new_link)).check(matches(isCompletelyDisplayed()))
213+
onView(withId(R.id.tv_your_shares)).check(matches(not(isDisplayed())))
214+
onView(withId(R.id.sharesList)).check(matches(not(isDisplayed())))
215+
onView(withId(R.id.tv_empty_shares)).check(matches(isCompletelyDisplayed()))
216+
onView(withId(R.id.tv_empty_shares)).check(matches(withText("No shares created yet.")))
217+
}
218+
219+
@Test
220+
fun validateQuickPermissionDialogForFiles() {
221+
val sharesList: MutableList<OCShare> = mutableListOf()
222+
223+
activityScenarioRule.scenario.onActivity { it ->
224+
OCShare(file.decryptedRemotePath).apply {
225+
remoteId = 1
226+
shareType = ShareType.USER
227+
sharedWithDisplayName = "Admin"
228+
permissions = OCShare.READ_PERMISSION_FLAG
229+
userId = getUserId(user)
230+
isFolder = false
231+
it.storageManager.saveShare(this)
232+
}
233+
234+
OCShare(file.decryptedRemotePath).apply {
235+
remoteId = 3
236+
shareType = ShareType.EMAIL
237+
sharedWithDisplayName = "[email protected]"
238+
permissions = SharingMenuHelper.CAN_EDIT_PERMISSIONS_FOR_FILE
239+
userId = getUserId(user)
240+
isFolder = false
241+
it.storageManager.saveShare(this)
242+
}
243+
244+
OCShare(file.decryptedRemotePath).apply {
245+
remoteId = 4
246+
shareType = ShareType.PUBLIC_LINK
247+
permissions = OCShare.READ_PERMISSION_FLAG
248+
userId = getUserId(user)
249+
label = "Customer"
250+
isFolder = false
251+
it.storageManager.saveShare(this)
252+
}
253+
254+
//get other shares
255+
sharesList.addAll(it.storageManager.getSharesWithForAFile(file.remotePath, user.accountName))
256+
257+
//get public link shares
258+
sharesList.addAll(it.storageManager.getSharesByPathAndType(file.remotePath, ShareType.PUBLIC_LINK, ""))
259+
260+
sharesList.sortByDescending { share -> share.shareType }
261+
}
262+
263+
264+
assertEquals(3, sharesList.size)
265+
266+
show(file)
267+
268+
for (i in sharesList.indices) {
269+
val share = sharesList[i]
270+
//since for public link the quick permission button is disabled
271+
if (share.shareType == ShareType.PUBLIC_LINK) {
272+
continue
273+
}
274+
showQuickPermissionDialogAndValidate(i, file.isFolder, share)
275+
pressBack()
276+
}
277+
}
278+
279+
@Test
280+
fun validateQuickPermissionDialogForFolder() {
281+
val sharesList: MutableList<OCShare> = mutableListOf()
282+
283+
activityScenarioRule.scenario.onActivity { it ->
284+
OCShare(folder.decryptedRemotePath).apply {
285+
remoteId = 1
286+
shareType = ShareType.USER
287+
sharedWithDisplayName = "Admin"
288+
permissions = OCShare.CREATE_PERMISSION_FLAG
289+
userId = getUserId(user)
290+
isFolder = true
291+
it.storageManager.saveShare(this)
292+
}
293+
294+
OCShare(folder.decryptedRemotePath).apply {
295+
remoteId = 3
296+
shareType = ShareType.EMAIL
297+
sharedWithDisplayName = "[email protected]"
298+
permissions = SharingMenuHelper.CAN_EDIT_PERMISSIONS_FOR_FOLDER
299+
userId = getUserId(user)
300+
isFolder = true
301+
it.storageManager.saveShare(this)
302+
}
303+
304+
OCShare(folder.decryptedRemotePath).apply {
305+
remoteId = 4
306+
shareType = ShareType.PUBLIC_LINK
307+
permissions = OCShare.READ_PERMISSION_FLAG
308+
userId = getUserId(user)
309+
label = "Customer"
310+
isFolder = true
311+
it.storageManager.saveShare(this)
312+
}
313+
314+
//get other shares
315+
sharesList.addAll(it.storageManager.getSharesWithForAFile(folder.remotePath, user.accountName))
316+
317+
//get public link shares
318+
sharesList.addAll(it.storageManager.getSharesByPathAndType(folder.remotePath, ShareType.PUBLIC_LINK, ""))
319+
320+
sharesList.sortByDescending { share -> share.shareType }
321+
}
322+
323+
324+
assertEquals(3, sharesList.size)
325+
326+
show(folder)
327+
328+
for (i in sharesList.indices) {
329+
val share = sharesList[i]
330+
showQuickPermissionDialogAndValidate(i, folder.isFolder, share)
331+
pressBack()
332+
}
333+
}
334+
335+
private fun showQuickPermissionDialogAndValidate(index: Int, isFolder: Boolean, ocShare: OCShare) {
336+
onView(withId(R.id.sharesList)).perform(
337+
actionOnItemAtPosition<RecyclerView.ViewHolder>(
338+
index,
339+
clickChildViewWithId(if (ocShare.shareType == ShareType.USER) R.id.share_name_layout else R.id.share_by_link_container)
340+
)
341+
)
342+
343+
val permissionList = permissionList(isFolder, ocShare.shareType)
344+
345+
for (i in permissionList.indices) {
346+
// Scroll to the item at position i
347+
onView(withId(R.id.rv_quick_share_permissions)).perform(
348+
RecyclerViewActions.scrollToPosition<RecyclerView.ViewHolder>(
349+
i
350+
)
351+
)
352+
353+
val permissionTextView = onView(
354+
withRecyclerView(R.id.rv_quick_share_permissions)
355+
.atPositionOnView(i, R.id.tv_quick_share_name)
356+
)
357+
permissionTextView.check(matches(withText(permissionList[i])))
358+
359+
val permissionCheckView = onView(
360+
withRecyclerView(R.id.rv_quick_share_permissions)
361+
.atPositionOnView(i, R.id.tv_quick_share_check_icon)
362+
)
363+
if ((permissionList[i] == "Read only" && SharingMenuHelper.isReadOnly(ocShare))
364+
|| (permissionList[i] == "Can edit" && SharingMenuHelper.isUploadAndEditingAllowed(ocShare))
365+
|| (permissionList[i] == "Filedrop only" && SharingMenuHelper.isFileDrop(ocShare))
366+
) {
367+
permissionCheckView.check(matches(isDisplayed()))
368+
}
369+
}
370+
}
371+
372+
@After
373+
override fun after() {
374+
activityScenarioRule.scenario.onActivity {
375+
it.storageManager.cleanShares()
376+
it.finish()
377+
}
378+
super.after()
379+
}
380+
381+
companion object {
382+
private val filePermissionList = listOf("Read only", "Can edit")
383+
private val folderExternalAndLinkSharePermissionList = listOf("Read only", "Can edit", "Filedrop only")
384+
private val folderOtherSharePermissionList = listOf("Read only", "Can edit")
385+
386+
fun permissionList(isFolder: Boolean, shareType: ShareType): List<String> =
387+
if (isFolder) {
388+
if (shareType == ShareType.PUBLIC_LINK || shareType == ShareType.EMAIL) folderExternalAndLinkSharePermissionList
389+
else folderOtherSharePermissionList
390+
} else filePermissionList
391+
}
392+
}

0 commit comments

Comments
 (0)