Skip to content

Commit

Permalink
Ensure keyboard is closed after search input
Browse files Browse the repository at this point in the history
  • Loading branch information
amberin committed Mar 17, 2024
1 parent cb75a86 commit a927baa
Show file tree
Hide file tree
Showing 7 changed files with 94 additions and 93 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
import static com.orgzly.android.espresso.util.EspressoUtils.onItemInAgenda;
import static com.orgzly.android.espresso.util.EspressoUtils.onNotesInAgenda;
import static com.orgzly.android.espresso.util.EspressoUtils.recyclerViewItemCount;
import static com.orgzly.android.espresso.util.EspressoUtils.searchForText;
import static com.orgzly.android.espresso.util.EspressoUtils.searchForTextCloseKeyboard;
import static org.hamcrest.Matchers.allOf;
import static org.hamcrest.Matchers.endsWith;
import static org.hamcrest.Matchers.equalTo;
Expand Down Expand Up @@ -74,7 +74,7 @@ public void tearDown() throws Exception {
@Test
public void testAgendaSavedSearch() {
scenario = defaultSetUp();
searchForText(".it.done ad.7");
searchForTextCloseKeyboard(".it.done ad.7");
/*
* 1 Overdue
* 1 Note B
Expand All @@ -90,16 +90,16 @@ public void testAgendaSavedSearch() {
@Test
public void testWithNoBook() {
scenario = ActivityScenario.launch(MainActivity.class);
searchForText(".it.done (s.7d or d.7d) ad.7");
searchForTextCloseKeyboard(".it.done (s.7d or d.7d) ad.7");
onNotesInAgenda().check(matches(recyclerViewItemCount(7)));
searchForText(".it.done (s.7d or d.7d) ad.3");
searchForTextCloseKeyboard(".it.done (s.7d or d.7d) ad.3");
onNotesInAgenda().check(matches(recyclerViewItemCount(3)));
}

@Test
public void testDayAgenda() {
scenario = defaultSetUp();
searchForText(".it.done (s.7d or d.7d) ad.1");
searchForTextCloseKeyboard(".it.done (s.7d or d.7d) ad.1");
onNotesInAgenda().check(matches(recyclerViewItemCount(7)));
onItemInAgenda(0, R.id.item_agenda_divider_text).check(matches(allOf(withText(R.string.overdue), isDisplayed())));
onItemInAgenda(1, R.id.item_head_title_view).check(matches(allOf(withText(endsWith("Note B")), isDisplayed())));
Expand All @@ -119,14 +119,14 @@ public void testAgendaRangeEvent() {
"<" + start.toString() + ">--<" + end.toString() + ">\n");

scenario = ActivityScenario.launch(MainActivity.class);
searchForText("ad.5");
searchForTextCloseKeyboard("ad.5");
onNotesInAgenda().check(matches(recyclerViewItemCount(10)));
}

@Test
public void testOneTimeTaskMarkedDone() {
scenario = defaultSetUp();
searchForText(".it.done ad.7");
searchForTextCloseKeyboard(".it.done ad.7");
/*
* 1 Overdue
* 1 Note B <- Mark as done
Expand All @@ -144,7 +144,7 @@ public void testOneTimeTaskMarkedDone() {
@Test
public void testRepeaterTaskMarkedDone() {
scenario = defaultSetUp();
searchForText(".it.done ad.7");
searchForTextCloseKeyboard(".it.done ad.7");
onItemInAgenda(2).perform(longClick());
onView(withId(R.id.toggle_state)).perform(click());
onNotesInAgenda().check(matches(recyclerViewItemCount(23)));
Expand All @@ -153,7 +153,7 @@ public void testRepeaterTaskMarkedDone() {
@Test
public void testRangeTaskMarkedDone() {
scenario = defaultSetUp();
searchForText(".it.done ad.7");
searchForTextCloseKeyboard(".it.done ad.7");
onItemInAgenda(3).perform(longClick());
onView(withId(R.id.toggle_state)).perform(click());
onNotesInAgenda().check(matches(recyclerViewItemCount(17)));
Expand All @@ -163,7 +163,7 @@ public void testRangeTaskMarkedDone() {
public void testMoveTaskWithRepeaterToTomorrow() {
DateTime tomorrow = DateTime.now().withTimeAtStartOfDay().plusDays(1);
scenario = defaultSetUp();
searchForText(".it.done ad.7");
searchForTextCloseKeyboard(".it.done ad.7");
onItemInAgenda(2).perform(longClick());
onView(withId(R.id.schedule)).perform(click());
onView(withId(R.id.date_picker_button)).perform(click());
Expand All @@ -181,7 +181,7 @@ public void testMoveTaskWithRepeaterToTomorrow() {
public void testPersistedSpinnerSelection() {
scenario = defaultSetUp();

searchForText(".it.done ad.7");
searchForTextCloseKeyboard(".it.done ad.7");
onNotesInAgenda().check(matches(recyclerViewItemCount(25)));

scenario.onActivity(activity ->
Expand All @@ -199,7 +199,7 @@ public void testDeselectRemovedNoteInAgenda() {

scenario = ActivityScenario.launch(MainActivity.class);

searchForText("i.todo ad.3");
searchForTextCloseKeyboard("i.todo ad.3");

onNotesInAgenda().check(matches(recyclerViewItemCount(12)));

Expand All @@ -226,7 +226,7 @@ public void testPreselectedStateOfSelectedNote() {
testUtils.setupBook("notebook", "* TODO Note A\nSCHEDULED: <2018-01-01 +1d>");
scenario = ActivityScenario.launch(MainActivity.class);

searchForText("ad.3");
searchForTextCloseKeyboard("ad.3");

onItemInAgenda(1).perform(longClick());
onView(withId(R.id.state)).perform(click());
Expand All @@ -238,7 +238,7 @@ public void testPreselectedStateOfSelectedNote() {
public void testSwipeDivider() {
testUtils.setupBook("notebook", "* TODO Note A\nSCHEDULED: <2018-01-01 +1d>");
scenario = ActivityScenario.launch(MainActivity.class);
searchForText("ad.3");
searchForTextCloseKeyboard("ad.3");
onItemInAgenda(0).perform(swipeLeft());
onItemInAgenda(2).perform(swipeLeft());
}
Expand All @@ -249,7 +249,7 @@ public void testOpenCorrectNote() {
testUtils.setupBook("notebook", "* TODO Note A\nSCHEDULED: <2018-01-01 +1d>");
scenario = ActivityScenario.launch(MainActivity.class);

searchForText("ad.3");
searchForTextCloseKeyboard("ad.3");

onItemInAgenda(1).perform(click());

Expand All @@ -264,7 +264,7 @@ public void testChangeStateWithReverseNoteClick() {
AppPreferences.isReverseNoteClickAction(context, false);
scenario = ActivityScenario.launch(MainActivity.class);

searchForText(".it.done ad.7");
searchForTextCloseKeyboard(".it.done ad.7");
onItemInAgenda(1).perform(longClick());
onView(withId(R.id.state)).perform(click());
onView(withText("NEXT")).perform(click());
Expand All @@ -274,7 +274,7 @@ public void testChangeStateWithReverseNoteClick() {
public void testInactiveScheduled() {
testUtils.setupBook("notebook-1", "* Note A\nSCHEDULED: [2020-07-01]\nDEADLINE: <2020-07-01>");
scenario = ActivityScenario.launch(MainActivity.class);
searchForText("ad.1");
searchForTextCloseKeyboard("ad.1");
// Overdue, note (deadline), today
onNotesInAgenda().check(matches(recyclerViewItemCount(3)));
}
Expand All @@ -283,7 +283,7 @@ public void testInactiveScheduled() {
public void testInactiveDeadline() {
testUtils.setupBook("notebook-1", "* Note A\nDEADLINE: [2020-07-01]\nSCHEDULED: <2020-07-01>");
scenario = ActivityScenario.launch(MainActivity.class);
searchForText("ad.1");
searchForTextCloseKeyboard("ad.1");
// Overdue, note (scheduled), today
onNotesInAgenda().check(matches(recyclerViewItemCount(3)));
}
Expand All @@ -292,7 +292,7 @@ public void testInactiveDeadline() {
public void testInactiveScheduledAndDeadline() {
testUtils.setupBook("notebook-1", "* Note A\nSCHEDULED: [2020-07-01]\nDEADLINE: [2020-07-01]");
scenario = ActivityScenario.launch(MainActivity.class);
searchForText("ad.1");
searchForTextCloseKeyboard("ad.1");
// Today
onNotesInAgenda().check(matches(recyclerViewItemCount(1)));
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@
import static com.orgzly.android.espresso.util.EspressoUtils.onNotesInSearch;
import static com.orgzly.android.espresso.util.EspressoUtils.recyclerViewItemCount;
import static com.orgzly.android.espresso.util.EspressoUtils.replaceTextCloseKeyboard;
import static com.orgzly.android.espresso.util.EspressoUtils.searchForText;
import static com.orgzly.android.espresso.util.EspressoUtils.searchForTextCloseKeyboard;
import static org.hamcrest.CoreMatchers.instanceOf;
import static org.hamcrest.Matchers.allOf;

Expand Down Expand Up @@ -68,7 +68,7 @@ public void tearDown() throws Exception {
public void testCondition() {
enableCreatedAt();

searchForText("cr.le.today");
searchForTextCloseKeyboard("cr.le.today");
onNotesInSearch().check(matches(recyclerViewItemCount(2)));

// TODO: Search before/after 2018-01-03 expecting 1 note
Expand All @@ -78,18 +78,18 @@ public void testCondition() {
public void testSortOrder() {
enableCreatedAt();

searchForText("o.cr");
searchForTextCloseKeyboard("o.cr");
onNoteInSearch(0, R.id.item_head_title_view)
.check(matches(allOf(withText("Note [a-2]"), isDisplayed())));

searchForText(".o.cr");
searchForTextCloseKeyboard(".o.cr");
onNoteInSearch(0, R.id.item_head_title_view)
.check(matches(allOf(withText("Note [a-1]"), isDisplayed())));
}

@Test
public void testChangeCreatedAtPropertyResultsShouldBeReordered() {
searchForText("o.cr");
searchForTextCloseKeyboard("o.cr");

onNoteInSearch(0, R.id.item_head_title_view).check(matches(withText("Note [a-1]")));
onNoteInSearch(1, R.id.item_head_title_view).check(matches(withText("Note [a-2]")));
Expand Down Expand Up @@ -119,11 +119,11 @@ public void testNewNote() {
onNoteInBook(3, R.id.item_head_title_view)
.check(matches(allOf(withText("new note created by test"), isDisplayed())));

searchForText("o.cr");
searchForTextCloseKeyboard("o.cr");
onNoteInSearch(0, R.id.item_head_title_view)
.check(matches(allOf(withText("Note [a-2]"), isDisplayed())));

searchForText(".o.cr");
searchForTextCloseKeyboard(".o.cr");
onNoteInSearch(0, R.id.item_head_title_view)
.check(matches(allOf(withText("new note created by test"), isDisplayed())));
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@
import static com.orgzly.android.espresso.util.EspressoUtils.onSavedSearch;
import static com.orgzly.android.espresso.util.EspressoUtils.replaceTextCloseKeyboard;
import static com.orgzly.android.espresso.util.EspressoUtils.scroll;
import static com.orgzly.android.espresso.util.EspressoUtils.searchForText;
import static com.orgzly.android.espresso.util.EspressoUtils.searchForTextCloseKeyboard;
import static com.orgzly.android.espresso.util.EspressoUtils.settingsSetDoneKeywords;
import static com.orgzly.android.espresso.util.EspressoUtils.settingsSetTodoKeywords;
import static org.hamcrest.Matchers.allOf;
Expand Down Expand Up @@ -465,7 +465,7 @@ public void testMainActivityFragments() {
fragmentTest(activity, true, withId(R.id.fragment_query_search_view_flipper));

// Agenda
searchForText("t.tag3 ad.3");
searchForTextCloseKeyboard("t.tag3 ad.3");
fragmentTest(activity, true, withId(R.id.fragment_query_agenda_view_flipper));
}
}
Expand Down Expand Up @@ -728,7 +728,7 @@ public void testActiveDrawerItemForSearchQuery() {
try (ActivityScenario<MainActivity> ignored = ActivityScenario.launch(MainActivity.class)) {
onBook(0).perform(click());

searchForText("note");
searchForTextCloseKeyboard("note");

onView(withId(R.id.drawer_layout)).perform(open());
onView(allOf(withText("booky-one"), isDescendantOfA(withId(R.id.drawer_navigation_view))))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ class NoteEventsTest : OrgzlyTest() {
testUtils.setupBook("book-a", "* Note $now")
scenario = ActivityScenario.launch(MainActivity::class.java)

searchForText("e.ge.today")
searchForTextCloseKeyboard("e.ge.today")
onNotesInSearch().check(matches(recyclerViewItemCount(1)))
}

Expand All @@ -77,7 +77,7 @@ class NoteEventsTest : OrgzlyTest() {
testUtils.setupBook("book-a", "* Note\n$now")
scenario = ActivityScenario.launch(MainActivity::class.java)

searchForText("e.ge.today")
searchForTextCloseKeyboard("e.ge.today")
onNotesInSearch().check(matches(recyclerViewItemCount(1)))
}

Expand All @@ -86,7 +86,7 @@ class NoteEventsTest : OrgzlyTest() {
testUtils.setupBook("book-a", "* Note\n$now $now")
scenario = ActivityScenario.launch(MainActivity::class.java)

searchForText("e.ge.today")
searchForTextCloseKeyboard("e.ge.today")
onNotesInSearch().check(matches(recyclerViewItemCount(1)))
}

Expand All @@ -95,7 +95,7 @@ class NoteEventsTest : OrgzlyTest() {
testUtils.setupBook("book-a", "* Note $now")
scenario = ActivityScenario.launch(MainActivity::class.java)

searchForText("ad.1")
searchForTextCloseKeyboard("ad.1")
onNotesInAgenda().check(matches(recyclerViewItemCount(2)))
}

Expand All @@ -104,7 +104,7 @@ class NoteEventsTest : OrgzlyTest() {
testUtils.setupBook("book-a", "* Note $now $tomorrow")
scenario = ActivityScenario.launch(MainActivity::class.java)

searchForText("ad.2")
searchForTextCloseKeyboard("ad.2")
onNotesInAgenda().check(matches(recyclerViewItemCount(4)))
}

Expand All @@ -113,7 +113,7 @@ class NoteEventsTest : OrgzlyTest() {
testUtils.setupBook("book-a", "* Note\n$now")
scenario = ActivityScenario.launch(MainActivity::class.java)

searchForText("ad.1")
searchForTextCloseKeyboard("ad.1")
onNotesInAgenda().check(matches(recyclerViewItemCount(2)))
}

Expand All @@ -122,7 +122,7 @@ class NoteEventsTest : OrgzlyTest() {
testUtils.setupBook("book-a", "* Note\n$now $tomorrow")
scenario = ActivityScenario.launch(MainActivity::class.java)

searchForText("ad.2")
searchForTextCloseKeyboard("ad.2")
onNotesInAgenda().check(matches(recyclerViewItemCount(4)))
}

Expand All @@ -148,7 +148,7 @@ class NoteEventsTest : OrgzlyTest() {

scenario = ActivityScenario.launch(MainActivity::class.java)

searchForText("ad.5")
searchForTextCloseKeyboard("ad.5")

onNotesInAgenda().check(matches(recyclerViewItemCount(10)))

Expand Down Expand Up @@ -192,7 +192,7 @@ class NoteEventsTest : OrgzlyTest() {

scenario = ActivityScenario.launch(MainActivity::class.java)

searchForText("b.book-a")
searchForTextCloseKeyboard("b.book-a")

onNotesInSearch().check(matches(recyclerViewItemCount(1)))

Expand All @@ -208,7 +208,7 @@ class NoteEventsTest : OrgzlyTest() {
"* Today $today\n* In few days $inFewDays\n* Today & In few days $today $inFewDays")
scenario = ActivityScenario.launch(MainActivity::class.java)

searchForText("e.gt.1d")
searchForTextCloseKeyboard("e.gt.1d")
onNotesInSearch().check(matches(recyclerViewItemCount(2)))
}

Expand All @@ -217,7 +217,7 @@ class NoteEventsTest : OrgzlyTest() {
testUtils.setupBook("book-a", "* Few days ago\n$fewDaysAgo")
scenario = ActivityScenario.launch(MainActivity::class.java)

searchForText("ad.2")
searchForTextCloseKeyboard("ad.2")
onNotesInAgenda().check(matches(recyclerViewItemCount(2)))
}

Expand All @@ -226,7 +226,7 @@ class NoteEventsTest : OrgzlyTest() {
testUtils.setupBook("book-a", "* $yesterday $fewDaysAgo\nSCHEDULED: $tomorrow")
scenario = ActivityScenario.launch(MainActivity::class.java)

searchForText("e.lt.now ad.3")
searchForTextCloseKeyboard("e.lt.now ad.3")
onNotesInAgenda().check(matches(recyclerViewItemCount(4)))
}

Expand All @@ -240,7 +240,7 @@ class NoteEventsTest : OrgzlyTest() {
""".trimIndent())
scenario = ActivityScenario.launch(MainActivity::class.java)

searchForText("e.today")
searchForTextCloseKeyboard("e.today")
onNotesInSearch().check(matches(recyclerViewItemCount(1)))
onNoteInSearch(0, R.id.item_head_title_view).check(matches(withText(startsWith("Note A-01"))))
}
Expand All @@ -257,7 +257,7 @@ class NoteEventsTest : OrgzlyTest() {
""".trimIndent())
scenario = ActivityScenario.launch(MainActivity::class.java)

searchForText("e.lt.now o.e")
searchForTextCloseKeyboard("e.lt.now o.e")
onNotesInSearch().check(matches(recyclerViewItemCount(2)))
onNoteInSearch(0, R.id.item_head_title_view).check(matches(withText(startsWith("Note A-01"))))
onNoteInSearch(1, R.id.item_head_title_view).check(matches(withText(startsWith("Note A-02"))))
Expand All @@ -275,7 +275,7 @@ class NoteEventsTest : OrgzlyTest() {
""".trimIndent())
scenario = ActivityScenario.launch(MainActivity::class.java)

searchForText("e.lt.now .o.e")
searchForTextCloseKeyboard("e.lt.now .o.e")
onNotesInSearch().check(matches(recyclerViewItemCount(2)))
onNoteInSearch(0, R.id.item_head_title_view).check(matches(withText(startsWith("Note A-01"))))
onNoteInSearch(1, R.id.item_head_title_view).check(matches(withText(startsWith("Note A-02"))))
Expand Down Expand Up @@ -316,7 +316,7 @@ class NoteEventsTest : OrgzlyTest() {
""".trimIndent())
scenario = ActivityScenario.launch(MainActivity::class.java)

searchForText(".it.done ad.7 o.e")
searchForTextCloseKeyboard(".it.done ad.7 o.e")

onNotesInAgenda().check(matches(recyclerViewItemCount(8)))
onItemInAgenda(2, R.id.item_head_title_view).check(matches(withText(startsWith("Note A-01"))))
Expand Down
Loading

0 comments on commit a927baa

Please sign in to comment.