-
-
Notifications
You must be signed in to change notification settings - Fork 154
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Make Back button/gesture not instantly collapse the MainActivity's se…
…arch view (#2030)
- Loading branch information
1 parent
7c7a05f
commit 80e4701
Showing
4 changed files
with
123 additions
and
4 deletions.
There are no files selected for viewing
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 |
---|---|---|
|
@@ -28,6 +28,9 @@ env: | |
jobs: | ||
build: | ||
runs-on: ubuntu-latest | ||
strategy: | ||
matrix: | ||
api-level: [ 21, 34 ] | ||
steps: | ||
- uses: actions/[email protected] | ||
- name: Fail on bad translations | ||
|
@@ -44,11 +47,22 @@ jobs: | |
run: ./gradlew lintRelease | ||
- name: Run unit tests | ||
run: timeout 5m ./gradlew testReleaseUnitTest || { ./gradlew --stop && timeout 5m ./gradlew testReleaseUnitTest; } | ||
- name: Enable KVM | ||
run: | | ||
echo 'KERNEL=="kvm", GROUP="kvm", MODE="0666", OPTIONS+="static_node=kvm"' | sudo tee /etc/udev/rules.d/99-kvm4all.rules | ||
sudo udevadm control --reload-rules | ||
sudo udevadm trigger --name-match=kvm | ||
- name: Run instrumented tests | ||
uses: ReactiveCircus/android-emulator-runner@v2 | ||
with: | ||
api-level: ${{ matrix.api-level }} | ||
arch: x86_64 | ||
script: ./gradlew connectedCheck | ||
- name: SpotBugs | ||
run: ./gradlew spotbugsRelease | ||
- name: Archive test results | ||
if: always() | ||
uses: actions/[email protected] | ||
with: | ||
name: test-results | ||
name: test-results-api${{ matrix.api-level }} | ||
path: app/build/reports |
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
67 changes: 67 additions & 0 deletions
67
app/src/androidTest/java/protect/card_locker/MainActivitySearchViewTest.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,67 @@ | ||
package protect.card_locker; | ||
|
||
import static androidx.test.espresso.Espresso.onView; | ||
import static androidx.test.espresso.action.ViewActions.click; | ||
import static androidx.test.espresso.action.ViewActions.typeText; | ||
import static androidx.test.espresso.assertion.ViewAssertions.matches; | ||
import static androidx.test.espresso.matcher.ViewMatchers.isDisplayed; | ||
import static androidx.test.espresso.matcher.ViewMatchers.withChild; | ||
import static androidx.test.espresso.matcher.ViewMatchers.withId; | ||
import static androidx.test.espresso.matcher.ViewMatchers.withText; | ||
import static org.hamcrest.Matchers.is; | ||
import static org.hamcrest.Matchers.not; | ||
import static org.junit.Assert.assertEquals; | ||
|
||
import androidx.appcompat.widget.Toolbar; | ||
import androidx.test.core.app.ActivityScenario; | ||
import androidx.test.ext.junit.runners.AndroidJUnit4; | ||
import androidx.test.platform.app.InstrumentationRegistry; | ||
import androidx.test.uiautomator.UiDevice; | ||
|
||
import org.junit.Test; | ||
import org.junit.runner.RunWith; | ||
|
||
@RunWith(AndroidJUnit4.class) | ||
public class MainActivitySearchViewTest { | ||
|
||
@Test | ||
public void whenSearchViewIsExpandedAndBackIsPressedThenMenuItemShouldNotBeCollapsed() { | ||
String query = "random arbitrary text"; | ||
try (ActivityScenario<MainActivity> mainActivityScenario = ActivityScenario.launch(MainActivity.class)) { | ||
mainActivityScenario.onActivity(this::makeSearchMenuItemVisible); | ||
onView(withId(R.id.action_search)).perform(click()); | ||
onView(withId(androidx.appcompat.R.id.search_src_text)).perform(typeText(query)); | ||
|
||
pressBack(); | ||
|
||
onView(withId(androidx.appcompat.R.id.search_src_text)).check(matches(withText(query))); | ||
mainActivityScenario.onActivity(activity -> assertEquals(query, activity.mFilter)); | ||
} | ||
} | ||
|
||
@Test | ||
public void whenSearchViewIsExpandedThenItShouldOnlyBeCollapsedWhenBackIsPressedTwice() { | ||
try (ActivityScenario<MainActivity> mainActivityScenario = ActivityScenario.launch(MainActivity.class)) { | ||
mainActivityScenario.onActivity(this::makeSearchMenuItemVisible); | ||
onView(withId(R.id.action_search)).perform(click()); | ||
|
||
pressBack(); | ||
|
||
onView(withId(androidx.appcompat.R.id.search_src_text)).check(matches(isDisplayed())); | ||
|
||
pressBack(); | ||
|
||
onView(withId(android.R.id.content)).check(matches(is(not(withChild(withId(androidx.appcompat.R.id.search_src_text)))))); | ||
} | ||
} | ||
|
||
private void makeSearchMenuItemVisible(MainActivity activity) { | ||
Toolbar toolbar = activity.findViewById(R.id.toolbar); | ||
toolbar.getMenu().findItem(R.id.action_search).setVisible(true); | ||
} | ||
|
||
private void pressBack() { | ||
UiDevice.getInstance(InstrumentationRegistry.getInstrumentation()).pressBack(); | ||
} | ||
|
||
} |
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