This repository has been archived by the owner on May 28, 2020. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 200
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
7 changed files
with
271 additions
and
46 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
26 changes: 0 additions & 26 deletions
26
app/src/androidTest/java/io/github/marktony/espresso/ExampleInstrumentedTest.java
This file was deleted.
Oops, something went wrong.
33 changes: 33 additions & 0 deletions
33
app/src/androidTest/java/io/github/marktony/espresso/onboarding/OnboardingScreenTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
package io.github.marktony.espresso.onboarding; | ||
|
||
import android.support.test.filters.SmallTest; | ||
import android.support.test.rule.ActivityTestRule; | ||
import android.support.test.runner.AndroidJUnit4; | ||
|
||
import org.junit.Rule; | ||
import org.junit.runner.RunWith; | ||
|
||
import io.github.marktony.espresso.ui.onboarding.OnboardingActivity; | ||
|
||
/** | ||
* Created by lizhaotailang on 2017/5/13. | ||
* Tests for the {@link android.support.v4.view.ViewPager} and | ||
* other layout components in {@link OnboardingActivity}. | ||
*/ | ||
|
||
@RunWith(AndroidJUnit4.class) | ||
@SmallTest | ||
public class OnboardingScreenTest { | ||
|
||
/** | ||
* {@link ActivityTestRule} is a JUnit {@link Rule @Rule} to launch your activity under test. | ||
* | ||
* <p> | ||
* Rules are interceptors which are executed for each test method and are important building | ||
* blocks of Junit tests. | ||
*/ | ||
@Rule | ||
ActivityTestRule<OnboardingActivity> mOnboardingActivityTestRule | ||
= new ActivityTestRule<>(OnboardingActivity.class); | ||
|
||
} |
167 changes: 167 additions & 0 deletions
167
app/src/androidTest/java/io/github/marktony/espresso/packages/AppNavigationTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,167 @@ | ||
package io.github.marktony.espresso.packages; | ||
|
||
import android.graphics.drawable.ColorDrawable; | ||
import android.support.test.filters.LargeTest; | ||
import android.support.test.rule.ActivityTestRule; | ||
import android.support.test.runner.AndroidJUnit4; | ||
import android.support.v7.widget.Toolbar; | ||
import android.view.Gravity; | ||
import android.view.View; | ||
|
||
import org.hamcrest.Description; | ||
import org.hamcrest.Matcher; | ||
import org.hamcrest.TypeSafeMatcher; | ||
import org.junit.Rule; | ||
import org.junit.Test; | ||
import org.junit.runner.RunWith; | ||
|
||
import io.github.marktony.espresso.R; | ||
import io.github.marktony.espresso.mvp.packages.MainActivity; | ||
|
||
import static android.support.test.espresso.Espresso.onView; | ||
import static android.support.test.espresso.assertion.ViewAssertions.matches; | ||
import static android.support.test.espresso.contrib.DrawerActions.open; | ||
import static android.support.test.espresso.contrib.DrawerMatchers.isClosed; | ||
import static android.support.test.espresso.contrib.NavigationViewActions.navigateTo; | ||
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.withParent; | ||
import static android.support.test.espresso.matcher.ViewMatchers.withText; | ||
import static org.hamcrest.Matchers.allOf; | ||
import static org.hamcrest.Matchers.not; | ||
|
||
/** | ||
* Created by lizhaotailang on 2017/5/12. | ||
* Tests for the {@link android.support.v4.widget.DrawerLayout} layout | ||
* component in {@link MainActivity} which manages the navigation | ||
* within the app. | ||
*/ | ||
|
||
@RunWith(AndroidJUnit4.class) | ||
@LargeTest | ||
public class AppNavigationTest { | ||
|
||
/** | ||
* {@link ActivityTestRule} is a JUnit {@link Rule @Rule} to launch your activity under test. | ||
* | ||
* <p> | ||
* Rules are interceptors which are executed for each test method and are important building | ||
* blocks of Junit tests. | ||
*/ | ||
@Rule | ||
public ActivityTestRule<MainActivity> mainActivityActivityTestRule | ||
= new ActivityTestRule<>(MainActivity.class); | ||
|
||
@Test | ||
public void clickOnNavigationDrawerItem_ShowsPackagesScreen() { | ||
// Open drawer to click on navigation. | ||
onView(withId(R.id.drawer_layout)) | ||
.check(matches(isClosed(Gravity.LEFT))) // Left drawer should be closed. | ||
.perform(open()); // Open the drawer. | ||
|
||
// Start packages screen | ||
onView(withId(R.id.nav_view)) | ||
.perform(navigateTo(R.id.nav_home)); | ||
|
||
// Check that packages fragment was opened. | ||
onView(withId(R.id.fragment_packages)) | ||
.check(matches(isDisplayed())); | ||
|
||
} | ||
|
||
@Test | ||
public void clickOnNavigationDrawerItem_ShowsCompaniesScreen() { | ||
// Open drawer to click on navigation. | ||
onView(withId(R.id.drawer_layout)) | ||
.check(matches(isClosed(Gravity.LEFT))) // Left drawer should be closed. | ||
.perform(open()); // Open the drawer. | ||
|
||
// Start companies screen | ||
onView(withId(R.id.nav_view)) | ||
.perform(navigateTo(R.id.nav_companies)); | ||
|
||
// Check that companies fragment was opened. | ||
onView(withId(R.id.recyclerViewCompaniesList)) | ||
.check(matches(isDisplayed())); | ||
} | ||
|
||
@Test | ||
public void clickOnNavigationDrawerItem_ShowsSettingsScreen() { | ||
// Open drawer to click on navigation. | ||
onView(withId(R.id.drawer_layout)) | ||
.check(matches(isClosed(Gravity.LEFT))) | ||
.perform(open()); | ||
|
||
// Start settings screen. | ||
onView(withId(R.id.nav_view)) | ||
.perform(navigateTo(R.id.nav_settings)); | ||
|
||
// Check that title is correct. | ||
onView(allOf(withParent(withId(R.id.toolbar)), | ||
withText(R.string.nav_settings))) | ||
.check(matches(isDisplayed())); | ||
} | ||
|
||
@Test | ||
public void clickOnNavigationDrawerItem_ShowsAboutScreen() { | ||
// Open drawer to click on navigation. | ||
onView(withId(R.id.drawer_layout)) | ||
.check(matches(isClosed(Gravity.LEFT))) | ||
.perform(open()); | ||
|
||
// Start about screen. | ||
onView(withId(R.id.nav_view)) | ||
.perform(navigateTo(R.id.nav_about)); | ||
|
||
// Check that title is correct. | ||
onView(allOf(withParent(withId(R.id.toolbar)), | ||
withText(R.string.nav_about))) | ||
.check(matches(isDisplayed())); | ||
} | ||
|
||
@Test | ||
public void clickOnNavigationDrawerItem_ChangeTheme() { | ||
// Open drawer to click on navigation. | ||
onView(withId(R.id.drawer_layout)) | ||
.check(matches(isClosed(Gravity.LEFT))) | ||
.perform(open()); | ||
|
||
// Get the color value of toolbar in package fragment. | ||
Toolbar toolbar = (Toolbar) mainActivityActivityTestRule.getActivity().findViewById(R.id.toolbar); | ||
int color = ((ColorDrawable) toolbar.getBackground()).getColor(); | ||
|
||
// Click the navigate item of changing theme. | ||
onView(withId(R.id.nav_view)) | ||
.perform(navigateTo(R.id.nav_switch_theme)); | ||
|
||
// Compare the current color with the old one. | ||
// If not match, the action of changing theme is successful. | ||
onView(withId(R.id.toolbar)) | ||
.check(matches(not(withBackgroundColor(color)))); | ||
|
||
} | ||
|
||
/** | ||
* A customized {@link Matcher} for testing that | ||
* if one color match the background color of current view. | ||
* @param backgroundColor A color int value. | ||
* | ||
* @return Match or not. | ||
*/ | ||
public static Matcher<View> withBackgroundColor(final int backgroundColor) { | ||
return new TypeSafeMatcher<View>() { | ||
|
||
@Override | ||
public boolean matchesSafely(View view) { | ||
int color = ((ColorDrawable) view.getBackground().getCurrent()).getColor(); | ||
return color == backgroundColor; | ||
} | ||
|
||
@Override | ||
public void describeTo(Description description) { | ||
description.appendText("with background color value: " + backgroundColor); | ||
} | ||
}; | ||
} | ||
|
||
} |
26 changes: 26 additions & 0 deletions
26
app/src/androidTest/java/io/github/marktony/espresso/packages/PackagesScreenTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
package io.github.marktony.espresso.packages; | ||
|
||
import android.support.test.filters.LargeTest; | ||
import android.support.test.rule.ActivityTestRule; | ||
import android.support.test.runner.AndroidJUnit4; | ||
|
||
import org.junit.Rule; | ||
import org.junit.runner.RunWith; | ||
|
||
import io.github.marktony.espresso.mvp.packages.MainActivity; | ||
|
||
/** | ||
* Created by lizhaotailang on 2017/5/12. | ||
*/ | ||
|
||
@RunWith(AndroidJUnit4.class) | ||
@LargeTest | ||
public class PackagesScreenTest { | ||
|
||
@Rule | ||
public ActivityTestRule<MainActivity> mainActivityActivityTestRule | ||
= new ActivityTestRule<>(MainActivity.class); | ||
|
||
|
||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters