From 33f811f6794e481d5cbdbdc359b70e8ab9309b05 Mon Sep 17 00:00:00 2001 From: cyBerta Date: Wed, 2 Jan 2019 14:12:26 +0100 Subject: fix instrumentation tests, update espresso test framework --- .../test/StartActivityDrawerTest.java | 84 ++++++++++++++++++---- 1 file changed, 69 insertions(+), 15 deletions(-) (limited to 'app/src/androidTest') diff --git a/app/src/androidTest/java/se/leap/bitmaskclient/test/StartActivityDrawerTest.java b/app/src/androidTest/java/se/leap/bitmaskclient/test/StartActivityDrawerTest.java index d7580c88..2d3fe6bb 100644 --- a/app/src/androidTest/java/se/leap/bitmaskclient/test/StartActivityDrawerTest.java +++ b/app/src/androidTest/java/se/leap/bitmaskclient/test/StartActivityDrawerTest.java @@ -15,8 +15,10 @@ import org.junit.runner.RunWith; import java.io.IOException; +import se.leap.bitmaskclient.BuildConfig; import se.leap.bitmaskclient.MainActivity; import se.leap.bitmaskclient.Provider; +import se.leap.bitmaskclient.R; import se.leap.bitmaskclient.testutils.TestSetupHelper; import static android.support.test.InstrumentationRegistry.getInstrumentation; @@ -26,17 +28,21 @@ import static android.support.test.espresso.action.ViewActions.click; import static android.support.test.espresso.assertion.ViewAssertions.matches; import static android.support.test.espresso.contrib.DrawerMatchers.isClosed; import static android.support.test.espresso.contrib.DrawerMatchers.isOpen; +import static android.support.test.espresso.matcher.RootMatchers.isDialog; import static android.support.test.espresso.matcher.ViewMatchers.isDisplayed; import static android.support.test.espresso.matcher.ViewMatchers.withId; +import static android.support.test.espresso.matcher.ViewMatchers.withText; import static org.hamcrest.Matchers.anything; +import static se.leap.bitmaskclient.Constants.FIRST_TIME_USER_DATE; +import static se.leap.bitmaskclient.Constants.LAST_DONATION_REMINDER_DATE; import static se.leap.bitmaskclient.Constants.SHARED_PREFERENCES; import static se.leap.bitmaskclient.MainActivity.ACTION_SHOW_VPN_FRAGMENT; import static se.leap.bitmaskclient.R.id.aboutLayout; import static se.leap.bitmaskclient.R.id.accountList; -import static se.leap.bitmaskclient.R.id.provider_list_layout; import static se.leap.bitmaskclient.R.id.drawer_layout; import static se.leap.bitmaskclient.R.id.eipServiceFragment; import static se.leap.bitmaskclient.R.id.log_layout; +import static se.leap.bitmaskclient.R.id.provider_list_layout; import static se.leap.bitmaskclient.R.id.settingsList; /** @@ -65,7 +71,8 @@ public class StartActivityDrawerTest { preferencesEditor = preferences.edit(); preferencesEditor.putString(Provider.KEY, TestSetupHelper.getInputAsString(InstrumentationRegistry.getContext().getAssets().open("riseup.net.json"))) .putString(Provider.CA_CERT, TestSetupHelper.getInputAsString(InstrumentationRegistry.getContext().getAssets().open("riseup.net.pem"))) - .commit(); + .putString(LAST_DONATION_REMINDER_DATE, null) + .putString(FIRST_TIME_USER_DATE, null).commit(); } @@ -89,39 +96,86 @@ public class StartActivityDrawerTest { } @Test - public void testClickProviderName_closeDrawerAndShowEipFragment() { - preferencesEditor.putBoolean("navigation_drawer_learned", false).commit(); + public void testClickProviderName_closeDrawerAndShowEipFragment() throws InterruptedException { + preferencesEditor.putBoolean("navigation_drawer_learned", true).commit(); mActivityRule.launchActivity(intent); - + onView(withId(drawer_layout)).check(matches(isClosed())); + onView(withId(drawer_layout)).perform(DrawerActions.open()); + onView(withId(drawer_layout)).check(matches(isOpen())); onData(anything()).inAdapterView(withId(accountList)).atPosition(0).perform(click()); onView(withId(drawer_layout)).check(matches(isClosed())); onView(withId(eipServiceFragment)).check(matches(isDisplayed())); } @Test - public void testClickSwitchProvider_closeDrawerAndShowProviderListView() { - preferencesEditor.putBoolean("navigation_drawer_learned", false).commit(); + public void testSaveBattery_closeDrawerAndShowSaveBatteryDialog() throws InterruptedException { + preferencesEditor.putBoolean("navigation_drawer_learned", true).commit(); mActivityRule.launchActivity(intent); - + onView(withId(drawer_layout)).check(matches(isClosed())); + onView(withId(drawer_layout)).perform(DrawerActions.open()); + onView(withId(drawer_layout)).check(matches(isOpen())); onData(anything()).inAdapterView(withId(settingsList)).atPosition(0).perform(click()); + onView(withText(R.string.save_battery_message)) + .inRoot(isDialog()) + .check(matches(isDisplayed())); + } + + @Test + public void testAlwaysOnVPN_closeDrawerAndShowDialog() throws InterruptedException { + preferencesEditor.putBoolean("navigation_drawer_learned", true).commit(); + mActivityRule.launchActivity(intent); + onView(withId(drawer_layout)).check(matches(isClosed())); + onView(withId(drawer_layout)).perform(DrawerActions.open()); + onView(withId(drawer_layout)).check(matches(isOpen())); + onData(anything()).inAdapterView(withId(settingsList)).atPosition(1).perform(click()); + onView(withText(R.string.always_on_vpn_user_message)) + .inRoot(isDialog()) + .check(matches(isDisplayed())); + } + + @Test + public void testClickSwitchProvider_closeDrawerAndShowProviderListView() throws InterruptedException { + if (BuildConfig.FLAVOR_branding.equals("custom")) { + return; + } + preferencesEditor.putBoolean("navigation_drawer_learned", true).commit(); + mActivityRule.launchActivity(intent); + onView(withId(drawer_layout)).check(matches(isClosed())); + onView(withId(drawer_layout)).perform(DrawerActions.open()); + onView(withId(drawer_layout)).check(matches(isOpen())); + + onData(anything()).inAdapterView(withId(settingsList)).atPosition(3).perform(click()); onView(withId(provider_list_layout)).check(matches(isDisplayed())); } @Test - public void testClickLog_closeDrawerAndShowLogFragment() { - preferencesEditor.putBoolean("navigation_drawer_learned", false).commit(); + public void testClickLog_closeDrawerAndShowLogFragment() throws InterruptedException { + preferencesEditor.putBoolean("navigation_drawer_learned", true).commit(); mActivityRule.launchActivity(intent); + onView(withId(drawer_layout)).check(matches(isClosed())); + onView(withId(drawer_layout)).perform(DrawerActions.open()); + onView(withId(drawer_layout)).check(matches(isOpen())); - onData(anything()).inAdapterView(withId(settingsList)).atPosition(1).perform(click()); + onData(anything()).inAdapterView(withId(settingsList)).atPosition(getPositionBasedOnFlavor(2, 3)).perform(click()); onView(withId(log_layout)).check(matches(isDisplayed())); } @Test - public void testClickAbout_closeDrawerAndShowAboutFragment() { - preferencesEditor.putBoolean("navigation_drawer_learned", false).commit(); + public void testClickAbout_closeDrawerAndShowAboutFragment() throws InterruptedException { + preferencesEditor.putBoolean("navigation_drawer_learned", true).commit(); mActivityRule.launchActivity(intent); - - onData(anything()).inAdapterView(withId(settingsList)).atPosition(2).perform(click()); + onView(withId(drawer_layout)).check(matches(isClosed())); + onView(withId(drawer_layout)).perform(DrawerActions.open()); + onView(withId(drawer_layout)).check(matches(isOpen())); + onData(anything()).inAdapterView(withId(settingsList)).atPosition(getPositionBasedOnFlavor(4,5)).perform(click()); onView(withId(aboutLayout)).check(matches(isDisplayed())); } + + private int getPositionBasedOnFlavor(int custom, int defaultNumber) { + if (BuildConfig.FLAVOR_branding.equals("custom")) { + return custom; + } else { + return defaultNumber; + } + } } -- cgit v1.2.3