Skip to content

Commit ebb7775

Browse files
PhilLabalperozturk96
authored andcommitted
Test that multi file upload does not offer the renaming UI
To reduce duplication, the file and folders are setup in a @before method, but this also affects the existing screenshot tests. Signed-off-by: Philipp Hasper <vcs@hasper.info>
1 parent 4cb8996 commit ebb7775

2 files changed

Lines changed: 65 additions & 22 deletions

File tree

app/src/androidTest/java/com/owncloud/android/AbstractIT.java

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,9 @@
6767
import java.io.FileWriter;
6868
import java.io.IOException;
6969
import java.io.InputStream;
70+
import java.util.Arrays;
7071
import java.util.Collection;
72+
import java.util.List;
7173
import java.util.Locale;
7274
import java.util.Objects;
7375
import java.util.Optional;
@@ -233,17 +235,19 @@ protected Account[] getAllAccounts() {
233235
return AccountManager.get(targetContext).getAccounts();
234236
}
235237

236-
protected static void createDummyFiles() throws IOException {
238+
protected static List<File> createDummyFiles() throws IOException {
237239
File tempPath = new File(FileStorageUtils.getTemporalPath(account.name));
238240
if (!tempPath.exists()) {
239241
assertTrue(tempPath.mkdirs());
240242
}
241243

242244
assertTrue(tempPath.exists());
243245

244-
createFile("empty.txt", 0);
245-
createFile("nonEmpty.txt", 100);
246-
createFile("chunkedFile.txt", 500000);
246+
return Arrays.asList(
247+
createFile("empty.txt", 0),
248+
createFile("nonEmpty.txt", 100),
249+
createFile("chunkedFile.txt", 500000)
250+
);
247251
}
248252

249253
protected static File getDummyFile(String name) throws IOException {

app/src/androidTest/java/com/owncloud/android/ui/activity/ReceiveExternalFilesActivityIT.kt

Lines changed: 57 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@ import com.owncloud.android.R
3232
import com.owncloud.android.datamodel.OCFile
3333
import com.owncloud.android.utils.ScreenshotTest
3434
import org.hamcrest.Matchers.not
35+
import org.junit.Before
3536
import org.junit.Rule
3637
import org.junit.Test
3738
import 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() {
@@ -64,33 +87,24 @@ class ReceiveExternalFilesActivityIT : AbstractIT() {
6487
removeAccount(secondAccount)
6588
}
6689

67-
6890
fun createSendIntent(file: File): Intent = Intent(targetContext, ReceiveExternalFilesActivity::class.java).apply {
6991
action = Intent.ACTION_SEND
7092
addFlags(Intent.FLAG_GRANT_READ_URI_PERMISSION)
7193
putExtra(Intent.EXTRA_STREAM, Uri.fromFile(file))
7294
}
7395

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+
74103
@Test
75104
fun renameSingleFileUpload() {
76105
val imageFile = getDummyFile("image.jpg")
77106
val intent = createSendIntent(imageFile)
78107

79-
// Create folders with the necessary permissions and another test file
80-
val mainFolder = OCFile("/folder/").apply {
81-
permissions = OCFile.PERMISSION_CAN_CREATE_FILE_AND_FOLDER
82-
setFolder()
83-
fileDataStorageManager.saveNewFile(this)
84-
}
85-
val subFolder = OCFile("${mainFolder.remotePath}sub folder/").apply {
86-
permissions = OCFile.PERMISSION_CAN_CREATE_FILE_AND_FOLDER
87-
setFolder()
88-
fileDataStorageManager.saveNewFile(this)
89-
}
90-
val otherFile = OCFile("${mainFolder.remotePath}Other Image File.jpg").apply {
91-
fileDataStorageManager.saveNewFile(this)
92-
}
93-
94108
// Store the folder in preferences, so the activity starts from there.
95109
@Suppress("DEPRECATION")
96110
val preferences = AppPreferencesImpl.fromContext(targetContext)
@@ -149,8 +163,8 @@ class ReceiveExternalFilesActivityIT : AbstractIT() {
149163
.check(matches(not(isEnabled())))
150164
onView(withId(R.id.user_input))
151165
.perform(ViewActions.click())
152-
.perform(ViewActions.typeTextIntoFocusedView(otherFile.fileName))
153-
.check(matches(withText(otherFile.fileName)))
166+
.perform(ViewActions.typeTextIntoFocusedView(existingImageFile.fileName))
167+
.check(matches(withText(existingImageFile.fileName)))
154168
onView(withText(R.string.uploader_btn_upload_text))
155169
.check(matches(isDisplayed()))
156170
.check(matches(not(isEnabled())))
@@ -204,4 +218,29 @@ class ReceiveExternalFilesActivityIT : AbstractIT() {
204218
.check(matches(withText(imageFile.name)))
205219
}
206220
}
221+
222+
@Test
223+
fun noRenameForMultiUpload() {
224+
val testFiles = createDummyFiles()
225+
val intent = createSendIntent(testFiles)
226+
227+
// Store the folder in preferences, so the activity starts from there.
228+
@Suppress("DEPRECATION")
229+
val preferences = AppPreferencesImpl.fromContext(targetContext)
230+
preferences.setLastUploadPath(mainFolder.remotePath)
231+
232+
launchActivity<ReceiveExternalFilesActivity>(intent).use {
233+
val expectedMainFolderTitle = (getCurrentActivity() as ToolbarActivity).getActionBarTitle(mainFolder, false)
234+
// Verify that the test starts in the expected folder. If this fails, change the setup calls above
235+
onView(withId(R.id.toolbar))
236+
.check(matches(hasDescendant(withText(expectedMainFolderTitle))))
237+
238+
onView(withText(R.string.uploader_btn_upload_text))
239+
.check(matches(isDisplayed()))
240+
.check(matches(isEnabled()))
241+
242+
onView(withId(R.id.user_input))
243+
.check(matches(not(isDisplayed())))
244+
}
245+
}
207246
}

0 commit comments

Comments
 (0)