mirror of
https://github.com/kiwix/kiwix-android.git
synced 2025-09-19 12:26:13 -04:00
fix test code
This commit is contained in:
parent
e222a50117
commit
9e40d7c763
@ -19,18 +19,34 @@
|
||||
package org.kiwix.kiwixmobile.language;
|
||||
|
||||
import android.Manifest;
|
||||
import android.support.test.espresso.ViewInteraction;
|
||||
import android.support.test.espresso.intent.Intents;
|
||||
import android.support.test.rule.GrantPermissionRule;
|
||||
import android.view.View;
|
||||
import android.view.ViewGroup;
|
||||
import android.view.ViewParent;
|
||||
import com.schibsted.spain.barista.interaction.BaristaSleepInteractions;
|
||||
import com.schibsted.spain.barista.rule.BaristaRule;
|
||||
import org.hamcrest.Description;
|
||||
import org.hamcrest.Matcher;
|
||||
import org.hamcrest.TypeSafeMatcher;
|
||||
import org.junit.Rule;
|
||||
import org.junit.Test;
|
||||
import org.kiwix.kiwixmobile.R;
|
||||
import org.kiwix.kiwixmobile.intro.IntroActivity;
|
||||
|
||||
import static android.support.test.InstrumentationRegistry.getInstrumentation;
|
||||
import static android.support.test.espresso.Espresso.onView;
|
||||
import static android.support.test.espresso.Espresso.openActionBarOverflowOrOptionsMenu;
|
||||
import static android.support.test.espresso.action.ViewActions.click;
|
||||
import static android.support.test.espresso.action.ViewActions.swipeLeft;
|
||||
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.withId;
|
||||
import static android.support.test.espresso.matcher.ViewMatchers.withText;
|
||||
import static org.hamcrest.Matchers.allOf;
|
||||
import static org.hamcrest.core.IsNull.notNullValue;
|
||||
import static org.kiwix.kiwixmobile.testutils.TestUtils.TEST_PAUSE_MS;
|
||||
|
||||
public class LanguageActivityTest {
|
||||
@ -50,6 +66,24 @@ public class LanguageActivityTest {
|
||||
onView(withId(R.id.get_started)).perform(click());
|
||||
BaristaSleepInteractions.sleep(TEST_PAUSE_MS);
|
||||
|
||||
openActionBarOverflowOrOptionsMenu(getInstrumentation().getTargetContext());
|
||||
onView(withText("Get Content")).perform(click());
|
||||
BaristaSleepInteractions.sleep(TEST_PAUSE_MS);
|
||||
|
||||
ViewInteraction viewPager = onView(
|
||||
allOf(withId(R.id.container),
|
||||
childAtPosition(
|
||||
allOf(withId(R.id.zim_manager_main_activity),
|
||||
childAtPosition(
|
||||
withId(android.R.id.content),
|
||||
0)),
|
||||
1),
|
||||
isDisplayed()));
|
||||
viewPager.perform(swipeLeft());
|
||||
|
||||
onView(withContentDescription("Choose a language")).check(matches(notNullValue()));
|
||||
onView(withContentDescription("Choose a language")).perform(click());
|
||||
|
||||
|
||||
// TODO: make sure the it is only possible to open the activity after the network call is finished and book list is updated
|
||||
// TODO: test that default language is based on device locale
|
||||
@ -58,4 +92,23 @@ public class LanguageActivityTest {
|
||||
// TODO: verify all the correct books are displayed and are displayed correctly
|
||||
// TODO: test selecting no language is allowed
|
||||
}
|
||||
|
||||
private static Matcher<View> childAtPosition(
|
||||
final Matcher<View> parentMatcher, final int position) {
|
||||
|
||||
return new TypeSafeMatcher<View>() {
|
||||
@Override
|
||||
public void describeTo(Description description) {
|
||||
description.appendText("Child at position " + position + " in parent ");
|
||||
parentMatcher.describeTo(description);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean matchesSafely(View view) {
|
||||
ViewParent parent = view.getParent();
|
||||
return parent instanceof ViewGroup && parentMatcher.matches(parent)
|
||||
&& view.equals(((ViewGroup) parent).getChildAt(position));
|
||||
}
|
||||
};
|
||||
}
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user