Skip to content

Commit

Permalink
Work around mysterious button text not matching string
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
amberin committed May 5, 2024
1 parent 3834676 commit 8a69330
Showing 1 changed file with 8 additions and 14 deletions.
22 changes: 8 additions & 14 deletions app/src/androidTest/java/com/orgzly/android/espresso/MiscTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -32,14 +32,14 @@
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;

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;
Expand All @@ -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");
Expand Down Expand Up @@ -191,6 +184,7 @@ public void testSchedulingMultipleNotes() {
"*** DONE Note #5.\n" +
"CLOSED: [2014-06-03 Tue 13:34]\n" +
"");
EspressoUtils.grantAlarmsAndRemindersPermission();
try (ActivityScenario<MainActivity> ignored = ActivityScenario.launch(MainActivity.class)) {
onView(allOf(withText("book-name"), isDisplayed())).perform(click());

Expand Down Expand Up @@ -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" +
Expand All @@ -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))));
}
}

Expand Down

0 comments on commit 8a69330

Please sign in to comment.