diff --git a/app/src/androidTest/java/com/a1/nextlocation/LocationFragmentTest.java b/app/src/androidTest/java/com/a1/nextlocation/LocationFragmentTest.java index 5f13c79..77ac98d 100644 --- a/app/src/androidTest/java/com/a1/nextlocation/LocationFragmentTest.java +++ b/app/src/androidTest/java/com/a1/nextlocation/LocationFragmentTest.java @@ -28,7 +28,6 @@ public class LocationFragmentTest { mActivityTestRule.getActivity().getSupportFragmentManager().beginTransaction().replace(R.id.mainActivity, new LocationFragment()).commit(); onView(withId(R.id.location_back_button)).perform(click()); onView(withId(R.id.homeFragment)).check(matches(isDisplayed())); - } @Test diff --git a/app/src/androidTest/java/com/a1/nextlocation/RouteDetailFragmentTest.java b/app/src/androidTest/java/com/a1/nextlocation/RouteDetailFragmentTest.java new file mode 100644 index 0000000..b756bd8 --- /dev/null +++ b/app/src/androidTest/java/com/a1/nextlocation/RouteDetailFragmentTest.java @@ -0,0 +1,43 @@ +package com.a1.nextlocation; + +import androidx.test.espresso.action.ViewActions; +import androidx.test.espresso.contrib.RecyclerViewActions; +import androidx.test.espresso.matcher.RootMatchers; +import androidx.test.espresso.matcher.ViewMatchers; +import androidx.test.rule.ActivityTestRule; + +import com.a1.nextlocation.fragments.LocationFragment; +import com.a1.nextlocation.fragments.RouteDetailFragment; +import com.a1.nextlocation.fragments.SettingsFragment; +import com.a1.nextlocation.fragments.StatisticFragment; + +import org.hamcrest.core.AllOf; +import org.hamcrest.core.Is; +import org.hamcrest.core.IsInstanceOf; +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.RootMatchers.isPlatformPopup; +import static androidx.test.espresso.matcher.ViewMatchers.*; +import static org.hamcrest.Matchers.allOf; +import static org.hamcrest.Matchers.*; +import static org.hamcrest.Matchers.is; + +public class RouteDetailFragmentTest { + + @Rule + public ActivityTestRule mActivityTestRule = new ActivityTestRule<>(MainActivity.class); + + @Test + public void clickBackButton() throws Exception{ + mActivityTestRule.getActivity().getSupportFragmentManager().beginTransaction().replace(R.id.mainActivity, new RouteDetailFragment()).commit(); + onView(withId(R.id.routeDetailBackButton)).perform(click()); + onView(withId(R.id.homeFragment)).check(matches(isDisplayed())); + } +} diff --git a/app/src/androidTest/java/com/a1/nextlocation/SettingsFragmentTest.java b/app/src/androidTest/java/com/a1/nextlocation/SettingsFragmentTest.java new file mode 100644 index 0000000..e2d99dd --- /dev/null +++ b/app/src/androidTest/java/com/a1/nextlocation/SettingsFragmentTest.java @@ -0,0 +1,70 @@ +package com.a1.nextlocation; + +import androidx.test.espresso.action.ViewActions; +import androidx.test.espresso.contrib.RecyclerViewActions; +import androidx.test.espresso.matcher.RootMatchers; +import androidx.test.espresso.matcher.ViewMatchers; +import androidx.test.rule.ActivityTestRule; + +import com.a1.nextlocation.fragments.LocationFragment; +import com.a1.nextlocation.fragments.SettingsFragment; +import com.a1.nextlocation.fragments.StatisticFragment; + +import org.hamcrest.core.AllOf; +import org.hamcrest.core.Is; +import org.hamcrest.core.IsInstanceOf; +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.RootMatchers.isPlatformPopup; +import static androidx.test.espresso.matcher.ViewMatchers.*; +import static org.hamcrest.Matchers.allOf; +import static org.hamcrest.Matchers.*; +import static org.hamcrest.Matchers.is; + +public class SettingsFragmentTest { + + + @Rule + public ActivityTestRule mActivityTestRule = new ActivityTestRule<>(MainActivity.class); + + //Tests if the back button sends you back home + @Test + public void clickBackButton() throws Exception{ + mActivityTestRule.getActivity().getSupportFragmentManager().beginTransaction().replace(R.id.mainActivity, new SettingsFragment()).commit(); + onView(withId(R.id.settings_back_button)).perform(click()); + onView(withId(R.id.homeFragment)).check(matches(isDisplayed())); + } + + //Checks if the dropdown is clickable, and checks if it has children + @Test + public void dropdownTest(){ + mActivityTestRule.getActivity().getSupportFragmentManager().beginTransaction().replace(R.id.mainActivity, new SettingsFragment()).commit(); + onView(withId(R.id.dropdown_menu_Settings)).check(matches(isClickable())); + onView(withId(R.id.dropdown_menu_Settings)).check(matches(hasMinimumChildCount(1))); + } + + //Tests if all buttons are clickable, and if they get checked after being clicked. + @Test + public void buttonTest(){ + mActivityTestRule.getActivity().getSupportFragmentManager().beginTransaction().replace(R.id.mainActivity, new SettingsFragment()).commit(); + onView(withId(R.id.settingsImperialButton)).check(matches(isClickable())); + onView(withId(R.id.settingsOldButton)).check(matches(isClickable())); + onView(withId(R.id.settingsEyesButton)).check(matches(isClickable())); + + onView(withId(R.id.settingsImperialButton)).perform(click()); + onView(withId(R.id.settingsImperialButton)).check(matches(isChecked())); + + onView(withId(R.id.settingsOldButton)).perform(click()); + onView(withId(R.id.settingsOldButton)).check(matches(isChecked())); + + onView(withId(R.id.settingsEyesButton)).perform(click()); + onView(withId(R.id.settingsEyesButton)).check(matches(isChecked())); + } +} diff --git a/app/src/androidTest/java/com/a1/nextlocation/StatisticFragmentTest.java b/app/src/androidTest/java/com/a1/nextlocation/StatisticFragmentTest.java new file mode 100644 index 0000000..e04ac58 --- /dev/null +++ b/app/src/androidTest/java/com/a1/nextlocation/StatisticFragmentTest.java @@ -0,0 +1,38 @@ +package com.a1.nextlocation; + +import androidx.test.espresso.contrib.RecyclerViewActions; +import androidx.test.rule.ActivityTestRule; + +import com.a1.nextlocation.fragments.LocationFragment; +import com.a1.nextlocation.fragments.StatisticFragment; + +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 StatisticFragmentTest { + + @Rule + public ActivityTestRule mActivityTestRule = new ActivityTestRule<>(MainActivity.class); + + //Tests to see if all boxes get created + @Test + public void checkText() throws Exception{ + mActivityTestRule.getActivity().getSupportFragmentManager().beginTransaction().replace(R.id.mainActivity, new StatisticFragment()).commit(); + onView(withId(R.id.textView)).check(matches(isDisplayed())); + onView(withId(R.id.name_box)).check(matches(isDisplayed())); + onView(withId(R.id.Box2)).check(matches(isDisplayed())); + onView(withId(R.id.Box3)).check(matches(isDisplayed())); + onView(withId(R.id.Box4)).check(matches(isDisplayed())); + } + + + +} diff --git a/app/src/main/res/layout/fragment_settings.xml b/app/src/main/res/layout/fragment_settings.xml index bafe6f4..5510e08 100644 --- a/app/src/main/res/layout/fragment_settings.xml +++ b/app/src/main/res/layout/fragment_settings.xml @@ -115,6 +115,7 @@ app:layout_constraintVertical_bias="0.0" />