diff --git a/app/build.gradle b/app/build.gradle index 003cd15..a5eb575 100644 --- a/app/build.gradle +++ b/app/build.gradle @@ -56,4 +56,7 @@ dependencies { androidTestImplementation 'androidx.test.ext:junit:1.1.2' androidTestImplementation 'androidx.test.espresso:espresso-core:3.3.0' testImplementation 'org.mockito:mockito-core:2.7.22' + androidTestImplementation 'com.21buttons:fragment-test-rule:2.0.1' + androidTestImplementation 'androidx.test:rules:1.3.0-beta01' + androidTestImplementation 'androidx.test.espresso:espresso-contrib:3.4.0-alpha02' } \ No newline at end of file diff --git a/app/src/androidTest/java/com/a1/nextlocation/LocationFragmentTest.java b/app/src/androidTest/java/com/a1/nextlocation/LocationFragmentTest.java new file mode 100644 index 0000000..f6d1e55 --- /dev/null +++ b/app/src/androidTest/java/com/a1/nextlocation/LocationFragmentTest.java @@ -0,0 +1,41 @@ +package com.a1.nextlocation; + +import androidx.test.espresso.contrib.RecyclerViewActions; +import androidx.test.rule.ActivityTestRule; + +import com.a1.nextlocation.fragments.LocationFragment; + +import org.junit.Rule; +import org.junit.Test; +import org.junit.runner.RunWith; + +import javax.inject.Inject; + +import static androidx.test.espresso.Espresso.*; +import static androidx.test.espresso.action.ViewActions.*; +import static androidx.test.espresso.assertion.ViewAssertions.*; +import static androidx.test.espresso.matcher.ViewMatchers.*; + + +public class LocationFragmentTest { + + @Rule + public ActivityTestRule mActivityTestRule = new ActivityTestRule<>(MainActivity.class); + + @Test + public void clickBackButton() throws Exception{ + mActivityTestRule.getActivity().getSupportFragmentManager().beginTransaction().replace(R.id.mainActivity, new LocationFragment()).commit(); + onView(withId(R.id.locationBackButton)).perform(click()); + onView(withId(R.id.homeFragment)).check(matches(isDisplayed())); + + } + + @Test + public void clickDetailButton() throws Exception{ + mActivityTestRule.getActivity().getSupportFragmentManager().beginTransaction().replace(R.id.mainActivity, new LocationFragment()).commit(); + onView(withId(R.id.locationRecyclerView)).perform(RecyclerViewActions.actionOnItemAtPosition(1, click())); + onView(withId(R.id.locationDetailFragment)).check(matches(isDisplayed())); + + } + +} diff --git a/app/src/main/res/layout/activity_main.xml b/app/src/main/res/layout/activity_main.xml index 97123a3..21c68f8 100644 --- a/app/src/main/res/layout/activity_main.xml +++ b/app/src/main/res/layout/activity_main.xml @@ -4,6 +4,7 @@ xmlns:tools="http://schemas.android.com/tools" android:layout_width="match_parent" android:layout_height="match_parent" + android:id="@+id/mainActivity" tools:context=".MainActivity"> diff --git a/app/src/main/res/layout/fragment_location.xml b/app/src/main/res/layout/fragment_location.xml index 7f03472..dd633d8 100644 --- a/app/src/main/res/layout/fragment_location.xml +++ b/app/src/main/res/layout/fragment_location.xml @@ -5,6 +5,7 @@ android:layout_width="match_parent" android:layout_height="match_parent" android:background="@color/primaryColour" + android:id="@+id/locationFragment" tools:context=".fragments.LocationFragment"> + app:layout_constraintTop_toBottomOf="@+id/locationBackButton" /> \ No newline at end of file diff --git a/app/src/main/res/layout/fragment_location_detail.xml b/app/src/main/res/layout/fragment_location_detail.xml index 17b7203..bbf0508 100644 --- a/app/src/main/res/layout/fragment_location_detail.xml +++ b/app/src/main/res/layout/fragment_location_detail.xml @@ -5,6 +5,7 @@ android:layout_width="match_parent" android:layout_height="match_parent" android:background="@color/primaryColour" + android:id="@+id/locationDetailFragment" tools:context=".fragments.LocationDetailFragment">