Improve clicking behaviour

This commit is contained in:
Marcatili, Manuel
2026-04-16 10:11:58 +03:00
committed by mmarca.tech
parent 40494557d4
commit b679f00cc5
5 changed files with 208 additions and 54 deletions
@@ -1,18 +1,21 @@
package de.dennisguse.opentracks.ui.aggregatedStatistics;
import static androidx.test.espresso.Espresso.onView;
import static androidx.test.espresso.action.ViewActions.click;
import static androidx.test.espresso.assertion.ViewAssertions.matches;
import static androidx.test.espresso.matcher.RootMatchers.isDialog;
import static androidx.test.espresso.matcher.ViewMatchers.hasDescendant;
import static androidx.test.espresso.matcher.ViewMatchers.isDisplayed;
import static androidx.test.espresso.matcher.ViewMatchers.isRoot;
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 de.dennisguse.opentracks.util.EspressoUtils.waitForView;
import static de.dennisguse.opentracks.util.EspressoUtils.performClick;
import static de.dennisguse.opentracks.util.EspressoUtils.waitForResumedView;
import static de.dennisguse.opentracks.util.EspressoUtils.waitForResumedViewCondition;
import static de.dennisguse.opentracks.util.EspressoUtils.withRecyclerViewItemCount;
import static org.hamcrest.Matchers.allOf;
import android.content.Context;
import android.content.Intent;
import android.util.Pair;
import android.view.View;
@@ -40,6 +43,7 @@ import de.dennisguse.opentracks.data.ContentProviderUtils;
import de.dennisguse.opentracks.data.models.Track;
import de.dennisguse.opentracks.data.models.TrackBuilder;
import de.dennisguse.opentracks.data.models.TrackPoint;
import de.dennisguse.opentracks.services.TrackRecordingService;
@LargeTest
@RunWith(AndroidJUnit4.class)
@@ -56,8 +60,11 @@ public class EspressoAggregatedFilterTest {
@Before
public void setUp() {
ContentProviderUtils contentProviderUtils = new ContentProviderUtils(ApplicationProvider.getApplicationContext());
contentProviderUtils.deleteAllTracks(ApplicationProvider.getApplicationContext());
Context context = ApplicationProvider.getApplicationContext();
context.stopService(new Intent(context, TrackRecordingService.class));
ContentProviderUtils contentProviderUtils = new ContentProviderUtils(context);
contentProviderUtils.deleteAllTracks(context);
Pair<Track, List<TrackPoint>> pair = TestDataUtil.createTrack(new Track.Id(System.currentTimeMillis()), 20);
TrackBuilder trackBuilder = new TrackBuilder(pair.first);
@@ -69,6 +76,8 @@ public class EspressoAggregatedFilterTest {
@After
public void tearDown() {
Context context = ApplicationProvider.getApplicationContext();
context.stopService(new Intent(context, TrackRecordingService.class));
if (scenario != null) {
scenario.close();
}
@@ -78,6 +87,8 @@ public class EspressoAggregatedFilterTest {
public void espressoAggregatedFilterTest() {
waitUntilDisplayed(withId(R.id.bottom_app_bar));
waitUntilDisplayed(withId(R.id.aggregated_statistics_filter));
waitUntilRecyclerViewItemCount(withId(R.id.aggregated_stats_list), 1);
waitUntilDisplayed(allOf(withId(R.id.aggregated_stats_type_label), withText(ACTIVITY_TYPE_LOCALIZED)));
// open FilterDialogFragment through the current bottom app bar action item
onView(withId(R.id.bottom_app_bar))
@@ -85,23 +96,25 @@ public class EspressoAggregatedFilterTest {
onView(withId(R.id.bottom_app_bar))
.check(matches(hasDescendant(withId(R.id.aggregated_statistics_filter))));
onView(withId(R.id.aggregated_statistics_filter))
.perform(click());
.perform(performClick());
// check there's a checkbox with ACTIVITY_TYPE_LOCALIZED text
Matcher<View> activityTypeFilter = allOf(withId(R.id.filter_dialog_check_button), withText(ACTIVITY_TYPE_LOCALIZED),
withParent(allOf(withId(R.id.filter_items),
withParent(IsInstanceOf.instanceOf(android.view.ViewGroup.class)))),
isDisplayed());
waitUntilDisplayedInCurrentRoot(activityTypeFilter);
onView(activityTypeFilter)
.inRoot(isDialog())
.check(matches(isDisplayed()));
// check there's an edit text for "from date"
onView(withId(R.id.filter_date_edit_text_from))
.inRoot(isDialog())
.check(matches(isDisplayed()));
// check there's an edit text for "to date"
onView(withId(R.id.filter_date_edit_text_to))
.inRoot(isDialog())
.check(matches(isDisplayed()));
}
@@ -109,7 +122,11 @@ public class EspressoAggregatedFilterTest {
waitForResumedView(allOf(viewMatcher, isDisplayed()), UI_TIMEOUT);
}
private void waitUntilDisplayedInCurrentRoot(Matcher<View> viewMatcher) {
onView(isRoot()).perform(waitForView(allOf(viewMatcher, isDisplayed()), UI_TIMEOUT));
private void waitUntilRecyclerViewItemCount(Matcher<View> viewMatcher, int expectedCount) {
waitForResumedViewCondition(
allOf(viewMatcher, isDisplayed()),
view -> withRecyclerViewItemCount(expectedCount).matches(view),
"RecyclerView item count to be " + expectedCount,
UI_TIMEOUT);
}
}