-
-
Notifications
You must be signed in to change notification settings - Fork 1.8k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #13671 from nextcloud/fix/FileDisplayActivityScree…
…nshotIT-test Fix - FileDisplayActivityScreenshotIT Tests
- Loading branch information
Showing
1 changed file
with
103 additions
and
61 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,35 +1,49 @@ | ||
/* | ||
* Nextcloud - Android Client | ||
* | ||
* SPDX-FileCopyrightText: 2024 Alper Ozturk <[email protected]> | ||
* SPDX-FileCopyrightText: 2019 Tobias Kaminsky <[email protected]> | ||
* SPDX-FileCopyrightText: 2019 Nextcloud GmbH | ||
* SPDX-License-Identifier: AGPL-3.0-or-later OR GPL-2.0-only | ||
*/ | ||
package com.nextcloud.client | ||
|
||
import android.Manifest | ||
import androidx.test.espresso.Espresso | ||
import androidx.annotation.UiThread | ||
import androidx.test.core.app.launchActivity | ||
import androidx.test.espresso.Espresso.onView | ||
import androidx.test.espresso.IdlingRegistry | ||
import androidx.test.espresso.assertion.ViewAssertions.matches | ||
import androidx.test.espresso.contrib.DrawerActions | ||
import androidx.test.espresso.contrib.NavigationViewActions | ||
import androidx.test.espresso.intent.rule.IntentsTestRule | ||
import androidx.test.espresso.matcher.ViewMatchers | ||
import androidx.test.espresso.matcher.ViewMatchers.isDisplayed | ||
import androidx.test.espresso.matcher.ViewMatchers.isRoot | ||
import androidx.test.rule.GrantPermissionRule | ||
import com.owncloud.android.AbstractIT | ||
import com.owncloud.android.R | ||
import com.owncloud.android.lib.common.utils.Log_OC | ||
import com.owncloud.android.ui.activity.FileDisplayActivity | ||
import com.owncloud.android.utils.EspressoIdlingResource | ||
import com.owncloud.android.utils.ScreenshotTest | ||
import org.junit.After | ||
import org.junit.Assert | ||
import org.junit.Before | ||
import org.junit.Rule | ||
import org.junit.Test | ||
|
||
class FileDisplayActivityScreenshotIT : AbstractIT() { | ||
@get:Rule | ||
val activityRule = IntentsTestRule( | ||
FileDisplayActivity::class.java, | ||
true, | ||
false | ||
) | ||
private val testClassName = "com.nextcloud.client.FileDisplayActivityScreenshotIT" | ||
|
||
@Before | ||
fun registerIdlingResource() { | ||
IdlingRegistry.getInstance().register(EspressoIdlingResource.countingIdlingResource) | ||
} | ||
|
||
@After | ||
fun unregisterIdlingResource() { | ||
IdlingRegistry.getInstance().unregister(EspressoIdlingResource.countingIdlingResource) | ||
} | ||
|
||
@get:Rule | ||
val permissionRule: GrantPermissionRule = GrantPermissionRule.grant( | ||
|
@@ -41,82 +55,110 @@ class FileDisplayActivityScreenshotIT : AbstractIT() { | |
} | ||
|
||
@Test | ||
@UiThread | ||
@ScreenshotTest | ||
fun open() { | ||
try { | ||
val sut = activityRule.launchActivity(null) | ||
|
||
shortSleep() | ||
sut.runOnUiThread { | ||
sut.listOfFilesFragment!!.setFabEnabled(false) | ||
sut.resetScrolling(true) | ||
sut.listOfFilesFragment!!.setEmptyListLoadingMessage() | ||
sut.listOfFilesFragment!!.isLoading = false | ||
launchActivity<FileDisplayActivity>().use { scenario -> | ||
scenario.onActivity { sut -> | ||
onIdleSync { | ||
EspressoIdlingResource.increment() | ||
|
||
sut.run { | ||
listOfFilesFragment?.let { | ||
it.setFabEnabled(false) | ||
resetScrolling(true) | ||
it.setEmptyListLoadingMessage() | ||
it.isLoading = false | ||
} | ||
} | ||
|
||
EspressoIdlingResource.decrement() | ||
|
||
val screenShotName = createName(testClassName + "_" + "open", "") | ||
onView(isRoot()).check(matches(isDisplayed())) | ||
screenshotViaName(sut, screenShotName) | ||
} | ||
} | ||
} | ||
shortSleep() | ||
waitForIdleSync() | ||
screenshot(sut) | ||
} catch (e: SecurityException) { | ||
Log_OC.e(TAG, "Error caught at open $e") | ||
} | ||
} | ||
|
||
@Test | ||
@UiThread | ||
@ScreenshotTest | ||
fun showMediaThenAllFiles() { | ||
try { | ||
val fileDisplayActivity = activityRule.launchActivity(null) | ||
val sut = fileDisplayActivity.listOfFilesFragment | ||
Assert.assertNotNull(sut) | ||
sut!!.setFabEnabled(false) | ||
sut.setEmptyListLoadingMessage() | ||
sut.isLoading = false | ||
|
||
// open drawer | ||
Espresso.onView(ViewMatchers.withId(R.id.drawer_layout)).perform(DrawerActions.open()) | ||
|
||
// click "all files" | ||
Espresso.onView(ViewMatchers.withId(R.id.nav_view)) | ||
.perform(NavigationViewActions.navigateTo(R.id.nav_gallery)) | ||
|
||
// wait | ||
shortSleep() | ||
|
||
// click "all files" | ||
Espresso.onView(ViewMatchers.withId(R.id.drawer_layout)).perform(DrawerActions.open()) | ||
Espresso.onView(ViewMatchers.withId(R.id.nav_view)) | ||
.perform(NavigationViewActions.navigateTo(R.id.nav_all_files)) | ||
|
||
// then compare screenshot | ||
shortSleep() | ||
sut.setFabEnabled(false) | ||
sut.setEmptyListLoadingMessage() | ||
sut.isLoading = false | ||
shortSleep() | ||
screenshot(fileDisplayActivity) | ||
launchActivity<FileDisplayActivity>().use { scenario -> | ||
scenario.onActivity { sut -> | ||
onIdleSync { | ||
EspressoIdlingResource.increment() | ||
val fragment = sut.listOfFilesFragment | ||
Assert.assertNotNull(fragment) | ||
fragment!!.setFabEnabled(false) | ||
fragment.setEmptyListLoadingMessage() | ||
fragment.isLoading = false | ||
EspressoIdlingResource.decrement() | ||
|
||
onView(ViewMatchers.withId(R.id.drawer_layout)).perform(DrawerActions.open()) | ||
|
||
onView(ViewMatchers.withId(R.id.nav_view)) | ||
.perform(NavigationViewActions.navigateTo(R.id.nav_gallery)) | ||
|
||
onView(ViewMatchers.withId(R.id.drawer_layout)).perform(DrawerActions.open()) | ||
onView(ViewMatchers.withId(R.id.nav_view)) | ||
.perform(NavigationViewActions.navigateTo(R.id.nav_all_files)) | ||
|
||
EspressoIdlingResource.increment() | ||
fragment.setFabEnabled(false) | ||
fragment.setEmptyListLoadingMessage() | ||
fragment.isLoading = false | ||
EspressoIdlingResource.decrement() | ||
|
||
val screenShotName = createName(testClassName + "_" + "showMediaThenAllFiles", "") | ||
onView(isRoot()).check(matches(isDisplayed())) | ||
screenshotViaName(sut, screenShotName) | ||
} | ||
} | ||
} | ||
} catch (e: SecurityException) { | ||
Log_OC.e(TAG, "Error caught at open $e") | ||
} | ||
} | ||
|
||
@Test | ||
@UiThread | ||
@ScreenshotTest | ||
fun drawer() { | ||
try { | ||
val sut = activityRule.launchActivity(null) | ||
Espresso.onView(ViewMatchers.withId(R.id.drawer_layout)).perform(DrawerActions.open()) | ||
|
||
shortSleep() | ||
sut.runOnUiThread { | ||
sut.hideInfoBox() | ||
sut.resetScrolling(true) | ||
sut.listOfFilesFragment!!.setFabEnabled(false) | ||
sut.listOfFilesFragment!!.setEmptyListLoadingMessage() | ||
sut.listOfFilesFragment!!.isLoading = false | ||
launchActivity<FileDisplayActivity>().use { scenario -> | ||
scenario.onActivity { sut -> | ||
onIdleSync { | ||
onView(ViewMatchers.withId(R.id.drawer_layout)).perform(DrawerActions.open()) | ||
|
||
EspressoIdlingResource.increment() | ||
|
||
sut.run { | ||
hideInfoBox() | ||
resetScrolling(true) | ||
|
||
listOfFilesFragment?.let { | ||
it.setFabEnabled(false) | ||
it.setEmptyListLoadingMessage() | ||
it.isLoading = false | ||
} | ||
} | ||
|
||
EspressoIdlingResource.decrement() | ||
|
||
val screenShotName = createName(testClassName + "_" + "drawer", "") | ||
onView(isRoot()).check(matches(isDisplayed())) | ||
screenshotViaName(sut, screenShotName) | ||
} | ||
} | ||
} | ||
shortSleep() | ||
waitForIdleSync() | ||
screenshot(sut) | ||
} catch (e: SecurityException) { | ||
Log_OC.e(TAG, "Error caught at open $e") | ||
} | ||
|