11/*
22 * Nextcloud - Android Client
33 *
4+ * SPDX-FileCopyrightText: 2025 Philipp Hasper <vcs@hasper.info>
45 * SPDX-FileCopyrightText: 2019 Tobias Kaminsky <tobias@kaminsky.me>
56 * SPDX-FileCopyrightText: 2019 Nextcloud GmbH
67 * SPDX-License-Identifier: AGPL-3.0-or-later OR GPL-2.0-only
@@ -14,12 +15,14 @@ import androidx.test.espresso.Espresso.onView
1415import androidx.test.espresso.IdlingRegistry
1516import androidx.test.espresso.action.ViewActions.click
1617import androidx.test.espresso.action.ViewActions.closeSoftKeyboard
18+ import androidx.test.espresso.assertion.ViewAssertions.doesNotExist
1719import androidx.test.espresso.assertion.ViewAssertions.matches
1820import androidx.test.espresso.contrib.DrawerActions
1921import androidx.test.espresso.contrib.NavigationViewActions
2022import androidx.test.espresso.contrib.RecyclerViewActions
2123import androidx.test.espresso.matcher.ViewMatchers
2224import androidx.test.espresso.matcher.ViewMatchers.hasDescendant
25+ import androidx.test.espresso.matcher.ViewMatchers.isDisplayed
2326import androidx.test.espresso.matcher.ViewMatchers.withEffectiveVisibility
2427import androidx.test.espresso.matcher.ViewMatchers.withId
2528import androidx.test.espresso.matcher.ViewMatchers.withText
@@ -36,6 +39,7 @@ import com.owncloud.android.operations.CreateFolderOperation
3639import com.owncloud.android.ui.activity.FileDisplayActivity
3740import com.owncloud.android.ui.adapter.OCFileListItemViewHolder
3841import com.owncloud.android.utils.EspressoIdlingResource
42+ import org.hamcrest.Matchers.allOf
3943import org.junit.After
4044import org.junit.Assert.assertEquals
4145import org.junit.Assert.assertTrue
@@ -44,6 +48,7 @@ import org.junit.Rule
4448import org.junit.Test
4549
4650class FileDisplayActivityIT : AbstractOnServerIT () {
51+
4752 @Before
4853 fun registerIdlingResource () {
4954 IdlingRegistry .getInstance().register(EspressoIdlingResource .countingIdlingResource)
@@ -236,4 +241,53 @@ class FileDisplayActivityIT : AbstractOnServerIT() {
236241 }
237242 }
238243 }
244+
245+ @Test
246+ fun testShowAndDismissLoadingDialog () {
247+ launchActivity<FileDisplayActivity >().use { scenario ->
248+ val loadingText = " Some text displayed while loading"
249+
250+ // Test that display works
251+ scenario.onActivity { sut ->
252+ sut.showLoadingDialog(loadingText)
253+ }
254+ onView(withText(loadingText))
255+ .check(matches(isDisplayed()))
256+
257+ // Test that hiding works
258+ scenario.onActivity { sut ->
259+ sut.dismissLoadingDialog()
260+ }
261+ onView(allOf(withText(loadingText), isDisplayed()))
262+ .check(doesNotExist())
263+
264+ // Test that there is no timing issue when hiding the dialog directly after.
265+ // This timing issue was reproducible when testing RemoveFilesDialogFragment#removeFiles
266+ // as well as sporadically "in the wild".
267+ scenario.onActivity { sut ->
268+ sut.showLoadingDialog(loadingText)
269+ sut.dismissLoadingDialog()
270+ }
271+ onView(allOf(withText(loadingText), isDisplayed()))
272+ .check(doesNotExist())
273+ // Wait for a potential timing issue - dialog appearing belatedly
274+ Thread .sleep(1000 )
275+ onView(allOf(withText(loadingText), isDisplayed()))
276+ .check(doesNotExist())
277+
278+ // Test that multiple display calls after another don't cause a timing issue
279+ scenario.onActivity { sut ->
280+ sut.showLoadingDialog(loadingText)
281+ sut.showLoadingDialog(loadingText)
282+ sut.showLoadingDialog(loadingText)
283+ sut.dismissLoadingDialog()
284+ }
285+ onView(allOf(withText(loadingText), isDisplayed()))
286+ .check(doesNotExist())
287+ // Wait for a potential timing issue - dialog appearing belatedly
288+ Thread .sleep(1000 )
289+ onView(allOf(withText(loadingText), isDisplayed()))
290+ .check(doesNotExist())
291+ }
292+ }
239293}
0 commit comments