Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Simplified tests #119

Merged
merged 1 commit into from
May 11, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
121 changes: 19 additions & 102 deletions app/src/androidTest/java/com/futsch1/medtimer/BasicUITest.java
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@
import static androidx.test.espresso.matcher.ViewMatchers.withClassName;
import static androidx.test.espresso.matcher.ViewMatchers.withContentDescription;
import static androidx.test.espresso.matcher.ViewMatchers.withId;
import static androidx.test.espresso.matcher.ViewMatchers.withParent;
import static androidx.test.espresso.matcher.ViewMatchers.withText;
import static org.hamcrest.Matchers.allOf;
import static org.hamcrest.Matchers.anything;
Expand All @@ -28,7 +27,6 @@
import androidx.test.filters.LargeTest;
import androidx.test.rule.GrantPermissionRule;

import org.hamcrest.core.IsInstanceOf;
import org.junit.Rule;
import org.junit.Test;
import org.junit.runner.RunWith;
Expand All @@ -51,8 +49,7 @@ public void basicUITest() {
AndroidTestHelper.navigateTo(AndroidTestHelper.MainMenu.MEDICINES);

ViewInteraction extendedFloatingActionButton = onView(
allOf(withId(R.id.addMedicine), withText("Add medicine"), withContentDescription("Add medicine"),
isDisplayed()));
withId(R.id.addMedicine));
extendedFloatingActionButton.perform(click());

ViewInteraction textInputEditText = onView(
Expand All @@ -65,29 +62,15 @@ public void basicUITest() {
textInputEditText.perform(replaceText("Test"), closeSoftKeyboard());

ViewInteraction materialButton = onView(
allOf(withId(android.R.id.button1), withText("OK"),
AndroidTestHelper.childAtPosition(
AndroidTestHelper.childAtPosition(
withClassName(is("android.widget.ScrollView")),
0),
3)));
allOf(withId(android.R.id.button1), withText("OK")));
materialButton.perform(scrollTo(), click());

ViewInteraction recyclerView = onView(
allOf(withId(R.id.medicineList),
AndroidTestHelper.childAtPosition(
withClassName(is("android.widget.FrameLayout")),
0)));
allOf(withId(R.id.medicineList)));
recyclerView.perform(actionOnItemAtPosition(0, click()));

ViewInteraction extendedFloatingActionButton2 = onView(
allOf(withId(R.id.addReminder), withText("Add reminder"),
AndroidTestHelper.childAtPosition(
AndroidTestHelper.childAtPosition(
withId(R.id.navHost),
0),
1),
isDisplayed()));
allOf(withId(R.id.addReminder)));
extendedFloatingActionButton2.perform(click());

ViewInteraction textInputEditText2 = onView(
Expand All @@ -100,24 +83,14 @@ public void basicUITest() {
textInputEditText2.perform(replaceText("1"), closeSoftKeyboard());

ViewInteraction materialButton2 = onView(
allOf(withId(android.R.id.button1), withText("OK"),
AndroidTestHelper.childAtPosition(
AndroidTestHelper.childAtPosition(
withClassName(is("android.widget.ScrollView")),
0),
3)));
allOf(withId(android.R.id.button1), withText("OK")));
materialButton2.perform(scrollTo(), click());

ViewInteraction materialButton3 = onView(
allOf(withId(com.google.android.material.R.id.material_timepicker_ok_button), withText("OK"),
AndroidTestHelper.childAtPosition(
AndroidTestHelper.childAtPosition(
withId(android.R.id.content),
0),
5),
isDisplayed()));
allOf(withId(com.google.android.material.R.id.material_timepicker_ok_button), withText("OK")));
materialButton3.perform(click());

onView(isRoot()).perform(AndroidTestHelper.waitFor(1000));
ViewInteraction materialButton4 = onView(
allOf(withId(R.id.open_advanced_settings), withText("Advanced settings"),
AndroidTestHelper.childAtPosition(
Expand All @@ -126,7 +99,6 @@ public void basicUITest() {
0),
1),
isDisplayed()));
onView(isRoot()).perform(AndroidTestHelper.waitFor(1000));
materialButton4.perform(click());

ViewInteraction checkableImageButton = onView(
Expand All @@ -148,106 +120,51 @@ public void basicUITest() {
materialTextView.perform(click());

ViewInteraction appCompatImageButton = onView(
allOf(withContentDescription("Navigate up"),
AndroidTestHelper.childAtPosition(
allOf(withId(androidx.appcompat.R.id.action_bar),
AndroidTestHelper.childAtPosition(
withId(androidx.appcompat.R.id.action_bar_container),
0)),
2),
isDisplayed()));
allOf(withContentDescription("Navigate up")));
appCompatImageButton.perform(click());

ViewInteraction materialButton5 = onView(
allOf(withId(R.id.open_advanced_settings), withText("Advanced settings"),
AndroidTestHelper.childAtPosition(
AndroidTestHelper.childAtPosition(
withId(R.id.advanced_settings),
0),
1),
isDisplayed()));
allOf(withId(R.id.open_advanced_settings)));
materialButton5.perform(click());

ViewInteraction editText = onView(
allOf(withId(R.id.editInstructions), withText("before the meal"),
withParent(withParent(withId(R.id.editInstructionsLayout))),
isDisplayed()));
allOf(withId(R.id.editInstructions), withText("before the meal")));
editText.check(matches(withText("before the meal")));

ViewInteraction appCompatImageButton2 = onView(
allOf(withContentDescription("Navigate up"),
AndroidTestHelper.childAtPosition(
allOf(withId(androidx.appcompat.R.id.action_bar),
AndroidTestHelper.childAtPosition(
withId(androidx.appcompat.R.id.action_bar_container),
0)),
2),
isDisplayed()));
allOf(withContentDescription("Navigate up")));
appCompatImageButton2.perform(click());

ViewInteraction textInputEditText3 = onView(
allOf(withId(R.id.editAmount), withText("1"),
AndroidTestHelper.childAtPosition(
AndroidTestHelper.childAtPosition(
withClassName(is("com.google.android.material.textfield.TextInputLayout")),
0),
0),
isDisplayed()));
allOf(withId(R.id.editAmount), withText("1")));
textInputEditText3.perform(replaceText("2"));

ViewInteraction textInputEditText4 = onView(
allOf(withId(R.id.editAmount), withText("2"),
AndroidTestHelper.childAtPosition(
AndroidTestHelper.childAtPosition(
withClassName(is("com.google.android.material.textfield.TextInputLayout")),
0),
0),
isDisplayed()));
allOf(withId(R.id.editAmount), withText("2")));
textInputEditText4.perform(closeSoftKeyboard());

ViewInteraction appCompatImageButton3 = onView(
allOf(withContentDescription("Navigate up"),
AndroidTestHelper.childAtPosition(
allOf(withId(androidx.appcompat.R.id.action_bar),
AndroidTestHelper.childAtPosition(
withId(androidx.appcompat.R.id.action_bar_container),
0)),
2),
isDisplayed()));
allOf(withContentDescription("Navigate up")));
appCompatImageButton3.perform(click());

ViewInteraction recyclerView2 = onView(
allOf(withId(R.id.medicineList),
AndroidTestHelper.childAtPosition(
withClassName(is("android.widget.FrameLayout")),
0)));
onView(isRoot()).perform(AndroidTestHelper.waitFor(100));
ViewInteraction recyclerView2 = onView(
allOf(withId(R.id.medicineList)));
recyclerView2.perform(actionOnItemAtPosition(0, click()));

ViewInteraction editText2 = onView(
allOf(withId(R.id.editAmount), withText("2"),
withParent(withParent(IsInstanceOf.instanceOf(android.widget.LinearLayout.class))),
isDisplayed()));
allOf(withId(R.id.editAmount), withText("2")));
editText2.check(matches(withText("2")));

ViewInteraction appCompatImageButton4 = onView(
allOf(withContentDescription("Navigate up"),
AndroidTestHelper.childAtPosition(
allOf(withId(androidx.appcompat.R.id.action_bar),
AndroidTestHelper.childAtPosition(
withId(androidx.appcompat.R.id.action_bar_container),
0)),
2),
isDisplayed()));
allOf(withContentDescription("Navigate up")));
appCompatImageButton4.perform(click());

AndroidTestHelper.navigateTo(AndroidTestHelper.MainMenu.OVERVIEW);
onView(isRoot()).perform(AndroidTestHelper.waitFor(1000));

ViewInteraction textView = onView(
allOf(withId(R.id.nextReminderInfo),
withParent(withParent(IsInstanceOf.instanceOf(androidx.cardview.widget.CardView.class))),
isDisplayed()));
allOf(withId(R.id.nextReminderInfo)));
textView.check(matches(withText(startsWith("2 of Test"))));
}

Expand Down
48 changes: 6 additions & 42 deletions app/src/androidTest/java/com/futsch1/medtimer/StatisticsTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -56,23 +56,11 @@ public void statisticsTest() {
onView(isRoot()).perform(AndroidTestHelper.waitFor(1000));

ViewInteraction overflowMenuButton = onView(
allOf(withContentDescription("More options"),
AndroidTestHelper.childAtPosition(
AndroidTestHelper.childAtPosition(
withId(androidx.appcompat.R.id.action_bar),
1),
0),
isDisplayed()));
allOf(withContentDescription("More options")));
overflowMenuButton.perform(click());

ViewInteraction materialTextView = onView(
allOf(withId(androidx.recyclerview.R.id.title), withText("Generate test data"),
AndroidTestHelper.childAtPosition(
AndroidTestHelper.childAtPosition(
withId(androidx.appcompat.R.id.content),
1),
0),
isDisplayed()));
allOf(withId(androidx.recyclerview.R.id.title), withText("Generate test data")));
materialTextView.perform(click());
onView(isRoot()).perform(AndroidTestHelper.waitFor(4000));

Expand All @@ -95,13 +83,7 @@ public void statisticsTest() {
AndroidTestHelper.navigateTo(AndroidTestHelper.MainMenu.ANALYSIS);

ViewInteraction appCompatSpinner = onView(
allOf(withId(R.id.timeSpinner),
AndroidTestHelper.childAtPosition(
AndroidTestHelper.childAtPosition(
withClassName(is("android.widget.LinearLayout")),
0),
2),
isDisplayed()));
allOf(withId(R.id.timeSpinner)));
appCompatSpinner.perform(click());

DataInteraction materialTextView2 = onData(anything())
Expand All @@ -112,13 +94,7 @@ public void statisticsTest() {
materialTextView2.perform(click());

ViewInteraction materialButton = onView(
allOf(withId(R.id.reminderTableButton), withText("Tabular view"),
AndroidTestHelper.childAtPosition(
AndroidTestHelper.childAtPosition(
withClassName(is("android.widget.LinearLayout")),
0),
0),
isDisplayed()));
allOf(withId(R.id.reminderTableButton), withText("Tabular view")));
materialButton.perform(click());

ViewInteraction linearLayout = onView(
Expand All @@ -141,27 +117,15 @@ public void statisticsTest() {
textView.check(matches(withText(startsWith("Selen (200 µg)"))));

ViewInteraction textInputEditText = onView(
allOf(withId(R.id.filter),
AndroidTestHelper.childAtPosition(
AndroidTestHelper.childAtPosition(
withId(R.id.filterLayout),
0),
0),
isDisplayed()));
allOf(withId(R.id.filter)));
textInputEditText.perform(replaceText("B"), closeSoftKeyboard());

ViewInteraction textView3 = onView(
new RecyclerViewMatcher(tableCellRecyclerViewId).atPositionOnView(0, "medicineName"));
textView3.check(matches(withText("B12 (500µg)")));

ViewInteraction checkableImageButton = onView(
allOf(withId(com.google.android.material.R.id.text_input_end_icon),
AndroidTestHelper.childAtPosition(
AndroidTestHelper.childAtPosition(
withClassName(is("com.google.android.material.textfield.EndCompoundLayout")),
1),
0),
isDisplayed()));
allOf(withId(com.google.android.material.R.id.text_input_end_icon)));
checkableImageButton.perform(click());
}

Expand Down