Skip to content

Introduce rendering matching espresso rule #741

@rjrjr

Description

@rjrjr

Find a home for this. Ideally the same place that we share whatever idling resource cleverness that we've been hoarding.

/**
 * Base class for matchers that examine the workflow [Screen] [shown][View.getScreen]
 * by a [View].
 */
abstract class WorkflowScreenMatcher : TypeSafeMatcher<View>() {

  final override fun matchesSafely(item: View): Boolean {
    return item.getScreen()?.let { matchesScreen(it) } == true
  }

  protected abstract fun matchesScreen(rendering: Screen): Boolean
}
/**
 * Matches [View]s showing workflow [Screen]s that have [compatibility keys][Compatible.keyFor]
 * that include [string].
 */
fun withScreenWithKeyContaining(string: String): Matcher<View> {
  return withScreenWithKey(containsString(string))
}

/**
 * Matches [View]s showing workflow [Screen]s that have [compatibility keys][Compatible.keyFor]
 * that match [stringMatcher].
 */
fun withScreenWithKey(stringMatcher: Matcher<String>): Matcher<View> {
  return WorkflowScreenWithKeyMatcher(stringMatcher)
}

private class WorkflowScreenWithKeyMatcher(
  private val stringMatcher: Matcher<String>
) : WorkflowScreenMatcher() {
  override fun describeTo(description: Description) {
    description.appendText("with Screen with compatibility key: ")
    stringMatcher.describeTo(description)
  }

  override fun matchesScreen(rendering: Screen): Boolean {
    return stringMatcher.matches(Compatible.keyFor(rendering))
  }
}

Metadata

Metadata

Assignees

No one assigned

    Labels

    uiRelated to UI integration

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions