Skip to content

Commit 24e7455

Browse files
Merge pull request #16262 from nextcloud/test_15925_move_or_copy_start_in_parent
Test that move or copy files starts in the file's parent folder
2 parents f2e84b3 + 54e9c43 commit 24e7455

File tree

1 file changed

+62
-0
lines changed

1 file changed

+62
-0
lines changed

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

Lines changed: 62 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 <[email protected]>
45
* SPDX-FileCopyrightText: 2025 Alper Ozturk <[email protected]>
56
* SPDX-FileCopyrightText: 2020 Tobias Kaminsky <[email protected]>
67
* SPDX-FileCopyrightText: 2020 Chris Narkiewicz <[email protected]>
@@ -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,48 @@ 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+
fragment.onFileActionChosen(R.id.action_move_or_copy, setOf(testFile))
441+
}
442+
// Check that the FolderPickerActivity was opened
443+
intended(hasComponent(FolderPickerActivity::class.java.canonicalName))
444+
445+
// Check that the Action Bar shows the current folder name as title
446+
onView(
447+
allOf(
448+
isDescendantOfA(withId(R.id.toolbar)),
449+
withText(testFolder!!.fileName)
450+
)
451+
).check(matches(isDisplayed()))
452+
453+
// Test the button's enabled status. "Move" should not be enabled, but the rest should.
454+
onView(allOf(withId(R.id.folder_picker_btn_cancel), isDisplayed()))
455+
.check(matches(isEnabled()))
456+
onView(allOf(withId(R.id.folder_picker_btn_copy), isDisplayed()))
457+
.check(matches(isEnabled()))
458+
onView(allOf(withId(R.id.folder_picker_btn_move), isDisplayed()))
459+
.check(matches(not(isEnabled())))
460+
}
461+
}
400462
}

0 commit comments

Comments
 (0)