From 08902472a360484ebb0d483f2ea69e0f499c98b1 Mon Sep 17 00:00:00 2001 From: Bipin Date: Tue, 5 Jan 2021 13:27:25 +0100 Subject: [PATCH] Added Settings and Statistics, started detail --- .../a1/nextlocation/LocationFragmentTest.java | 1 - .../nextlocation/RouteDetailFragmentTest.java | 43 ++++++++++++ .../a1/nextlocation/SettingsFragmentTest.java | 70 +++++++++++++++++++ .../nextlocation/StatisticFragmentTest.java | 38 ++++++++++ app/src/main/res/layout/fragment_settings.xml | 4 ++ 5 files changed, 155 insertions(+), 1 deletion(-) create mode 100644 app/src/androidTest/java/com/a1/nextlocation/RouteDetailFragmentTest.java create mode 100644 app/src/androidTest/java/com/a1/nextlocation/SettingsFragmentTest.java create mode 100644 app/src/androidTest/java/com/a1/nextlocation/StatisticFragmentTest.java diff --git a/app/src/androidTest/java/com/a1/nextlocation/LocationFragmentTest.java b/app/src/androidTest/java/com/a1/nextlocation/LocationFragmentTest.java index f6d1e55..611a1d7 100644 --- a/app/src/androidTest/java/com/a1/nextlocation/LocationFragmentTest.java +++ b/app/src/androidTest/java/com/a1/nextlocation/LocationFragmentTest.java @@ -27,7 +27,6 @@ public class LocationFragmentTest { 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 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..365e6ad --- /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.settingsBackButton)).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.settingsEyeButton)).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.settingsEyeButton)).perform(click()); + onView(withId(R.id.settingsEyeButton)).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..f13909b --- /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.Box1)).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 84ca1c0..81f6f43 100644 --- a/app/src/main/res/layout/fragment_settings.xml +++ b/app/src/main/res/layout/fragment_settings.xml @@ -9,6 +9,7 @@ tools:context=".fragments.SettingsFragment">