Screenshot tests: Improve Activities activity tests

Force-close snackbar to not have the timing break tests

Signed-off-by: Álvaro Brey Vilas <alvaro.brey@nextcloud.com>
This commit is contained in:
Álvaro Brey Vilas 2022-01-13 11:07:47 +01:00
parent acf575e762
commit 5631d79b41
No known key found for this signature in database
GPG key ID: 2585783189A62105
8 changed files with 52 additions and 20 deletions

Binary file not shown.

Before

Width:  |  Height:  |  Size: 14 KiB

After

Width:  |  Height:  |  Size: 11 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 12 KiB

After

Width:  |  Height:  |  Size: 8.1 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 8.6 KiB

After

Width:  |  Height:  |  Size: 5.1 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 20 KiB

After

Width:  |  Height:  |  Size: 20 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 21 KiB

After

Width:  |  Height:  |  Size: 18 KiB

View file

@ -21,7 +21,6 @@
*/
package com.nextcloud.client
import android.view.View
import androidx.test.espresso.Espresso
import androidx.test.espresso.contrib.DrawerActions
import androidx.test.espresso.intent.rule.IntentsTestRule
@ -51,9 +50,9 @@ class ActivitiesActivityIT : AbstractIT() {
shortSleep()
Espresso.onView(withId(R.id.drawer_layout)).perform(DrawerActions.open())
sut.runOnUiThread {
sut.binding.emptyList.emptyListView.visibility = View.VISIBLE
sut.binding.list.visibility = View.INVISIBLE
sut.dismissSnackbar()
}
shortSleep()
waitForIdleSync()
screenshot(sut)
}
@ -62,6 +61,11 @@ class ActivitiesActivityIT : AbstractIT() {
@ScreenshotTest
fun loading() {
val sut: ActivitiesActivity = activityRule.launchActivity(null)
sut.runOnUiThread {
sut.dismissSnackbar()
}
shortSleep()
Screenshot.snapActivity(sut).record()
}
@ -74,6 +78,7 @@ class ActivitiesActivityIT : AbstractIT() {
sut.runOnUiThread {
sut.showActivities(mutableListOf(), nextcloudClient, -1)
sut.setProgressIndicatorState(false)
sut.dismissSnackbar()
}
shortSleep()
@ -164,6 +169,7 @@ class ActivitiesActivityIT : AbstractIT() {
sut.runOnUiThread {
sut.showActivities(activities as List<Any>?, nextcloudClient, -1)
sut.setProgressIndicatorState(false)
sut.dismissSnackbar()
}
shortSleep()
@ -179,6 +185,7 @@ class ActivitiesActivityIT : AbstractIT() {
sut.runOnUiThread {
sut.showEmptyContent("Error", "Error! Please try again later!")
sut.setProgressIndicatorState(false)
sut.dismissSnackbar()
}
shortSleep()

View file

@ -23,6 +23,7 @@ import android.os.Bundle;
import android.view.MenuItem;
import android.view.View;
import com.google.android.material.snackbar.Snackbar;
import com.nextcloud.client.network.ClientFactory;
import com.nextcloud.common.NextcloudClient;
import com.owncloud.android.R;
@ -51,8 +52,8 @@ import androidx.annotation.VisibleForTesting;
import androidx.recyclerview.widget.LinearLayoutManager;
import androidx.recyclerview.widget.RecyclerView;
import static com.owncloud.android.ui.activity.FileActivity.EXTRA_USER;
import static com.owncloud.android.ui.activity.FileActivity.EXTRA_FILE;
import static com.owncloud.android.ui.activity.FileActivity.EXTRA_USER;
/**
* This Activity presents activities feed.
@ -65,6 +66,7 @@ public class ActivitiesActivity extends DrawerActivity implements ActivityListIn
private int lastGiven;
private boolean isLoadingActivities;
private ActivitiesContract.ActionListener actionListener;
private Snackbar snackbar;
@Inject ActivitiesRepository activitiesRepository;
@Inject FilesRepository filesRepository;
@ -198,7 +200,7 @@ public class ActivitiesActivity extends DrawerActivity implements ActivityListIn
@Override
public void showActivitiesLoadError(String error) {
DisplayUtils.showSnackMessage(this, error);
snackbar = DisplayUtils.showSnackMessage(this, error);
}
@Override
@ -217,12 +219,12 @@ public class ActivitiesActivity extends DrawerActivity implements ActivityListIn
@Override
public void showActivityDetailUIIsNull() {
DisplayUtils.showSnackMessage(this, R.string.file_not_found);
snackbar = DisplayUtils.showSnackMessage(this, R.string.file_not_found);
}
@Override
public void showActivityDetailError(String error) {
DisplayUtils.showSnackMessage(this, error);
snackbar = DisplayUtils.showSnackMessage(this, error);
}
@Override
@ -255,4 +257,12 @@ public class ActivitiesActivity extends DrawerActivity implements ActivityListIn
actionListener.onStop();
}
@VisibleForTesting
public void dismissSnackbar() {
if (snackbar != null && snackbar.isShown()) {
snackbar.dismiss();
snackbar = null;
}
}
}

View file

@ -646,9 +646,10 @@ public final class DisplayUtils {
*
* @param activity The {@link Activity} to which's content view the {@link Snackbar} is bound.
* @param messageResource The resource id of the string resource to use. Can be formatted text.
* @return The created {@link Snackbar}
*/
public static void showSnackMessage(Activity activity, @StringRes int messageResource) {
showSnackMessage(activity.findViewById(android.R.id.content), messageResource);
public static Snackbar showSnackMessage(Activity activity, @StringRes int messageResource) {
return showSnackMessage(activity.findViewById(android.R.id.content), messageResource);
}
/**
@ -656,9 +657,12 @@ public final class DisplayUtils {
*
* @param activity The {@link Activity} to which's content view the {@link Snackbar} is bound.
* @param message Message to show.
* @return The created {@link Snackbar}
*/
public static void showSnackMessage(Activity activity, String message) {
Snackbar.make(activity.findViewById(android.R.id.content), message, Snackbar.LENGTH_LONG).show();
public static Snackbar showSnackMessage(Activity activity, String message) {
final Snackbar snackbar = Snackbar.make(activity.findViewById(android.R.id.content), message, Snackbar.LENGTH_LONG);
snackbar.show();
return snackbar;
}
/**
@ -666,9 +670,12 @@ public final class DisplayUtils {
*
* @param view The view the {@link Snackbar} is bound to.
* @param messageResource The resource id of the string resource to use. Can be formatted text.
* @return The created {@link Snackbar}
*/
public static void showSnackMessage(View view, @StringRes int messageResource) {
Snackbar.make(view, messageResource, Snackbar.LENGTH_LONG).show();
public static Snackbar showSnackMessage(View view, @StringRes int messageResource) {
final Snackbar snackbar = Snackbar.make(view, messageResource, Snackbar.LENGTH_LONG);
snackbar.show();
return snackbar;
}
/**
@ -676,9 +683,12 @@ public final class DisplayUtils {
*
* @param view The view the {@link Snackbar} is bound to.
* @param message The message.
* @return The created {@link Snackbar}
*/
public static void showSnackMessage(View view, String message) {
Snackbar.make(view, message, Snackbar.LENGTH_LONG).show();
public static Snackbar showSnackMessage(View view, String message) {
final Snackbar snackbar = Snackbar.make(view, message, Snackbar.LENGTH_LONG);
snackbar.show();
return snackbar;
}
/**
@ -686,6 +696,7 @@ public final class DisplayUtils {
*
* @param view The view the {@link Snackbar} is bound to.
* @param messageResource The resource id of the string resource to use. Can be formatted text.
* @return The created {@link Snackbar}
*/
public static Snackbar createSnackbar(View view, @StringRes int messageResource, int length) {
return Snackbar.make(view, messageResource, length);
@ -697,9 +708,10 @@ public final class DisplayUtils {
* @param activity The {@link Activity} to which's content view the {@link Snackbar} is bound.
* @param messageResource The resource id of the string resource to use. Can be formatted text.
* @param formatArgs The format arguments that will be used for substitution.
* @return The created {@link Snackbar}
*/
public static void showSnackMessage(Activity activity, @StringRes int messageResource, Object... formatArgs) {
showSnackMessage(activity, activity.findViewById(android.R.id.content), messageResource, formatArgs);
public static Snackbar showSnackMessage(Activity activity, @StringRes int messageResource, Object... formatArgs) {
return showSnackMessage(activity, activity.findViewById(android.R.id.content), messageResource, formatArgs);
}
/**
@ -709,13 +721,16 @@ public final class DisplayUtils {
* @param view The content view the {@link Snackbar} is bound to.
* @param messageResource The resource id of the string resource to use. Can be formatted text.
* @param formatArgs The format arguments that will be used for substitution.
* @return The created {@link Snackbar}
*/
public static void showSnackMessage(Context context, View view, @StringRes int messageResource, Object... formatArgs) {
Snackbar.make(
public static Snackbar showSnackMessage(Context context, View view, @StringRes int messageResource, Object... formatArgs) {
final Snackbar snackbar = Snackbar.make(
view,
String.format(context.getString(messageResource, formatArgs)),
Snackbar.LENGTH_LONG)
Snackbar.LENGTH_LONG);
snackbar
.show();
return snackbar;
}
// Solution inspired by https://stackoverflow.com/questions/34936590/why-isnt-my-vector-drawable-scaling-as-expected