Added three tests to test clearing the search view
This commit is contained in:
parent
7887ced41e
commit
632c547f38
|
@ -35,11 +35,13 @@ import static android.support.test.espresso.assertion.ViewAssertions.doesNotExis
|
|||
import static android.support.test.espresso.assertion.ViewAssertions.matches;
|
||||
import static android.support.test.espresso.matcher.ViewMatchers.isAssignableFrom;
|
||||
import static android.support.test.espresso.matcher.ViewMatchers.isDisplayed;
|
||||
import static android.support.test.espresso.matcher.ViewMatchers.withContentDescription;
|
||||
import static android.support.test.espresso.matcher.ViewMatchers.withId;
|
||||
import static android.support.test.espresso.matcher.ViewMatchers.withText;
|
||||
import static org.hamcrest.Matchers.allOf;
|
||||
import static org.hamcrest.Matchers.anything;
|
||||
import static org.hamcrest.Matchers.containsString;
|
||||
import static org.xbmc.kore.testhelpers.action.ViewActions.clearFocus;
|
||||
|
||||
public class EspressoTestUtils {
|
||||
|
||||
|
@ -71,8 +73,18 @@ public class EspressoTestUtils {
|
|||
}
|
||||
}
|
||||
|
||||
public static void clickHomeButton() {
|
||||
onView(withId(android.R.id.home)).perform(click());
|
||||
/**
|
||||
* Clicks the arrow button in the toolbar when its function is collapsing a view. For instance,
|
||||
* collapse the search view in the toolbar.
|
||||
*/
|
||||
public static void clickToolbarCollapseButton() {
|
||||
/**
|
||||
* The image button in the toolbar used as home/collapse/back button has no ID we can use.
|
||||
* In appcompat v7 the arrow button in the toolbar used to collapse a search view has a
|
||||
* description "Collapse". We use this to find the button in the view and perform the click
|
||||
* action.
|
||||
*/
|
||||
onView(withContentDescription("Collapse")).perform(click());
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -84,7 +96,7 @@ public class EspressoTestUtils {
|
|||
EspressoTestUtils.clickMenuItem(activity, activity.getString(R.string.action_search), R.id.action_search);
|
||||
|
||||
onView(isAssignableFrom(AutoCompleteTextView.class))
|
||||
.perform(click(), typeText(query));
|
||||
.perform(click(), typeText(query), clearFocus());
|
||||
|
||||
Espresso.closeSoftKeyboard();
|
||||
}
|
||||
|
|
|
@ -0,0 +1,48 @@
|
|||
/**
|
||||
* Copyright (C) 2014 Subito.it S.r.l (www.subito.it)
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
package org.xbmc.kore.testhelpers.action;
|
||||
|
||||
import android.support.test.espresso.UiController;
|
||||
import android.support.test.espresso.ViewAction;
|
||||
import android.view.View;
|
||||
|
||||
import org.hamcrest.Matcher;
|
||||
import static org.hamcrest.Matchers.allOf;
|
||||
|
||||
import static android.support.test.espresso.matcher.ViewMatchers.isDisplayed;
|
||||
import static android.support.test.espresso.matcher.ViewMatchers.isAssignableFrom;
|
||||
|
||||
public class ClearFocus implements ViewAction {
|
||||
|
||||
@Override
|
||||
public Matcher<View> getConstraints() {
|
||||
|
||||
return allOf(isDisplayed(), isAssignableFrom(View.class));
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getDescription() {
|
||||
|
||||
return "Clear focus on the given view";
|
||||
}
|
||||
|
||||
@Override
|
||||
public void perform(UiController uiController, View view) {
|
||||
|
||||
view.clearFocus();
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,36 @@
|
|||
/*
|
||||
* Copyright 2016 Martijn Brekhof. All rights reserved.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package org.xbmc.kore.testhelpers.action;
|
||||
|
||||
|
||||
import android.support.test.espresso.ViewAction;
|
||||
import static android.support.test.espresso.action.ViewActions.actionWithAssertions;
|
||||
|
||||
public final class ViewActions {
|
||||
/**
|
||||
* Returns an action that clears the focus on the view.
|
||||
* <br/>
|
||||
* View constraints:
|
||||
* <ul>
|
||||
* <li>must be displayed on screen</li>
|
||||
* </ul>
|
||||
*/
|
||||
public static ViewAction clearFocus() {
|
||||
return actionWithAssertions(new ClearFocus());
|
||||
}
|
||||
|
||||
}
|
|
@ -187,6 +187,7 @@ public class RestoreSearchQueryListFragmentTest {
|
|||
* 2. Press back
|
||||
* 3. Result: search query should be cleared, collapsed, and list should show everything
|
||||
*/
|
||||
@Test
|
||||
public void searchBackTest() {
|
||||
EspressoTestUtils.enterSearchQuery(mActivityRule.getActivity(), SEARCH_QUERY);
|
||||
Espresso.pressBack();
|
||||
|
@ -204,11 +205,12 @@ public class RestoreSearchQueryListFragmentTest {
|
|||
* 4. Press home button
|
||||
* 5. Result: search query should be cleared, collapsed, and list should show everything
|
||||
*/
|
||||
@Test
|
||||
public void searchClickBackUpTest() {
|
||||
EspressoTestUtils.enterSearchQuery(mActivityRule.getActivity(), SEARCH_QUERY);
|
||||
EspressoTestUtils.clickAdapterViewItem(0, R.id.list);
|
||||
Espresso.pressBack();
|
||||
EspressoTestUtils.clickHomeButton();
|
||||
EspressoTestUtils.clickToolbarCollapseButton();
|
||||
EspressoTestUtils.checkSearchMenuCollapsed();
|
||||
EspressoTestUtils.checkListMatchesSearchQuery("", COMPLETE_LIST_SIZE, R.id.list);
|
||||
}
|
||||
|
@ -221,10 +223,10 @@ public class RestoreSearchQueryListFragmentTest {
|
|||
* 2. Press home button
|
||||
* 3. Result: search query should be cleared, collapsed, and list should show everything
|
||||
*/
|
||||
@Test
|
||||
public void searchUpTest() {
|
||||
EspressoTestUtils.enterSearchQuery(mActivityRule.getActivity(), SEARCH_QUERY);
|
||||
Espresso.pressBack();
|
||||
EspressoTestUtils.clickHomeButton();
|
||||
EspressoTestUtils.clickToolbarCollapseButton();
|
||||
EspressoTestUtils.checkSearchMenuCollapsed();
|
||||
EspressoTestUtils.checkListMatchesSearchQuery("", COMPLETE_LIST_SIZE, R.id.list);
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue