@@ -145,18 +145,11 @@ class PreviewImageActivityIT : AbstractOnServerIT() {
145145 Espresso .setFailureHandler(DefaultFailureHandler (targetContext))
146146 }
147147
148- @Before
149- fun bringUp () {
150- IdlingRegistry .getInstance().register(fileRemovedIdlingResource)
151- }
152-
153- @After
154- fun tearDown () {
155- IdlingRegistry .getInstance().unregister(fileRemovedIdlingResource)
156- }
157-
158- private fun testDeleteFromSlideshow_impl (localOnly : Boolean , offline : Boolean ) {
159- // Prepare local test data
148+ private fun executeDeletionTestScenario (
149+ localOnly : Boolean ,
150+ offline : Boolean ,
151+ fileListTransformation : (List <OCFile >) -> List <OCFile >
152+ ) {
160153 val imageCount = 5
161154 val testFiles = if (localOnly) {
162155 createLocalMockedImageFiles(
@@ -165,9 +158,9 @@ class PreviewImageActivityIT : AbstractOnServerIT() {
165158 } else {
166159 createAndUploadImageFiles(imageCount)
167160 }
161+ val expectedFileOrder = fileListTransformation(testFiles)
168162
169- // Launch the activity with the first image
170- val intent = PreviewImageActivity .previewFileIntent(targetContext, user, testFiles[0 ])
163+ val intent = PreviewImageActivity .previewFileIntent(targetContext, user, expectedFileOrder.first())
171164 launchActivity<PreviewImageActivity >(intent).use { scenario ->
172165 if (offline) {
173166 scenario.onActivity { activity ->
@@ -176,7 +169,7 @@ class PreviewImageActivityIT : AbstractOnServerIT() {
176169 }
177170 onView(isRoot()).check(matches(isDisplayed()))
178171
179- for (testFile in testFiles ) {
172+ for (testFile in expectedFileOrder ) {
180173 veryImageThenDelete(testFile)
181174 assertTrue(
182175 " Test file still exists on the server: ${testFile.remotePath} " ,
@@ -186,6 +179,27 @@ class PreviewImageActivityIT : AbstractOnServerIT() {
186179 }
187180 }
188181
182+ private fun testDeleteFromSlideshow_impl (localOnly : Boolean , offline : Boolean ) {
183+ // Case 1: start at first image
184+ executeDeletionTestScenario(localOnly, offline) { list -> list }
185+ // Case 2: start at last image (reversed)
186+ executeDeletionTestScenario(localOnly, offline) { list -> list.reversed() }
187+ // Case 3: Start in the middle. From middle to the end, then backwards through remaining files of the first half
188+ executeDeletionTestScenario(localOnly, offline) { list ->
189+ list.subList(list.size / 2 , list.size) + list.subList(0 , list.size / 2 ).reversed()
190+ }
191+ }
192+
193+ @Before
194+ fun bringUp () {
195+ IdlingRegistry .getInstance().register(fileRemovedIdlingResource)
196+ }
197+
198+ @After
199+ fun tearDown () {
200+ IdlingRegistry .getInstance().unregister(fileRemovedIdlingResource)
201+ }
202+
189203 @Test
190204 fun deleteFromSlideshow_localOnly_online () {
191205 testDeleteFromSlideshow_impl(localOnly = true , offline = false )
0 commit comments