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

View file

@ -23,6 +23,7 @@ import android.os.Bundle;
import android.view.MenuItem; import android.view.MenuItem;
import android.view.View; import android.view.View;
import com.google.android.material.snackbar.Snackbar;
import com.nextcloud.client.network.ClientFactory; import com.nextcloud.client.network.ClientFactory;
import com.nextcloud.common.NextcloudClient; import com.nextcloud.common.NextcloudClient;
import com.owncloud.android.R; import com.owncloud.android.R;
@ -51,8 +52,8 @@ import androidx.annotation.VisibleForTesting;
import androidx.recyclerview.widget.LinearLayoutManager; import androidx.recyclerview.widget.LinearLayoutManager;
import androidx.recyclerview.widget.RecyclerView; 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_FILE;
import static com.owncloud.android.ui.activity.FileActivity.EXTRA_USER;
/** /**
* This Activity presents activities feed. * This Activity presents activities feed.
@ -65,6 +66,7 @@ public class ActivitiesActivity extends DrawerActivity implements ActivityListIn
private int lastGiven; private int lastGiven;
private boolean isLoadingActivities; private boolean isLoadingActivities;
private ActivitiesContract.ActionListener actionListener; private ActivitiesContract.ActionListener actionListener;
private Snackbar snackbar;
@Inject ActivitiesRepository activitiesRepository; @Inject ActivitiesRepository activitiesRepository;
@Inject FilesRepository filesRepository; @Inject FilesRepository filesRepository;
@ -198,7 +200,7 @@ public class ActivitiesActivity extends DrawerActivity implements ActivityListIn
@Override @Override
public void showActivitiesLoadError(String error) { public void showActivitiesLoadError(String error) {
DisplayUtils.showSnackMessage(this, error); snackbar = DisplayUtils.showSnackMessage(this, error);
} }
@Override @Override
@ -217,12 +219,12 @@ public class ActivitiesActivity extends DrawerActivity implements ActivityListIn
@Override @Override
public void showActivityDetailUIIsNull() { public void showActivityDetailUIIsNull() {
DisplayUtils.showSnackMessage(this, R.string.file_not_found); snackbar = DisplayUtils.showSnackMessage(this, R.string.file_not_found);
} }
@Override @Override
public void showActivityDetailError(String error) { public void showActivityDetailError(String error) {
DisplayUtils.showSnackMessage(this, error); snackbar = DisplayUtils.showSnackMessage(this, error);
} }
@Override @Override
@ -255,4 +257,12 @@ public class ActivitiesActivity extends DrawerActivity implements ActivityListIn
actionListener.onStop(); 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 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 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) { public static Snackbar showSnackMessage(Activity activity, @StringRes int messageResource) {
showSnackMessage(activity.findViewById(android.R.id.content), 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 activity The {@link Activity} to which's content view the {@link Snackbar} is bound.
* @param message Message to show. * @param message Message to show.
* @return The created {@link Snackbar}
*/ */
public static void showSnackMessage(Activity activity, String message) { public static Snackbar showSnackMessage(Activity activity, String message) {
Snackbar.make(activity.findViewById(android.R.id.content), message, Snackbar.LENGTH_LONG).show(); 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 view The view the {@link Snackbar} is bound to.
* @param messageResource The resource id of the string resource to use. Can be formatted text. * @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) { public static Snackbar showSnackMessage(View view, @StringRes int messageResource) {
Snackbar.make(view, messageResource, Snackbar.LENGTH_LONG).show(); 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 view The view the {@link Snackbar} is bound to.
* @param message The message. * @param message The message.
* @return The created {@link Snackbar}
*/ */
public static void showSnackMessage(View view, String message) { public static Snackbar showSnackMessage(View view, String message) {
Snackbar.make(view, message, Snackbar.LENGTH_LONG).show(); 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 view The view the {@link Snackbar} is bound to.
* @param messageResource The resource id of the string resource to use. Can be formatted text. * @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) { public static Snackbar createSnackbar(View view, @StringRes int messageResource, int length) {
return Snackbar.make(view, messageResource, 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 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 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. * @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) { public static Snackbar showSnackMessage(Activity activity, @StringRes int messageResource, Object... formatArgs) {
showSnackMessage(activity, activity.findViewById(android.R.id.content), messageResource, 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 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 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. * @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) { public static Snackbar showSnackMessage(Context context, View view, @StringRes int messageResource, Object... formatArgs) {
Snackbar.make( final Snackbar snackbar = Snackbar.make(
view, view,
String.format(context.getString(messageResource, formatArgs)), String.format(context.getString(messageResource, formatArgs)),
Snackbar.LENGTH_LONG) Snackbar.LENGTH_LONG);
snackbar
.show(); .show();
return snackbar;
} }
// Solution inspired by https://stackoverflow.com/questions/34936590/why-isnt-my-vector-drawable-scaling-as-expected // Solution inspired by https://stackoverflow.com/questions/34936590/why-isnt-my-vector-drawable-scaling-as-expected