Skip to content

Commit 9445d8c

Browse files
committed
Test that move or copy files starts in the file's parent folder
This tests the changes of #15925, where the old behavior of moving up to the root folder was changed to stay in the parent folder of the file(s) to move/copy. The new behavior is in sync with iOS and the Web UI, hence this test ensures it doesn't break Signed-off-by: Philipp Hasper <vcs@hasper.info>
1 parent 39330bb commit 9445d8c

File tree

1 file changed

+64
-0
lines changed

1 file changed

+64
-0
lines changed

app/src/androidTest/java/com/owncloud/android/ui/fragment/OCFileListFragmentStaticServerIT.kt

Lines changed: 64 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
/*
22
* Nextcloud - Android Client
33
*
4+
* SPDX-FileCopyrightText: 2025 Philipp Hasper <vcs@hasper.info>
45
* SPDX-FileCopyrightText: 2025 Alper Ozturk <alper.ozturk@nextcloud.com>
56
* SPDX-FileCopyrightText: 2020 Tobias Kaminsky <tobias@kaminsky.me>
67
* SPDX-FileCopyrightText: 2020 Chris Narkiewicz <hello@ezaquarii.com>
@@ -12,19 +13,31 @@ package com.owncloud.android.ui.fragment
1213
import androidx.test.core.app.launchActivity
1314
import androidx.test.espresso.Espresso.onView
1415
import androidx.test.espresso.assertion.ViewAssertions.matches
16+
import androidx.test.espresso.intent.Intents
17+
import androidx.test.espresso.intent.Intents.intended
18+
import androidx.test.espresso.intent.matcher.IntentMatchers.hasComponent
19+
import androidx.test.espresso.matcher.ViewMatchers.isDescendantOfA
1520
import androidx.test.espresso.matcher.ViewMatchers.isDisplayed
21+
import androidx.test.espresso.matcher.ViewMatchers.isEnabled
1622
import androidx.test.espresso.matcher.ViewMatchers.isRoot
23+
import androidx.test.espresso.matcher.ViewMatchers.withId
24+
import androidx.test.espresso.matcher.ViewMatchers.withText
1725
import com.nextcloud.test.GrantStoragePermissionRule.Companion.grant
1826
import com.nextcloud.test.TestActivity
1927
import com.owncloud.android.AbstractIT
28+
import com.owncloud.android.R
2029
import com.owncloud.android.datamodel.OCFile
2130
import com.owncloud.android.lib.resources.shares.ShareType
2231
import com.owncloud.android.lib.resources.shares.ShareeUser
2332
import com.owncloud.android.lib.resources.tags.Tag
33+
import com.owncloud.android.ui.activity.FolderPickerActivity
2434
import com.owncloud.android.utils.EspressoIdlingResource
2535
import com.owncloud.android.utils.MimeType
2636
import com.owncloud.android.utils.ScreenshotTest
37+
import org.hamcrest.Matchers.allOf
38+
import org.hamcrest.Matchers.not
2739
import org.junit.Assert
40+
import org.junit.Before
2841
import org.junit.Rule
2942
import org.junit.Test
3043
import org.junit.rules.TestRule
@@ -35,6 +48,11 @@ class OCFileListFragmentStaticServerIT : AbstractIT() {
3548
@get:Rule
3649
var storagePermissionRule: TestRule = grant()
3750

51+
@Before
52+
fun initIntentRecording() {
53+
Intents.init()
54+
}
55+
3856
@Test
3957
@ScreenshotTest
4058
@Suppress("MagicNumber")
@@ -397,4 +415,50 @@ class OCFileListFragmentStaticServerIT : AbstractIT() {
397415
Assert.assertTrue(sut.adapter.shouldShowHeader())
398416
}
399417
}
418+
419+
@Test
420+
fun shouldStartMoveInParentFolder() {
421+
launchActivity<TestActivity>().use { scenario ->
422+
val fragment = OCFileListFragment()
423+
var testFolder: OCFile? = null
424+
425+
scenario.onActivity { activity ->
426+
testFolder = OCFile("/folder/").apply {
427+
setFolder()
428+
}
429+
activity.storageManager.saveNewFile(testFolder)
430+
431+
val testFile = OCFile("${testFolder.remotePath}myImage.png").apply {
432+
parentId = testFolder.fileId
433+
activity.storageManager.saveNewFile(this)
434+
}
435+
436+
activity.addFragment(fragment)
437+
activity.supportFragmentManager.executePendingTransactions()
438+
439+
fragment.listDirectory(testFolder, false)
440+
activity.supportFragmentManager.executePendingTransactions()
441+
fragment.onFileActionChosen(R.id.action_move_or_copy, setOf(testFile))
442+
activity.supportFragmentManager.executePendingTransactions()
443+
}
444+
// Check that the FolderPickerActivity was opened
445+
intended(hasComponent(FolderPickerActivity::class.java.canonicalName))
446+
447+
// Check that the Action Bar shows the current folder name as title
448+
onView(
449+
allOf(
450+
isDescendantOfA(withId(R.id.toolbar)),
451+
withText(testFolder!!.fileName)
452+
)
453+
).check(matches(isDisplayed()))
454+
455+
// Test the button's enabled status. "Move" should not be enabled, but the rest should.
456+
onView(allOf(withId(R.id.folder_picker_btn_cancel), isDisplayed()))
457+
.check(matches(isEnabled()))
458+
onView(allOf(withId(R.id.folder_picker_btn_copy), isDisplayed()))
459+
.check(matches(isEnabled()))
460+
onView(allOf(withId(R.id.folder_picker_btn_move), isDisplayed()))
461+
.check(matches(not(isEnabled())))
462+
}
463+
}
400464
}

0 commit comments

Comments
 (0)