Commit 05fbb87c authored by Torsten Grote's avatar Torsten Grote

Add a NavDrawerActivityTest

parent daf5db47
......@@ -53,6 +53,7 @@ dependencies {
def espressoVersion = '3.0.2'
androidTestImplementation "com.android.support.test.espresso:espresso-core:$espressoVersion"
androidTestImplementation "com.android.support.test.espresso:espresso-contrib:$espressoVersion"
androidTestImplementation "com.android.support.test.espresso:espresso-intents:$espressoVersion"
androidTestImplementation "tools.fastlane:screengrab:1.1.0"
androidTestAnnotationProcessor "com.google.dagger:dagger-compiler:2.0.2"
androidTestCompileOnly 'javax.annotation:jsr250-api:1.0'
......
......@@ -3,7 +3,8 @@ package org.briarproject.briar.android;
import org.briarproject.bramble.BrambleAndroidModule;
import org.briarproject.bramble.BrambleCoreModule;
import org.briarproject.briar.BriarCoreModule;
import org.briarproject.briar.android.settings.DarkThemeTest;
import org.briarproject.briar.android.navdrawer.NavDrawerActivityTest;
import org.briarproject.briar.android.settings.SettingsActivityTest;
import javax.inject.Singleton;
......@@ -18,6 +19,7 @@ import dagger.Component;
})
public interface BriarTestComponent extends AndroidComponent {
void inject(DarkThemeTest test);
void inject(NavDrawerActivityTest test);
void inject(SettingsActivityTest test);
}
package org.briarproject.briar.android.navdrawer;
import android.support.test.espresso.contrib.DrawerActions;
import android.support.test.espresso.intent.rule.IntentsTestRule;
import android.view.Gravity;
import org.briarproject.briar.R;
import org.briarproject.briar.android.BriarTestComponent;
import org.briarproject.briar.android.settings.SettingsActivity;
import org.briarproject.briar.android.test.ScreenshotTest;
import org.junit.Before;
import org.junit.Rule;
import org.junit.Test;
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.contrib.DrawerMatchers.isClosed;
import static android.support.test.espresso.intent.Intents.intended;
import static android.support.test.espresso.intent.matcher.IntentMatchers.hasComponent;
import static android.support.test.espresso.matcher.ViewMatchers.isDisplayed;
import static android.support.test.espresso.matcher.ViewMatchers.isRoot;
import static android.support.test.espresso.matcher.ViewMatchers.withId;
import static android.support.test.espresso.matcher.ViewMatchers.withText;
import static org.briarproject.briar.android.test.ViewActions.waitForActivityToResume;
public class NavDrawerActivityTest extends ScreenshotTest {
@Rule
public IntentsTestRule<NavDrawerActivity> activityRule =
new IntentsTestRule<>(NavDrawerActivity.class);
@Override
protected void inject(BriarTestComponent component) {
component.inject(this);
}
@Before
public void waitForSignIn() {
onView(isRoot())
.perform(waitForActivityToResume(activityRule.getActivity()));
}
@Test
public void openSettings() {
onView(withId(R.id.drawer_layout))
.check(matches(isClosed(Gravity.LEFT)))
.perform(DrawerActions.open());
onView(withText(R.string.settings_button))
.check(matches(isDisplayed()))
.perform(click());
intended(hasComponent(SettingsActivity.class.getName()));
}
}
......@@ -28,7 +28,7 @@ import static android.support.test.espresso.matcher.ViewMatchers.withText;
import static org.briarproject.briar.android.test.ViewActions.waitForActivityToResume;
@RunWith(AndroidJUnit4.class)
public class DarkThemeTest extends ScreenshotTest {
public class SettingsActivityTest extends ScreenshotTest {
@Rule
public ActivityTestRule<SettingsActivity> activityRule =
......
......@@ -2,14 +2,19 @@ package org.briarproject.briar.android.test;
import android.support.test.InstrumentationRegistry;
import android.support.test.espresso.NoMatchingViewException;
import android.support.test.espresso.contrib.DrawerActions;
import android.util.Log;
import android.view.Gravity;
import org.briarproject.bramble.api.lifecycle.LifecycleManager;
import org.briarproject.briar.R;
import org.briarproject.briar.android.BriarTestApplication;
import org.briarproject.briar.android.BriarTestComponent;
import org.junit.Before;
import org.junit.ClassRule;
import javax.inject.Inject;
import tools.fastlane.screengrab.Screengrab;
import tools.fastlane.screengrab.UiAutomatorScreenshotStrategy;
import tools.fastlane.screengrab.locale.LocaleTestRule;
......@@ -18,9 +23,11 @@ import static android.support.test.espresso.Espresso.onView;
import static android.support.test.espresso.action.ViewActions.click;
import static android.support.test.espresso.action.ViewActions.typeText;
import static android.support.test.espresso.assertion.ViewAssertions.matches;
import static android.support.test.espresso.contrib.DrawerMatchers.isClosed;
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.briarproject.bramble.api.lifecycle.LifecycleManager.LifecycleState.RUNNING;
import static tools.fastlane.screengrab.Screengrab.setDefaultScreenshotStrategy;
public abstract class ScreenshotTest {
......@@ -39,6 +46,8 @@ public abstract class ScreenshotTest {
private final BriarTestApplication app =
(BriarTestApplication) InstrumentationRegistry.getTargetContext()
.getApplicationContext();
@Inject
LifecycleManager lifecycleManager;
protected abstract void inject(BriarTestComponent component);
......@@ -51,6 +60,7 @@ public abstract class ScreenshotTest {
@Before
public void signIn() throws Exception {
inject((BriarTestComponent) app.getApplicationComponent());
if (lifecycleManager.getLifecycleState() == RUNNING) return;
try {
onView(withId(R.id.edit_password))
......@@ -93,6 +103,15 @@ public abstract class ScreenshotTest {
.check(matches(isDisplayed()));
}
protected void signOut() {
onView(withId(R.id.drawer_layout))
.check(matches(isClosed(Gravity.LEFT)))
.perform(DrawerActions.open());
onView(withText(R.string.sign_out_button))
.check(matches(isDisplayed()))
.perform(click());
}
protected void screenshot(String name) {
try {
Screengrab.screenshot(name);
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment