From dfb13ca7a4830d32a5b905de38a729d329155b51 Mon Sep 17 00:00:00 2001 From: Hocuri Date: Fri, 1 Oct 2021 13:31:38 +0200 Subject: [PATCH] Don't let the doze dialog make the tests fail --- androidTest/com/b44t/messenger/TestUtils.java | 18 ++++++++++++++++-- .../uitests/online/OnboardingTest.java | 12 +----------- 2 files changed, 17 insertions(+), 13 deletions(-) diff --git a/androidTest/com/b44t/messenger/TestUtils.java b/androidTest/com/b44t/messenger/TestUtils.java index 1b600d963..1eb61642e 100644 --- a/androidTest/com/b44t/messenger/TestUtils.java +++ b/androidTest/com/b44t/messenger/TestUtils.java @@ -1,5 +1,6 @@ package com.b44t.messenger; +import android.app.Activity; import android.content.ComponentName; import android.content.Context; import android.content.Intent; @@ -62,16 +63,29 @@ public class TestUtils { Intent intent = Intent.makeMainActivity( new ComponentName(getInstrumentation().getTargetContext(), ConversationListActivity.class)); - TestUtils.createOfflineAccount(); + createOfflineAccount(); + prepare(); return new ActivityScenarioRule<>(intent); } + @NonNull + public static ActivityScenarioRule getOnlineActivityRule(Class activityClass) { + Context context = getInstrumentation().getTargetContext(); + AccountManager.getInstance().beginAccountCreation(context); + prepare(); + return new ActivityScenarioRule<>(new Intent(getInstrumentation().getTargetContext(), activityClass)); + } + + private static void prepare() { + Prefs.setBooleanPreference(getInstrumentation().getTargetContext(), Prefs.DOZE_ASKED_DIRECTLY, true); + } + /** * Perform action of waiting for a certain view within a single root view * * @param matcher Generic Matcher used to find our view */ - static ViewAction searchFor(Matcher matcher) { + private static ViewAction searchFor(Matcher matcher) { return new ViewAction() { public Matcher getConstraints() { diff --git a/androidTest/com/b44t/messenger/uitests/online/OnboardingTest.java b/androidTest/com/b44t/messenger/uitests/online/OnboardingTest.java index ea5726550..64bc50137 100644 --- a/androidTest/com/b44t/messenger/uitests/online/OnboardingTest.java +++ b/androidTest/com/b44t/messenger/uitests/online/OnboardingTest.java @@ -1,8 +1,6 @@ package com.b44t.messenger.uitests.online; -import android.content.Context; -import android.content.Intent; import android.text.TextUtils; import androidx.test.ext.junit.rules.ActivityScenarioRule; @@ -18,7 +16,6 @@ import org.junit.runner.RunWith; import org.thoughtcrime.securesms.BuildConfig; import org.thoughtcrime.securesms.R; import org.thoughtcrime.securesms.WelcomeActivity; -import org.thoughtcrime.securesms.connect.AccountManager; import static androidx.test.espresso.Espresso.onView; import static androidx.test.espresso.action.ViewActions.click; @@ -28,19 +25,12 @@ import static androidx.test.espresso.matcher.ViewMatchers.isClickable; import static androidx.test.espresso.matcher.ViewMatchers.withContentDescription; import static androidx.test.espresso.matcher.ViewMatchers.withHint; import static androidx.test.espresso.matcher.ViewMatchers.withText; -import static androidx.test.platform.app.InstrumentationRegistry.getInstrumentation; @RunWith(AndroidJUnit4.class) @LargeTest public class OnboardingTest { @Rule - public ActivityScenarioRule activityRule = new ActivityScenarioRule<>(getIntent()); - - private Intent getIntent() { - Context context = getInstrumentation().getTargetContext(); - AccountManager.getInstance().beginAccountCreation(context); - return new Intent(getInstrumentation().getTargetContext(), WelcomeActivity.class); - } + public ActivityScenarioRule activityRule = TestUtils.getOnlineActivityRule(WelcomeActivity.class); @Test public void testAccountCreation() {