Skip to content

Commit

Permalink
fix back press issues
Browse files Browse the repository at this point in the history
  • Loading branch information
Jojo Narte authored and Jojo Narte committed May 16, 2018
1 parent 3a06166 commit c3e60dc
Show file tree
Hide file tree
Showing 4 changed files with 53 additions and 10 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
package bbct.android.common.navigation.test;

import android.support.test.espresso.Espresso;
import android.support.test.espresso.NoMatchingViewException;
import android.support.test.rule.ActivityTestRule;
import android.support.test.runner.AndroidJUnit4;

Expand Down Expand Up @@ -51,19 +52,20 @@ public void setUp() throws Exception {
.getSupportFragmentManager().beginTransaction();
}

@Test
public void testNavigateToAboutFragment() {
openActionBarOverflowOrOptionsMenu(getInstrumentation().getTargetContext());

String aboutTitle = getInstrumentation().getTargetContext().getString(R.string.about_title);
Espresso.pressBack();

String expectedTitle = getInstrumentation().getTargetContext().getString(R.string.bbct_title, aboutTitle);
onView(withText(expectedTitle)).check(matches(isDisplayed()));
private void skipSurvey() {
try {
onView(withText(R.string.survey1)).check(matches(isDisplayed()));
onView(withText(R.string.later))
.check(matches(isDisplayed()))
.perform(click());
} catch (NoMatchingViewException e) {
//view not displayed logic
}
}

@Test
public void testNavigateBack() {
skipSurvey();
String initialTitle = (String) activityActivityTestRule.getActivity().getTitle();
openActionBarOverflowOrOptionsMenu(getInstrumentation().getTargetContext());

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
package bbct.android.common.navigation.test;

import android.support.test.espresso.Espresso;
import android.support.test.espresso.NoMatchingViewException;
import android.support.test.rule.ActivityTestRule;
import android.support.test.runner.AndroidJUnit4;

Expand Down Expand Up @@ -50,8 +51,20 @@ public void setUp() throws Exception {
.getSupportFragmentManager().beginTransaction();
}

private void skipSurvey() {
try {
onView(withText(R.string.survey1)).check(matches(isDisplayed()));
onView(withText(R.string.later))
.check(matches(isDisplayed()))
.perform(click());
} catch (NoMatchingViewException e) {
//view not displayed logic
}
}

@Test
public void testDefaultNavigateUpWithNoData() {
skipSurvey();
String cardDetailsTitle = getInstrumentation().getTargetContext().getString(R.string.card_details_title);
String expectedTitle = getInstrumentation().getTargetContext().getString(R.string.bbct_title, cardDetailsTitle);
Espresso.closeSoftKeyboard();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
package bbct.android.common.navigation.test;

import android.support.test.espresso.Espresso;
import android.support.test.espresso.NoMatchingViewException;
import android.support.test.rule.ActivityTestRule;
import android.support.test.runner.AndroidJUnit4;

Expand All @@ -33,6 +34,7 @@

import static android.support.test.InstrumentationRegistry.getInstrumentation;
import static android.support.test.espresso.Espresso.onView;
import static android.support.test.espresso.action.ViewActions.click;
import static android.support.test.espresso.assertion.ViewAssertions.matches;
import static android.support.test.espresso.matcher.ViewMatchers.isDisplayed;
import static android.support.test.espresso.matcher.ViewMatchers.withText;
Expand All @@ -49,8 +51,20 @@ public void setUp() throws Exception {
.getSupportFragmentManager().beginTransaction();
}

private void skipSurvey() {
try {
onView(withText(R.string.survey1)).check(matches(isDisplayed()));
onView(withText(R.string.later))
.check(matches(isDisplayed()))
.perform(click());
} catch (NoMatchingViewException e) {
//view not displayed logic
}
}

@Test
public void testBackPress() {
skipSurvey();
String expectedTitle = getInstrumentation().getTargetContext().getString(R.string.app_name);
Espresso.closeSoftKeyboard();
Espresso.pressBack();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
package bbct.android.common.navigation.test;

import android.support.test.espresso.Espresso;
import android.support.test.espresso.NoMatchingViewException;
import android.support.test.rule.ActivityTestRule;
import android.support.test.runner.AndroidJUnit4;

Expand All @@ -33,6 +34,7 @@
import static android.support.test.InstrumentationRegistry.getInstrumentation;
import static android.support.test.espresso.Espresso.onView;
import static android.support.test.espresso.action.ViewActions.click;
import static android.support.test.espresso.assertion.ViewAssertions.matches;
import static android.support.test.espresso.matcher.ViewMatchers.isDisplayed;
import static android.support.test.espresso.matcher.ViewMatchers.withContentDescription;
import static android.support.test.espresso.matcher.ViewMatchers.withText;
Expand All @@ -49,10 +51,22 @@ public void setUp() throws Exception {
.getSupportFragmentManager().beginTransaction();
}

private void skipSurvey() {
try {
onView(withText(R.string.survey1)).check(matches(isDisplayed()));
onView(withText(R.string.later))
.check(matches(isDisplayed()))
.perform(click());
} catch (NoMatchingViewException e) {
//view not displayed logic
}
}

@Test
public void testNavigateUp() {

skipSurvey();
String expectedTitle = getInstrumentation().getTargetContext().getString(R.string.app_name);
Espresso.closeSoftKeyboard();
Espresso.pressBack();
onView(allOf(withContentDescription(R.string.filter_cards_title), isDisplayed())).perform(click());
Espresso.pressBack();
Expand Down

0 comments on commit c3e60dc

Please sign in to comment.