Skip to content

Commit a99eec4

Browse files
committed
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 0435482 commit a99eec4

File tree

2 files changed

+65
-22
lines changed

2 files changed

+65
-22
lines changed

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

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,9 @@
6868
import java.io.FileWriter;
6969
import java.io.IOException;
7070
import java.io.InputStream;
71+
import java.util.Arrays;
7172
import java.util.Collection;
73+
import java.util.List;
7274
import java.util.Locale;
7375
import java.util.Objects;
7476
import java.util.Optional;
@@ -234,17 +236,19 @@ protected Account[] getAllAccounts() {
234236
return AccountManager.get(targetContext).getAccounts();
235237
}
236238

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

243245
assertTrue(tempPath.exists());
244246

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

250254
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
@@ -31,6 +31,7 @@ import com.owncloud.android.R
3131
import com.owncloud.android.datamodel.OCFile
3232
import com.owncloud.android.utils.ScreenshotTest
3333
import org.hamcrest.Matchers.not
34+
import org.junit.Before
3435
import org.junit.Rule
3536
import org.junit.Test
3637
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() {
@@ -63,33 +86,24 @@ class ReceiveExternalFilesActivityIT : AbstractIT() {
6386
removeAccount(secondAccount)
6487
}
6588

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

95+
fun createSendIntent(files: Iterable<File>): Intent =
96+
Intent(targetContext, ReceiveExternalFilesActivity::class.java).apply {
97+
action = Intent.ACTION_SEND_MULTIPLE
98+
addFlags(Intent.FLAG_GRANT_READ_URI_PERMISSION)
99+
putParcelableArrayListExtra(Intent.EXTRA_STREAM, ArrayList(files.map { Uri.fromFile(it) }))
100+
}
101+
73102
@Test
74103
fun renameSingleFileUpload() {
75104
val imageFile = getDummyFile("image.jpg")
76105
val intent = createSendIntent(imageFile)
77106

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-
}
92-
93107
// Store the folder in preferences, so the activity starts from there.
94108
@Suppress("DEPRECATION")
95109
val preferences = AppPreferencesImpl.fromContext(targetContext)
@@ -148,8 +162,8 @@ class ReceiveExternalFilesActivityIT : AbstractIT() {
148162
.check(matches(not(isEnabled())))
149163
onView(withId(R.id.user_input))
150164
.perform(ViewActions.click())
151-
.perform(ViewActions.typeTextIntoFocusedView(otherFile.fileName))
152-
.check(matches(withText(otherFile.fileName)))
165+
.perform(ViewActions.typeTextIntoFocusedView(existingImageFile.fileName))
166+
.check(matches(withText(existingImageFile.fileName)))
153167
onView(withText(R.string.uploader_btn_upload_text))
154168
.check(matches(isDisplayed()))
155169
.check(matches(not(isEnabled())))
@@ -203,4 +217,29 @@ class ReceiveExternalFilesActivityIT : AbstractIT() {
203217
.check(matches(withText(imageFile.name)))
204218
}
205219
}
220+
221+
@Test
222+
fun noRenameForMultiUpload() {
223+
val testFiles = createDummyFiles()
224+
val intent = createSendIntent(testFiles)
225+
226+
// Store the folder in preferences, so the activity starts from there.
227+
@Suppress("DEPRECATION")
228+
val preferences = AppPreferencesImpl.fromContext(targetContext)
229+
preferences.setLastUploadPath(mainFolder.remotePath)
230+
231+
launchActivity<ReceiveExternalFilesActivity>(intent).use {
232+
val expectedMainFolderTitle = (getCurrentActivity() as ToolbarActivity).getActionBarTitle(mainFolder, false)
233+
// Verify that the test starts in the expected folder. If this fails, change the setup calls above
234+
onView(withId(R.id.toolbar))
235+
.check(matches(hasDescendant(withText(expectedMainFolderTitle))))
236+
237+
onView(withText(R.string.uploader_btn_upload_text))
238+
.check(matches(isDisplayed()))
239+
.check(matches(isEnabled()))
240+
241+
onView(withId(R.id.user_input))
242+
.check(matches(not(isDisplayed())))
243+
}
244+
}
206245
}

0 commit comments

Comments
 (0)