From 8a693302cad8eb23960b709317c54d2cb844604b Mon Sep 17 00:00:00 2001 From: Victor Andreasson Date: Wed, 24 Apr 2024 01:12:02 +0200 Subject: [PATCH] Work around mysterious button text not matching string The test works just fine on API 33, but on API 34 the string "4:05 AM" will never match, even though the actual textView looks exactly right. Strangely, matching any whitespace character instead of the space between "4:05" and "AM" works. I have no idea what is going on. And no other tests behave like this. --- .../com/orgzly/android/espresso/MiscTest.java | 22 +++++++------------ 1 file changed, 8 insertions(+), 14 deletions(-) diff --git a/app/src/androidTest/java/com/orgzly/android/espresso/MiscTest.java b/app/src/androidTest/java/com/orgzly/android/espresso/MiscTest.java index 43d6dce90..263caff8c 100644 --- a/app/src/androidTest/java/com/orgzly/android/espresso/MiscTest.java +++ b/app/src/androidTest/java/com/orgzly/android/espresso/MiscTest.java @@ -32,6 +32,7 @@ import static org.hamcrest.Matchers.allOf; import static org.hamcrest.Matchers.containsString; import static org.hamcrest.Matchers.equalTo; +import static org.hamcrest.Matchers.matchesPattern; import static org.hamcrest.Matchers.not; import static org.hamcrest.Matchers.startsWith; import static org.junit.Assert.assertTrue; @@ -39,7 +40,6 @@ import android.app.Activity; import android.content.pm.ActivityInfo; import android.os.SystemClock; -import android.text.format.DateFormat; import android.view.View; import android.widget.DatePicker; import android.widget.TimePicker; @@ -49,26 +49,19 @@ import com.orgzly.BuildConfig; import com.orgzly.R; import com.orgzly.android.OrgzlyTest; -import com.orgzly.android.RetryTestRule; import com.orgzly.android.db.entity.NotePosition; +import com.orgzly.android.espresso.util.EspressoUtils; import com.orgzly.android.repos.RepoType; import com.orgzly.android.ui.main.MainActivity; import com.orgzly.android.ui.repos.ReposActivity; import org.hamcrest.Matcher; import org.junit.Assume; -import org.junit.Rule; import org.junit.Test; -import org.junit.rules.TestRule; -import java.util.Calendar; -import java.util.GregorianCalendar; public class MiscTest extends OrgzlyTest { - @Rule - public TestRule mRetryTestRule = new RetryTestRule(); - @Test public void testLftRgt() { testUtils.setupBook("booky", "Preface\n* Note 1\n** Note 2\n* Note 3\n"); @@ -191,6 +184,7 @@ public void testSchedulingMultipleNotes() { "*** DONE Note #5.\n" + "CLOSED: [2014-06-03 Tue 13:34]\n" + ""); + EspressoUtils.grantAlarmsAndRemindersPermission(); try (ActivityScenario ignored = ActivityScenario.launch(MainActivity.class)) { onView(allOf(withText("book-name"), isDisplayed())).perform(click()); @@ -272,6 +266,7 @@ public void testBookTitleMustBeDisplayedWhenOpeningBookFromDrawer() { @Test public void testTimestampDialogTimeButtonValueWhenToggling() { + EspressoUtils.grantAlarmsAndRemindersPermission(); testUtils.setupBook("book-name", "Sample book used for tests\n" + "* TODO Note #1.\n" + "SCHEDULED: <2015-01-18 04:05 +6d>\n" + @@ -282,15 +277,14 @@ public void testTimestampDialogTimeButtonValueWhenToggling() { onNoteInBook(1).perform(click()); - Calendar cal = new GregorianCalendar(2015, 0, 18, 4, 5); - String s = DateFormat.getTimeFormat(context).format(cal.getTime()); + String regex = "4:05\\sAM"; onView(withId(R.id.scheduled_button)).perform(click()); - onView(withId(R.id.time_picker_button)).check(matches(withText(containsString(s)))); + onView(withId(R.id.time_picker_button)).check(matches(withText(matchesPattern(regex)))); onView(withId(R.id.time_used_checkbox)).perform(scroll(), click()); - onView(withId(R.id.time_picker_button)).check(matches(withText(containsString(s)))); + onView(withId(R.id.time_picker_button)).check(matches(withText(matchesPattern(regex)))); onView(withId(R.id.time_used_checkbox)).perform(click()); - onView(withId(R.id.time_picker_button)).check(matches(withText(containsString(s)))); + onView(withId(R.id.time_picker_button)).check(matches(withText(matchesPattern(regex)))); } }