forked from osmandapp/OsmAnd
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
3e3e3d8
commit 904e482
Showing
3 changed files
with
145 additions
and
105 deletions.
There are no files selected for viewing
70 changes: 70 additions & 0 deletions
70
OsmAnd/test/java/net/osmand/plus/settings/fragments/search/SearchButtonClick.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,70 @@ | ||
package net.osmand.plus.settings.fragments.search; | ||
|
||
import static androidx.test.espresso.Espresso.onData; | ||
import static androidx.test.espresso.Espresso.onView; | ||
import static androidx.test.espresso.action.ViewActions.click; | ||
import static androidx.test.espresso.matcher.ViewMatchers.isDisplayed; | ||
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 net.osmand.test.common.Matchers.childAtPosition; | ||
import static net.osmand.test.common.OsmAndDialogInteractions.skipAppStartDialogs; | ||
import static org.hamcrest.Matchers.allOf; | ||
import static org.hamcrest.Matchers.anything; | ||
import static org.hamcrest.Matchers.is; | ||
|
||
import android.view.View; | ||
|
||
import androidx.test.espresso.DataInteraction; | ||
|
||
import net.osmand.plus.OsmandApplication; | ||
import net.osmand.plus.R; | ||
|
||
import org.hamcrest.Matcher; | ||
|
||
class SearchButtonClick { | ||
|
||
public static void clickSearchButton(final OsmandApplication osmandApplication) { | ||
skipAppStartDialogs(osmandApplication); | ||
onView(mapMenuButton()).perform(click()); | ||
settingsButton().perform(click()); | ||
onView(searchButton()).perform(click()); | ||
} | ||
|
||
private static Matcher<View> mapMenuButton() { | ||
return allOf( | ||
withId(R.id.map_menu_button), | ||
withContentDescription("Back to menu"), | ||
childAtPosition( | ||
allOf( | ||
withId(R.id.map_hud_layout), | ||
childAtPosition( | ||
withId(R.id.map_hud_container), | ||
0)), | ||
10), | ||
isDisplayed()); | ||
} | ||
|
||
private static DataInteraction settingsButton() { | ||
return onData(anything()) | ||
.inAdapterView( | ||
allOf( | ||
withId(R.id.menuItems), | ||
childAtPosition( | ||
withId(R.id.drawer_relative_layout), | ||
0))) | ||
.atPosition(13); | ||
} | ||
|
||
private static Matcher<View> searchButton() { | ||
return allOf( | ||
withId(R.id.action_button), | ||
childAtPosition( | ||
allOf(withId(R.id.actions_container), | ||
childAtPosition( | ||
withClassName(is("android.widget.LinearLayout")), | ||
2)), | ||
0), | ||
isDisplayed()); | ||
} | ||
} |
69 changes: 69 additions & 0 deletions
69
.../test/java/net/osmand/plus/settings/fragments/search/SettingsSearchParameterizedTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,69 @@ | ||
package net.osmand.plus.settings.fragments.search; | ||
|
||
import static androidx.test.espresso.Espresso.onView; | ||
import static androidx.test.espresso.action.ViewActions.closeSoftKeyboard; | ||
import static androidx.test.espresso.action.ViewActions.replaceText; | ||
import static androidx.test.espresso.assertion.ViewAssertions.matches; | ||
import static net.osmand.plus.settings.fragments.search.SearchButtonClick.clickSearchButton; | ||
import static net.osmand.plus.settings.fragments.search.SettingsSearchTest.hasSearchResultWithSubstring; | ||
import static net.osmand.plus.settings.fragments.search.SettingsSearchTest.searchResultsView; | ||
import static net.osmand.plus.settings.fragments.search.SettingsSearchTest.searchView; | ||
|
||
import androidx.annotation.StringRes; | ||
import androidx.test.ext.junit.rules.ActivityScenarioRule; | ||
import androidx.test.filters.LargeTest; | ||
|
||
import net.osmand.plus.R; | ||
import net.osmand.plus.activities.MapActivity; | ||
import net.osmand.test.common.AndroidTest; | ||
|
||
import org.junit.Rule; | ||
import org.junit.Test; | ||
import org.junit.runner.RunWith; | ||
import org.junit.runners.Parameterized; | ||
|
||
import java.util.Arrays; | ||
|
||
@LargeTest | ||
@RunWith(Parameterized.class) | ||
public class SettingsSearchParameterizedTest extends AndroidTest { | ||
|
||
@Parameterized.Parameter(value = 0) | ||
public String description; | ||
|
||
@Parameterized.Parameter(value = 1) | ||
public @StringRes int searchQueryId; | ||
|
||
@Parameterized.Parameters(name = "{0}") | ||
public static Iterable<Object[]> data() { | ||
return Arrays.asList( | ||
new Object[][]{ | ||
{"RecalculateRoute", R.string.recalculate_route}, | ||
{"AnnouncementTimeBottomSheet_title", R.string.announcement_time_title}, | ||
{"AnnouncementTimeBottomSheet_description", R.string.announcement_time_descr}, | ||
{"FuelTankCapacityBottomSheet_description", R.string.fuel_tank_capacity_description}, | ||
{"RecalculateRouteInDeviationBottomSheet_title", R.string.recalculate_route_in_deviation}, | ||
{"RecalculateRouteInDeviationBottomSheet_description", R.string.select_distance_route_will_recalc}, | ||
{"RecalculateRouteInDeviationBottomSheet_longDescription", R.string.recalculate_route_distance_promo} | ||
}); | ||
} | ||
|
||
@Rule | ||
public ActivityScenarioRule<MapActivity> mActivityScenarioRule = new ActivityScenarioRule<>(MapActivity.class); | ||
|
||
@Test | ||
public void testSearchAndFind() { | ||
testSearchAndFind(app.getResources().getString(searchQueryId)); | ||
} | ||
|
||
private void testSearchAndFind(final String searchQuery) { | ||
// Given | ||
clickSearchButton(app); | ||
|
||
// When | ||
onView(searchView()).perform(replaceText(searchQuery), closeSoftKeyboard()); | ||
|
||
// Then | ||
onView(searchResultsView()).check(matches(hasSearchResultWithSubstring(searchQuery))); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters