Skip to content
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.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -1,32 +1,29 @@
package com.squareup.sample.poetryapp

import androidx.test.espresso.Espresso.onView
import androidx.test.espresso.assertion.ViewAssertions.matches
import androidx.test.espresso.matcher.ViewMatchers.isDisplayed
import androidx.test.espresso.matcher.ViewMatchers.withText
import androidx.test.ext.junit.rules.ActivityScenarioRule
import androidx.test.ext.junit.runners.AndroidJUnit4
import com.squareup.sample.container.poetryapp.R
import com.squareup.workflow1.ui.WorkflowUiExperimentalApi
import com.squareup.workflow1.ui.internal.test.IdlingDispatcherRule
import com.squareup.workflow1.ui.internal.test.inAnyView
import leakcanary.DetectLeaksAfterTestSuccess
import org.junit.Rule
import org.junit.Test
import org.junit.rules.RuleChain
import org.junit.runner.RunWith

@RunWith(AndroidJUnit4::class)
@OptIn(WorkflowUiExperimentalApi::class)
class PoetryAppTest {

private val scenarioRule = ActivityScenarioRule(PoetryActivity::class.java)

@get:Rule val rules = RuleChain.outerRule(DetectLeaksAfterTestSuccess())
@get:Rule val rules: RuleChain = RuleChain.outerRule(DetectLeaksAfterTestSuccess())
.around(scenarioRule)
.around(IdlingDispatcherRule)

@Test fun launches() {
inAnyView(withText(R.string.poems))
.check(matches(isDisplayed()))
onView(withText(R.string.poems)).check(matches(isDisplayed()))
}
}
Original file line number Diff line number Diff line change
@@ -1,31 +1,29 @@
package com.squareup.sample.ravenapp

import androidx.test.espresso.Espresso.onView
import androidx.test.espresso.assertion.ViewAssertions.matches
import androidx.test.espresso.matcher.ViewMatchers.isDisplayed
import androidx.test.espresso.matcher.ViewMatchers.withText
import androidx.test.ext.junit.rules.ActivityScenarioRule
import androidx.test.ext.junit.runners.AndroidJUnit4
import com.squareup.workflow1.ui.WorkflowUiExperimentalApi
import com.squareup.workflow1.ui.internal.test.IdlingDispatcherRule
import com.squareup.workflow1.ui.internal.test.inAnyView
import leakcanary.DetectLeaksAfterTestSuccess
import org.junit.Rule
import org.junit.Test
import org.junit.rules.RuleChain
import org.junit.runner.RunWith

@RunWith(AndroidJUnit4::class)
@OptIn(WorkflowUiExperimentalApi::class)
class RavenAppTest {

private val scenarioRule = ActivityScenarioRule(RavenActivity::class.java)

@get:Rule val rules = RuleChain.outerRule(DetectLeaksAfterTestSuccess())
@get:Rule val rules: RuleChain = RuleChain.outerRule(DetectLeaksAfterTestSuccess())
.around(scenarioRule)
.around(IdlingDispatcherRule)

@Test fun launches() {
inAnyView(withText("The Raven"))
onView(withText("The Raven"))
.check(matches(isDisplayed()))
}
}
Original file line number Diff line number Diff line change
@@ -1,17 +1,17 @@
package com.squareup.sample.hellobackbutton

import androidx.test.espresso.Espresso.onView
import androidx.test.espresso.action.ViewActions.click
import androidx.test.espresso.action.ViewActions.pressBack
import androidx.test.espresso.assertion.ViewAssertions.matches
import androidx.test.espresso.matcher.RootMatchers.isDialog
import androidx.test.espresso.matcher.ViewMatchers.isDisplayed
import androidx.test.espresso.matcher.ViewMatchers.withId
import androidx.test.espresso.matcher.ViewMatchers.withText
import androidx.test.ext.junit.rules.ActivityScenarioRule
import androidx.test.ext.junit.runners.AndroidJUnit4
import com.squareup.workflow1.ui.WorkflowUiExperimentalApi
import com.squareup.workflow1.ui.internal.test.IdlingDispatcherRule
import com.squareup.workflow1.ui.internal.test.actuallyPressBack
import com.squareup.workflow1.ui.internal.test.inAnyView
import com.squareup.workflow1.ui.internal.test.retryBlocking
import leakcanary.DetectLeaksAfterTestSuccess
import org.junit.Rule
import org.junit.Test
Expand All @@ -24,29 +24,32 @@ class HelloBackButtonEspressoTest {

private val scenarioRule = ActivityScenarioRule(HelloBackButtonActivity::class.java)

@get:Rule val rules = RuleChain.outerRule(DetectLeaksAfterTestSuccess())
@get:Rule val rules: RuleChain = RuleChain.outerRule(DetectLeaksAfterTestSuccess())
.around(scenarioRule)
.around(IdlingDispatcherRule)

@Test fun wrappedTakesPrecedence() = retryBlocking {
inAnyView(withId(R.id.hello_message)).apply {
@Test fun wrappedTakesPrecedence() {
onView(withId(R.id.hello_message)).apply {
check(matches(withText("Able")))
perform(click())
check(matches(withText("Baker")))
perform(click())
check(matches(withText("Charlie")))
actuallyPressBack()
perform(pressBack())
check(matches(withText("Baker")))
actuallyPressBack()
perform(pressBack())
check(matches(withText("Able")))
}
}

@Test fun outerHandlerAppliesIfWrappedHandlerIsNull() = retryBlocking {
inAnyView(withId(R.id.hello_message)).apply {
actuallyPressBack()
inAnyView(withText("Are you sure you want to do this thing?"))
.check(matches(isDisplayed()))
@Test fun outerHandlerAppliesIfWrappedHandlerIsNull() {
onView(withId(R.id.hello_message)).apply {
check(matches(isDisplayed()))
perform(pressBack())
}

onView(withText("Are you sure you want to do this thing?"))
.inRoot(isDialog())
.check(matches(isDisplayed()))
}
}
Original file line number Diff line number Diff line change
@@ -1,31 +1,29 @@
package com.squareup.sample.dungeon

import androidx.test.espresso.Espresso.onView
import androidx.test.espresso.assertion.ViewAssertions.matches
import androidx.test.espresso.matcher.ViewMatchers.isDisplayed
import androidx.test.espresso.matcher.ViewMatchers.withText
import androidx.test.ext.junit.rules.ActivityScenarioRule
import androidx.test.ext.junit.runners.AndroidJUnit4
import com.squareup.workflow1.ui.WorkflowUiExperimentalApi
import com.squareup.workflow1.ui.internal.test.IdlingDispatcherRule
import com.squareup.workflow1.ui.internal.test.inAnyView
import leakcanary.DetectLeaksAfterTestSuccess
import org.junit.Rule
import org.junit.Test
import org.junit.rules.RuleChain
import org.junit.runner.RunWith

@RunWith(AndroidJUnit4::class)
@OptIn(WorkflowUiExperimentalApi::class)
class DungeonAppTest {

private val scenarioRule = ActivityScenarioRule(DungeonActivity::class.java)

@get:Rule val rules = RuleChain.outerRule(DetectLeaksAfterTestSuccess())
@get:Rule val rules: RuleChain = RuleChain.outerRule(DetectLeaksAfterTestSuccess())
.around(scenarioRule)
.around(IdlingDispatcherRule)

@Test fun loadsBoardsList() {
inAnyView(withText(R.string.boards_list_label))
onView(withText(R.string.boards_list_label))
.check(matches(isDisplayed()))
}
}
Original file line number Diff line number Diff line change
@@ -1,14 +1,13 @@
package com.squareup.sample.helloworkflowfragment

import androidx.test.espresso.Espresso.onView
import androidx.test.espresso.action.ViewActions.click
import androidx.test.espresso.assertion.ViewAssertions.matches
import androidx.test.espresso.matcher.ViewMatchers.isDisplayed
import androidx.test.espresso.matcher.ViewMatchers.withText
import androidx.test.ext.junit.rules.ActivityScenarioRule
import androidx.test.ext.junit.runners.AndroidJUnit4
import com.squareup.workflow1.ui.WorkflowUiExperimentalApi
import com.squareup.workflow1.ui.internal.test.IdlingDispatcherRule
import com.squareup.workflow1.ui.internal.test.inAnyView
import leakcanary.DetectLeaksAfterTestSuccess
import org.hamcrest.Matchers.containsString
import org.junit.Rule
Expand All @@ -17,25 +16,24 @@ import org.junit.rules.RuleChain
import org.junit.runner.RunWith

@RunWith(AndroidJUnit4::class)
@OptIn(WorkflowUiExperimentalApi::class)
class HelloWorkflowFragmentAppTest {

private val scenarioRule = ActivityScenarioRule(HelloWorkflowFragmentActivity::class.java)

@get:Rule val rules = RuleChain.outerRule(DetectLeaksAfterTestSuccess())
@get:Rule val rules: RuleChain = RuleChain.outerRule(DetectLeaksAfterTestSuccess())
.around(scenarioRule)
.around(IdlingDispatcherRule)

@Test fun togglesHelloAndGoodbye() {
inAnyView(withText(containsString("Hello")))
onView(withText(containsString("Hello")))
.check(matches(isDisplayed()))
.perform(click())

inAnyView(withText(containsString("Goodbye")))
onView(withText(containsString("Goodbye")))
.check(matches(isDisplayed()))
.perform(click())

inAnyView(withText(containsString("Hello")))
onView(withText(containsString("Hello")))
.check(matches(isDisplayed()))
}
}
Original file line number Diff line number Diff line change
@@ -1,40 +1,38 @@
package com.squareup.sample.helloworkflow

import androidx.test.espresso.Espresso.onView
import androidx.test.espresso.action.ViewActions.click
import androidx.test.espresso.assertion.ViewAssertions.matches
import androidx.test.espresso.matcher.ViewMatchers.isDisplayed
import androidx.test.espresso.matcher.ViewMatchers.withText
import androidx.test.ext.junit.rules.ActivityScenarioRule
import androidx.test.ext.junit.runners.AndroidJUnit4
import com.squareup.workflow1.ui.WorkflowUiExperimentalApi
import com.squareup.workflow1.ui.internal.test.IdlingDispatcherRule
import com.squareup.workflow1.ui.internal.test.inAnyView
import leakcanary.DetectLeaksAfterTestSuccess
import org.junit.Rule
import org.junit.Test
import org.junit.rules.RuleChain
import org.junit.runner.RunWith

@RunWith(AndroidJUnit4::class)
@OptIn(WorkflowUiExperimentalApi::class)
class HelloWorkflowAppTest {

private val scenarioRule = ActivityScenarioRule(HelloWorkflowActivity::class.java)

@get:Rule val rules = RuleChain.outerRule(DetectLeaksAfterTestSuccess())
@get:Rule val rules: RuleChain = RuleChain.outerRule(DetectLeaksAfterTestSuccess())
.around(scenarioRule)
.around(IdlingDispatcherRule)

@Test fun togglesHelloAndGoodbye() {
inAnyView(withText("Hello"))
onView(withText("Hello"))
.check(matches(isDisplayed()))
.perform(click())

inAnyView(withText("Goodbye"))
onView(withText("Goodbye"))
.check(matches(isDisplayed()))
.perform(click())

inAnyView(withText("Hello"))
onView(withText("Hello"))
.check(matches(isDisplayed()))
}
}
25 changes: 25 additions & 0 deletions samples/nested-overlays/build.gradle.kts
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
plugins {
id("com.android.application")
`kotlin-android`
`android-sample-app`
`android-ui-tests`
}

android {
defaultConfig {
applicationId = "com.squareup.sample.nestedoverlays"
}
namespace = "com.squareup.sample.nestedoverlays"
}

dependencies {
debugImplementation(libs.squareup.leakcanary.android)

implementation(libs.androidx.activity.ktx)
implementation(libs.androidx.lifecycle.viewmodel.ktx)
implementation(libs.androidx.lifecycle.viewmodel.savedstate)
implementation(libs.androidx.viewbinding)

implementation(project(":workflow-ui:core-android"))
implementation(project(":workflow-ui:core-common"))
}
4 changes: 4 additions & 0 deletions samples/nested-overlays/lint-baseline.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
<?xml version="1.0" encoding="UTF-8"?>
<issues format="6" by="lint 7.4.1" type="baseline" client="gradle" dependencies="false" name="AGP (7.4.1)" variant="fatal" version="7.4.1">

</issues>
Original file line number Diff line number Diff line change
@@ -0,0 +1,99 @@
package com.squareup.sample.nestedoverlays

import androidx.test.espresso.Espresso.onView
import androidx.test.espresso.ViewInteraction
import androidx.test.espresso.action.ViewActions.click
import androidx.test.espresso.assertion.ViewAssertions.doesNotExist
import androidx.test.espresso.assertion.ViewAssertions.matches
import androidx.test.espresso.matcher.ViewMatchers.isDisplayed
import androidx.test.espresso.matcher.ViewMatchers.withParent
import androidx.test.espresso.matcher.ViewMatchers.withParentIndex
import androidx.test.espresso.matcher.ViewMatchers.withText
import androidx.test.ext.junit.rules.ActivityScenarioRule
import androidx.test.ext.junit.runners.AndroidJUnit4
import com.squareup.workflow1.ui.internal.test.IdlingDispatcherRule
import leakcanary.DetectLeaksAfterTestSuccess
import org.hamcrest.core.AllOf.allOf
import org.hamcrest.core.IsNot.not
import org.junit.Rule
import org.junit.Test
import org.junit.rules.RuleChain
import org.junit.runner.RunWith

@RunWith(AndroidJUnit4::class)
class NestedOverlaysAppTest {

private val scenarioRule = ActivityScenarioRule(NestedOverlaysActivity::class.java)

@get:Rule val rules: RuleChain = RuleChain.outerRule(DetectLeaksAfterTestSuccess())
.around(scenarioRule)
.around(IdlingDispatcherRule)

@Test fun basics() {
onTopCoverBody().assertDisplayed()
onTopCoverEverything().assertDisplayed()
onBottomCoverBody().assertDisplayed()
onBottomCoverEverything().assertDisplayed()

onTopCoverBody().perform(click())
onView(withText("Close")).perform(click())
onTopCoverEverything().perform(click())
onView(withText("Close")).perform(click())

onView(withText("Hide Top Bar")).perform(click())
onTopCoverBody().assertNotDisplayed()
onTopCoverEverything().assertNotDisplayed()
onBottomCoverBody().assertDisplayed()
onBottomCoverEverything().assertDisplayed()

onView(withText("Hide Bottom Bar")).perform(click())
onTopCoverBody().assertNotDisplayed()
onTopCoverEverything().assertNotDisplayed()
onBottomCoverBody().assertNotDisplayed()
onBottomCoverEverything().assertNotDisplayed()
}

// https://github.com/square/workflow-kotlin/issues/966
@Test fun canInsertDialog() {
onTopCoverEverything().perform(click())
onView(withText("Hide Top Bar")).check(doesNotExist())
onView(withText("Cover Body")).perform(click())

// This line fails due to https://github.com/square/workflow-kotlin/issues/966
// onView(withText("Hide Top Bar")).check(doesNotExist())

// Should continue to close the top sheet and assert that the inner sheet is visible.
}

// So far can't express this in Espresso. Considering move to Maestro
// @Test fun canClickPastInnerWindow() {
// onView(allOf(withText("Cover Everything"), withParent(withParentIndex(0))))
// .perform(click())
//
// scenario.onActivity { activity ->
// onView(allOf(withText("Cover Everything"), withParent(withParentIndex(0))))
// .inRoot(withDecorView(not(`is`(activity.window.decorView))))
// .perform(click())
// }
// }

private fun ViewInteraction.assertNotDisplayed() {
check(matches(not(isDisplayed())))
}

private fun ViewInteraction.assertDisplayed() {
check(matches(isDisplayed()))
}

private fun onBottomCoverEverything() =
onView(allOf(withText("Cover Everything"), withParent(withParentIndex(2))))

private fun onBottomCoverBody() =
onView(allOf(withText("Cover Body"), withParent(withParentIndex(2))))

private fun onTopCoverBody() =
onView(allOf(withText("Cover Body"), withParent(withParentIndex(0))))

private fun onTopCoverEverything() =
onView(allOf(withText("Cover Everything"), withParent(withParentIndex(0))))
}
Loading