Skip to content

Commit e4efc5b

Browse files
improve tests resiliece
1 parent 710f64a commit e4efc5b

File tree

3 files changed

+20
-8
lines changed

3 files changed

+20
-8
lines changed

app/src/androidTest/java/com/nononsenseapps/notepad/espresso_tests/TestAddTaskListsScrollNavigationDrawer.java

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,9 @@ public void testAddTaskListsScrollNavigationDrawer() {
4848
.check(matches(isDisplayed()));
4949

5050
// onView() can click on the item, but can't scroll to it
51-
onView(allOf(withText("ut "), withId(android.R.id.text1)))
51+
onView(allOf(
52+
withText(equalToIgnoringCase("ut ")),
53+
withId(android.R.id.text1)))
5254
.perform(click());
5355

5456
EspressoHelper.openDrawer();

app/src/androidTest/java/com/nononsenseapps/notepad/espresso_tests/TestCompletedTasksAreCleared.java

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,8 @@
1414
import static org.hamcrest.Matchers.anything;
1515

1616
import androidx.test.espresso.DataInteraction;
17+
import androidx.test.espresso.Espresso;
18+
import androidx.test.espresso.PerformException;
1719
import androidx.test.filters.LargeTest;
1820

1921
import com.nononsenseapps.notepad.R;
@@ -64,7 +66,11 @@ public void testCompletedTasksAreCleared() {
6466
*/
6567
private void clickCheckBoxAt(int position) {
6668
// the keyboard may cover the notes, which makes the next lines crash!
67-
onView(isRoot()).perform(closeSoftKeyboard());
69+
try {
70+
Espresso.closeSoftKeyboard();
71+
} catch (PerformException ignored) {
72+
// keyboard was already closed
73+
}
6874
DataInteraction di = onData(anything())
6975
.inAdapterView(allOf(withId(android.R.id.list), hasChildCount(5)))
7076
.atPosition(position)

app/src/main/java/com/nononsenseapps/notepad/activities/main/ActivityMain.java

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -454,12 +454,16 @@ void newOnBackPressed() {
454454
return;
455455
}
456456

457-
// If search view is expanded, collapse it instead of closing the activity
458-
SearchView mSearchVi = (SearchView) mSearchViewMenuItem.getActionView();
459-
if (mSearchVi != null && !mSearchVi.isIconified()) {
460-
mSearchViewMenuItem.collapseActionView();
461-
invalidateOptionsMenu();
462-
return;
457+
if (mSearchViewMenuItem != null) {
458+
// If search view is expanded, collapse it instead of closing the activity
459+
SearchView mSearchVi = (SearchView) mSearchViewMenuItem.getActionView();
460+
if (mSearchVi != null && !mSearchVi.isIconified()) {
461+
mSearchViewMenuItem.collapseActionView();
462+
invalidateOptionsMenu();
463+
return;
464+
}
465+
} else {
466+
// cannot fetch the searchview. Therefore, don't try to close it
463467
}
464468

465469
// Reset intent so we get proper fragment handling when the stack pops

0 commit comments

Comments
 (0)