@@ -31,6 +31,7 @@ import com.owncloud.android.R
3131import com.owncloud.android.datamodel.OCFile
3232import com.owncloud.android.utils.ScreenshotTest
3333import org.hamcrest.Matchers.not
34+ import org.junit.Before
3435import org.junit.Rule
3536import org.junit.Test
3637import org.junit.rules.TestRule
@@ -42,6 +43,28 @@ class ReceiveExternalFilesActivityIT : AbstractIT() {
4243 @get:Rule
4344 var storagePermissionRule: TestRule = GrantStoragePermissionRule .grant()
4445
46+ lateinit var mainFolder: OCFile
47+ lateinit var subFolder: OCFile
48+ lateinit var existingImageFile: OCFile
49+
50+ @Before
51+ fun setupFolderAndFileStructure () {
52+ // Create folders with the necessary permissions and another test file
53+ mainFolder = OCFile (" /folder/" ).apply {
54+ permissions = OCFile .PERMISSION_CAN_CREATE_FILE_AND_FOLDER
55+ setFolder()
56+ fileDataStorageManager.saveNewFile(this )
57+ }
58+ subFolder = OCFile (" ${mainFolder.remotePath} sub folder/" ).apply {
59+ permissions = OCFile .PERMISSION_CAN_CREATE_FILE_AND_FOLDER
60+ setFolder()
61+ fileDataStorageManager.saveNewFile(this )
62+ }
63+ existingImageFile = OCFile (" ${mainFolder.remotePath} Existing Image File.jpg" ).apply {
64+ fileDataStorageManager.saveNewFile(this )
65+ }
66+ }
67+
4568 @Test
4669 @ScreenshotTest
4770 fun open () {
@@ -70,25 +93,18 @@ class ReceiveExternalFilesActivityIT : AbstractIT() {
7093 putExtra(Intent .EXTRA_STREAM , Uri .fromFile(file))
7194 }
7295
96+ fun createSendIntent (files : Iterable <File >): Intent =
97+ Intent (targetContext, ReceiveExternalFilesActivity ::class .java).apply {
98+ action = Intent .ACTION_SEND_MULTIPLE
99+ addFlags(Intent .FLAG_GRANT_READ_URI_PERMISSION )
100+ putParcelableArrayListExtra(Intent .EXTRA_STREAM , ArrayList (files.map { Uri .fromFile(it) }))
101+ }
102+
73103 @Test
74104 fun renameSingleFileUpload () {
75105 val imageFile = getDummyFile(" image.jpg" )
76106 val intent = createSendIntent(imageFile)
77107
78- // Create folders with the necessary permissions and another test file
79- val mainFolder = OCFile (" /folder/" ).apply {
80- permissions = OCFile .PERMISSION_CAN_CREATE_FILE_AND_FOLDER
81- setFolder()
82- fileDataStorageManager.saveNewFile(this )
83- }
84- val subFolder = OCFile (" ${mainFolder.remotePath} sub folder/" ).apply {
85- permissions = OCFile .PERMISSION_CAN_CREATE_FILE_AND_FOLDER
86- setFolder()
87- fileDataStorageManager.saveNewFile(this )
88- }
89- val otherFile = OCFile (" ${mainFolder.remotePath} Other Image File.jpg" ).apply {
90- fileDataStorageManager.saveNewFile(this )
91- }
92108
93109 // Store the folder in preferences, so the activity starts from there.
94110 @Suppress(" DEPRECATION" )
@@ -148,8 +164,8 @@ class ReceiveExternalFilesActivityIT : AbstractIT() {
148164 .check(matches(not (isEnabled())))
149165 onView(withId(R .id.user_input))
150166 .perform(ViewActions .click())
151- .perform(ViewActions .typeTextIntoFocusedView(otherFile .fileName))
152- .check(matches(withText(otherFile .fileName)))
167+ .perform(ViewActions .typeTextIntoFocusedView(existingImageFile .fileName))
168+ .check(matches(withText(existingImageFile .fileName)))
153169 onView(withText(R .string.uploader_btn_upload_text))
154170 .check(matches(isDisplayed()))
155171 .check(matches(not (isEnabled())))
@@ -203,4 +219,29 @@ class ReceiveExternalFilesActivityIT : AbstractIT() {
203219 .check(matches(withText(imageFile.name)))
204220 }
205221 }
222+
223+ @Test
224+ fun noRenameForMultiUpload () {
225+ val testFiles = createDummyFiles()
226+ val intent = createSendIntent(testFiles)
227+
228+ // Store the folder in preferences, so the activity starts from there.
229+ @Suppress(" DEPRECATION" )
230+ val preferences = AppPreferencesImpl .fromContext(targetContext)
231+ preferences.setLastUploadPath(mainFolder.remotePath)
232+
233+ launchActivity<ReceiveExternalFilesActivity >(intent).use {
234+ val expectedMainFolderTitle = (getCurrentActivity() as ToolbarActivity ).getActionBarTitle(mainFolder, false )
235+ // Verify that the test starts in the expected folder. If this fails, change the setup calls above
236+ onView(withId(R .id.toolbar))
237+ .check(matches(hasDescendant(withText(expectedMainFolderTitle))))
238+
239+ onView(withText(R .string.uploader_btn_upload_text))
240+ .check(matches(isDisplayed()))
241+ .check(matches(isEnabled()))
242+
243+ onView(withId(R .id.user_input))
244+ .check(matches(not (isDisplayed())))
245+ }
246+ }
206247}
0 commit comments