Skip to content

Commit

Permalink
With text barista (#388)
Browse files Browse the repository at this point in the history
* Create withCompatText

* Move all withText(String) to withCompatText(String)

* Add tests

* Use custom matchers, no need to creater one

* Fix  tests

* Fix test
  • Loading branch information
alorma authored Jul 5, 2021
1 parent 1b61a36 commit dcc9469
Show file tree
Hide file tree
Showing 78 changed files with 252 additions and 177 deletions.
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
package com.adevinta.android.barista.assertion

import android.view.View
import androidx.test.espresso.Espresso.onView
import androidx.test.espresso.NoActivityResumedException
import androidx.test.espresso.action.ViewActions
import androidx.test.espresso.matcher.ViewMatchers
import androidx.test.espresso.matcher.ViewMatchers.isRoot
import android.view.View
import com.adevinta.android.barista.internal.assertAnyView
import com.adevinta.android.barista.internal.failurehandler.RethrowingFailureHandler
import com.adevinta.android.barista.internal.matcher.BooleanMatcher
import com.adevinta.android.barista.internal.matcher.withCompatText
import com.adevinta.android.barista.internal.util.resourceMatcher
import org.hamcrest.Matcher
import org.junit.Assert.fail
Expand Down Expand Up @@ -42,7 +42,7 @@ object BaristaAssertions {
*/
@JvmStatic
inline fun <reified T : View> assertAny(text: String, assertionDescription: String? = null, noinline block: (T) -> Boolean) {
assertAny(ViewMatchers.withText(text), assertionDescription, block)
assertAny(withCompatText(text), assertionDescription, block)
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@ import androidx.annotation.IdRes
import androidx.annotation.StringRes
import androidx.test.espresso.matcher.ViewMatchers
import androidx.test.platform.app.InstrumentationRegistry
import com.google.android.material.textfield.TextInputLayout
import com.adevinta.android.barista.internal.assertAny
import com.google.android.material.textfield.TextInputLayout
import org.hamcrest.Description
import org.hamcrest.Matcher
import org.hamcrest.TypeSafeMatcher
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
package com.adevinta.android.barista.assertion

import androidx.test.espresso.matcher.ViewMatchers.isChecked
import androidx.test.espresso.matcher.ViewMatchers.withText
import com.adevinta.android.barista.internal.assertAny
import com.adevinta.android.barista.internal.matcher.withCompatText
import com.adevinta.android.barista.internal.util.resourceMatcher
import org.hamcrest.Matchers.not

Expand All @@ -15,7 +15,7 @@ object BaristaCheckedAssertions {

@JvmStatic
fun assertChecked(text: String) {
withText(text).assertAny(isChecked())
withCompatText(text).assertAny(isChecked())
}

@JvmStatic
Expand All @@ -25,6 +25,6 @@ object BaristaCheckedAssertions {

@JvmStatic
fun assertUnchecked(text: String) {
withText(text).assertAny(not(isChecked()))
withCompatText(text).assertAny(not(isChecked()))
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@ package com.adevinta.android.barista.assertion

import android.view.View
import androidx.annotation.IdRes
import com.google.android.material.chip.ChipGroup
import com.adevinta.android.barista.assertion.BaristaAssertions.assertAny
import com.google.android.material.chip.ChipGroup

object BaristaChipAssertions {

Expand Down
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
package com.adevinta.android.barista.assertion

import androidx.test.espresso.matcher.ViewMatchers.isClickable
import androidx.test.espresso.matcher.ViewMatchers.withText
import com.adevinta.android.barista.internal.assertAny
import com.adevinta.android.barista.internal.util.resourceMatcher
import com.adevinta.android.barista.internal.matcher.withCompatText
import org.hamcrest.Matchers.not

object BaristaClickableAssertions {
Expand All @@ -15,7 +15,7 @@ object BaristaClickableAssertions {

@JvmStatic
fun assertClickable(text: String) {
withText(text).assertAny(isClickable())
withCompatText(text).assertAny(isClickable())
}

@JvmStatic
Expand All @@ -25,6 +25,6 @@ object BaristaClickableAssertions {

@JvmStatic
fun assertNotClickable(text: String) {
withText(text).assertAny(not(isClickable()))
withCompatText(text).assertAny(not(isClickable()))
}
}
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
package com.adevinta.android.barista.assertion

import androidx.annotation.IdRes
import androidx.core.view.GravityCompat
import androidx.drawerlayout.widget.DrawerLayout
import androidx.test.espresso.Espresso.onView
import androidx.test.espresso.assertion.ViewAssertions.matches
import androidx.test.espresso.contrib.DrawerMatchers.isClosed
import androidx.test.espresso.contrib.DrawerMatchers.isOpen
import androidx.test.espresso.matcher.ViewMatchers
import androidx.core.view.GravityCompat
import androidx.drawerlayout.widget.DrawerLayout

object BaristaDrawerAssertions {

Expand Down
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
package com.adevinta.android.barista.assertion

import androidx.test.espresso.matcher.ViewMatchers.isEnabled
import androidx.test.espresso.matcher.ViewMatchers.withText
import com.adevinta.android.barista.internal.assertAny
import com.adevinta.android.barista.internal.util.resourceMatcher
import com.adevinta.android.barista.internal.matcher.withCompatText
import org.hamcrest.Matchers.not

object BaristaEnabledAssertions {
Expand All @@ -15,7 +15,7 @@ object BaristaEnabledAssertions {

@JvmStatic
fun assertEnabled(text: String) {
withText(text).assertAny(isEnabled())
withCompatText(text).assertAny(isEnabled())
}

@JvmStatic
Expand All @@ -25,6 +25,6 @@ object BaristaEnabledAssertions {

@JvmStatic
fun assertDisabled(text: String) {
withText(text).assertAny(not(isEnabled()))
withCompatText(text).assertAny(not(isEnabled()))
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,8 @@ import androidx.annotation.IdRes
import androidx.annotation.StringRes
import androidx.test.core.app.ApplicationProvider
import androidx.test.espresso.matcher.ViewMatchers
import com.google.android.material.textfield.TextInputLayout
import com.adevinta.android.barista.internal.assertAny
import com.google.android.material.textfield.TextInputLayout
import org.hamcrest.Description
import org.hamcrest.Matcher
import org.hamcrest.TypeSafeMatcher
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,9 @@ package com.adevinta.android.barista.assertion

import androidx.annotation.IdRes
import androidx.test.espresso.matcher.ViewMatchers.hasFocus
import androidx.test.espresso.matcher.ViewMatchers.withText
import com.adevinta.android.barista.internal.assertAny
import com.adevinta.android.barista.internal.util.resourceMatcher
import com.adevinta.android.barista.internal.matcher.withCompatText
import org.hamcrest.Matchers.not

object BaristaFocusedAssertions {
Expand All @@ -21,11 +21,11 @@ object BaristaFocusedAssertions {

@JvmStatic
fun assertFocused(text: String) {
withText(text).assertAny(hasFocus())
withCompatText(text).assertAny(hasFocus())
}

@JvmStatic
fun assertNotFocused(text: String) {
withText(text).assertAny(not(hasFocus()))
withCompatText(text).assertAny(not(hasFocus()))
}
}
Original file line number Diff line number Diff line change
@@ -1,16 +1,16 @@
package com.adevinta.android.barista.assertion

import android.content.Context
import androidx.annotation.IdRes
import androidx.annotation.StringRes
import com.google.android.material.textfield.TextInputEditText
import com.google.android.material.textfield.TextInputLayout
import androidx.test.espresso.matcher.ViewMatchers.withId
import android.view.View
import android.widget.EditText
import android.widget.FrameLayout
import androidx.annotation.IdRes
import androidx.annotation.StringRes
import androidx.test.core.app.ApplicationProvider
import androidx.test.espresso.matcher.ViewMatchers.withId
import com.adevinta.android.barista.internal.assertAny
import com.google.android.material.textfield.TextInputEditText
import com.google.android.material.textfield.TextInputLayout
import org.hamcrest.Description
import org.hamcrest.Matcher
import org.hamcrest.TypeSafeMatcher
Expand Down
Original file line number Diff line number Diff line change
@@ -1,25 +1,26 @@
package com.adevinta.android.barista.assertion

import android.view.View
import android.widget.ListView
import androidx.annotation.DrawableRes
import androidx.annotation.IdRes
import androidx.annotation.StringRes
import androidx.recyclerview.widget.RecyclerView
import androidx.test.espresso.Espresso
import androidx.test.espresso.NoMatchingViewException
import androidx.test.espresso.ViewAssertion
import androidx.test.espresso.assertion.ViewAssertions
import androidx.test.espresso.matcher.ViewMatchers
import androidx.recyclerview.widget.RecyclerView
import android.view.View
import android.widget.ListView
import androidx.annotation.DrawableRes
import com.adevinta.android.barista.interaction.BaristaListInteractions.findListViewMatcher
import com.adevinta.android.barista.interaction.BaristaListInteractions.findRecyclerMatcher
import com.adevinta.android.barista.interaction.BaristaListInteractions.scrollListToPosition
import com.adevinta.android.barista.internal.failurehandler.SpyFailureHandler
import com.adevinta.android.barista.internal.matcher.ListViewNotEmptyAssertion
import com.adevinta.android.barista.internal.matcher.DrawableMatcher
import com.adevinta.android.barista.internal.matcher.ListViewItemCountAssertion
import com.adevinta.android.barista.internal.matcher.RecyclerViewNotEmptyAssertion
import com.adevinta.android.barista.internal.matcher.ListViewNotEmptyAssertion
import com.adevinta.android.barista.internal.matcher.RecyclerViewItemCountAssertion
import com.adevinta.android.barista.internal.matcher.DrawableMatcher
import com.adevinta.android.barista.internal.matcher.RecyclerViewNotEmptyAssertion
import com.adevinta.android.barista.internal.matcher.withCompatText
import org.hamcrest.CoreMatchers
import org.hamcrest.Description
import org.hamcrest.Matcher
Expand Down Expand Up @@ -81,8 +82,8 @@ object BaristaListAssertions {
targetViewId = targetViewId,
viewAssertion = ViewAssertions.matches(
CoreMatchers.anyOf(
ViewMatchers.withChild(ViewMatchers.withText(text)),
ViewMatchers.withText(text)
ViewMatchers.withChild(withCompatText(text)),
withCompatText(text)
)
)
)
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
package com.adevinta.android.barista.assertion

import android.view.View
import androidx.annotation.AttrRes
import androidx.annotation.IdRes
import androidx.annotation.StringRes
import androidx.annotation.StyleRes
Expand All @@ -16,6 +15,7 @@ import com.adevinta.android.barista.internal.assertAny
import com.adevinta.android.barista.internal.matcher.TextColorMatcher
import com.adevinta.android.barista.internal.matcher.TextStyleableColorMatcher
import com.adevinta.android.barista.internal.util.resourceMatcher
import com.adevinta.android.barista.internal.matcher.withCompatText
import org.hamcrest.CoreMatchers.containsString
import org.hamcrest.Matcher
import org.hamcrest.Matchers.allOf
Expand All @@ -35,12 +35,12 @@ object BaristaVisibilityAssertions {

@JvmStatic
fun assertDisplayed(text: String) {
withText(text).assertAny(isDisplayed())
withCompatText(text).assertAny(isDisplayed())
}

@JvmStatic
fun assertDisplayed(@IdRes viewId: Int, text: String) {
viewId.resourceMatcher().assertAny(allOf(isDisplayed(), withText(text)))
viewId.resourceMatcher().assertAny(allOf(isDisplayed(), withCompatText(text)))
}

@JvmStatic
Expand All @@ -55,7 +55,7 @@ object BaristaVisibilityAssertions {

@JvmStatic
fun assertNotExist(text: String) {
onView(withText(text)).check(doesNotExist())
onView(withCompatText(text)).check(doesNotExist())
}

@JvmStatic
Expand All @@ -65,7 +65,7 @@ object BaristaVisibilityAssertions {

@JvmStatic
fun assertNotDisplayed(text: String) {
withText(text).assertAny(not(isDisplayed()))
withCompatText(text).assertAny(not(isDisplayed()))
}

@JvmStatic
Expand All @@ -75,7 +75,7 @@ object BaristaVisibilityAssertions {

@JvmStatic
fun assertNotDisplayed(@IdRes viewId: Int, text: String) {
viewId.resourceMatcher().assertAny(not(allOf(isDisplayed(), withText(text))))
viewId.resourceMatcher().assertAny(not(allOf(isDisplayed(), withCompatText(text))))
}

@JvmStatic
Expand All @@ -85,7 +85,7 @@ object BaristaVisibilityAssertions {

@JvmStatic
fun assertContains(text: String) {
withText(containsString(text)).assertAny(isDisplayed())
withCompatText(containsString(text)).assertAny(isDisplayed())
}

@JvmStatic
Expand All @@ -96,7 +96,7 @@ object BaristaVisibilityAssertions {

@JvmStatic
fun assertContains(@IdRes viewId: Int, text: String) {
viewId.resourceMatcher().assertAny(withText(containsString(text)))
viewId.resourceMatcher().assertAny(withCompatText(containsString(text)))
}

@JvmStatic
Expand All @@ -107,7 +107,7 @@ object BaristaVisibilityAssertions {

@JvmStatic
fun assertNotContains(text: String) {
onView(withText(containsString(text))).check(doesNotExist())
onView(withCompatText(containsString(text))).check(doesNotExist())
}

@JvmStatic
Expand All @@ -118,7 +118,7 @@ object BaristaVisibilityAssertions {

@JvmStatic
fun assertNotContains(@IdRes resId: Int, text: String) {
onView(allOf(withId(resId), withText(containsString(text)))).check(doesNotExist())
onView(allOf(withId(resId), withCompatText(containsString(text)))).check(doesNotExist())
}

@JvmStatic
Expand Down
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
package com.adevinta.android.barista.interaction

import android.widget.EditText
import androidx.annotation.IdRes
import androidx.test.espresso.matcher.ViewMatchers.isAssignableFrom
import androidx.test.espresso.matcher.ViewMatchers.isDescendantOfA
import androidx.test.espresso.matcher.ViewMatchers.withId
import android.widget.EditText
import com.adevinta.android.barista.internal.performAction
import com.adevinta.android.barista.internal.viewaction.AutoCompleteViewActions.replaceAutoComplete
import org.hamcrest.Matchers.allOf
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,9 @@ package com.adevinta.android.barista.interaction
import androidx.test.espresso.Espresso.pressBack
import androidx.test.espresso.action.ViewActions.click
import androidx.test.espresso.action.ViewActions.longClick
import androidx.test.espresso.matcher.ViewMatchers.withText
import com.adevinta.android.barista.internal.performAction
import com.adevinta.android.barista.internal.util.resourceMatcher
import com.adevinta.android.barista.internal.matcher.withCompatText

object BaristaClickInteractions {

Expand All @@ -21,7 +21,7 @@ object BaristaClickInteractions {

@JvmStatic
fun clickOn(text: String) {
withText(text).performAction(click())
withCompatText(text).performAction(click())
}

@JvmStatic
Expand All @@ -31,6 +31,6 @@ object BaristaClickInteractions {

@JvmStatic
fun longClickOn(text: String) {
withText(text).performAction(longClick())
withCompatText(text).performAction(longClick())
}
}
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
package com.adevinta.android.barista.interaction

import androidx.annotation.IdRes
import androidx.core.view.GravityCompat
import androidx.drawerlayout.widget.DrawerLayout
import androidx.test.espresso.contrib.DrawerActions.close
import androidx.test.espresso.contrib.DrawerActions.open
import androidx.test.espresso.matcher.ViewMatchers.isAssignableFrom
import androidx.test.espresso.matcher.ViewMatchers.withId
import androidx.core.view.GravityCompat
import androidx.drawerlayout.widget.DrawerLayout
import com.adevinta.android.barista.internal.performAction

object BaristaDrawerInteractions {
Expand Down
Loading

0 comments on commit dcc9469

Please sign in to comment.