mirror of
https://github.com/anyproto/anytype-kotlin.git
synced 2025-06-08 05:47:05 +09:00
Editor | Enhancement | Nested decorations for text list blocks (#2373)
This commit is contained in:
parent
62f96685be
commit
cfb9c1a95f
14 changed files with 773 additions and 52 deletions
|
@ -16,8 +16,11 @@ import androidx.test.espresso.matcher.ViewMatchers.withInputType
|
|||
import com.anytypeio.anytype.test_utils.utils.TestUtils.withRecyclerView
|
||||
import com.anytypeio.anytype.test_utils.utils.espresso.HasChildViewWithText
|
||||
import com.anytypeio.anytype.test_utils.utils.espresso.HasViewGroupChildViewWithText
|
||||
import com.anytypeio.anytype.test_utils.utils.espresso.HasViewGroupChildWithBackground
|
||||
import com.anytypeio.anytype.test_utils.utils.espresso.HasViewGroupChildWithMarginLeft
|
||||
import com.anytypeio.anytype.test_utils.utils.espresso.WithBackgroundColor
|
||||
import com.anytypeio.anytype.test_utils.utils.espresso.WithChildViewCount
|
||||
import com.anytypeio.anytype.test_utils.utils.espresso.WithMarginStart
|
||||
import com.anytypeio.anytype.test_utils.utils.espresso.WithTextColor
|
||||
import com.anytypeio.anytype.test_utils.utils.espresso.WithoutBackgroundColor
|
||||
import org.hamcrest.Matchers.not
|
||||
|
@ -83,6 +86,16 @@ fun ViewInteraction.checkHasNoBackground() {
|
|||
check(matches(WithoutBackgroundColor()))
|
||||
}
|
||||
|
||||
fun ViewInteraction.checkHasMarginStart(marginStart: Int) {
|
||||
check(
|
||||
matches(
|
||||
WithMarginStart(
|
||||
marginStartExpected = marginStart
|
||||
)
|
||||
)
|
||||
)
|
||||
}
|
||||
|
||||
fun ViewInteraction.checkHasChildViewCount(count: Int) : ViewInteraction {
|
||||
return check(matches(WithChildViewCount(count)))
|
||||
}
|
||||
|
@ -104,6 +117,34 @@ fun ViewInteraction.checkHasChildViewWithText(
|
|||
return check(matches(HasChildViewWithText(pos, text, target)))
|
||||
}
|
||||
|
||||
fun ViewInteraction.checkHasViewGroupChildWithBackground(
|
||||
pos: Int,
|
||||
background: Int
|
||||
) : ViewInteraction {
|
||||
return check(
|
||||
matches(
|
||||
HasViewGroupChildWithBackground(
|
||||
pos = pos,
|
||||
background = background
|
||||
)
|
||||
)
|
||||
)
|
||||
}
|
||||
|
||||
fun ViewInteraction.checkHasViewGroupChildWithMarginLeft(
|
||||
pos: Int,
|
||||
margin: Int
|
||||
) : ViewInteraction {
|
||||
return check(
|
||||
matches(
|
||||
HasViewGroupChildWithMarginLeft(
|
||||
pos = pos,
|
||||
margin = margin
|
||||
)
|
||||
)
|
||||
)
|
||||
}
|
||||
|
||||
fun ViewInteraction.checkHasViewGroupChildWithText(
|
||||
pos: Int,
|
||||
text: String
|
||||
|
|
|
@ -8,6 +8,7 @@ import android.widget.TextView
|
|||
import androidx.annotation.ColorInt
|
||||
import androidx.annotation.ColorRes
|
||||
import androidx.core.content.ContextCompat
|
||||
import androidx.core.view.marginStart
|
||||
import androidx.recyclerview.widget.RecyclerView
|
||||
import androidx.test.espresso.UiController
|
||||
import androidx.test.espresso.ViewAction
|
||||
|
@ -22,8 +23,7 @@ import org.hamcrest.TypeSafeMatcher
|
|||
class WithTextColor(
|
||||
@ColorInt
|
||||
private val expectedColor: Int
|
||||
) :
|
||||
BoundedMatcher<View, TextView>(TextView::class.java) {
|
||||
) : BoundedMatcher<View, TextView>(TextView::class.java) {
|
||||
override fun matchesSafely(item: TextView) = item.currentTextColor == expectedColor
|
||||
override fun describeTo(description: Description) {
|
||||
description.appendText("with text color:")
|
||||
|
@ -64,8 +64,24 @@ class WithChildViewCount(private val expectedCount: Int) :
|
|||
}
|
||||
}
|
||||
|
||||
class HasViewGroupChildViewWithText(private val pos: Int, val text: String) :
|
||||
BoundedMatcher<View, ViewGroup>(ViewGroup::class.java) {
|
||||
class WithMarginStart(
|
||||
private val marginStartExpected: Int
|
||||
) : BoundedMatcher<View, View>(View::class.java) {
|
||||
override fun describeTo(description: Description) {
|
||||
description.appendText("with margin start:")
|
||||
description.appendValue(marginStartExpected)
|
||||
}
|
||||
|
||||
override fun matchesSafely(item: View): Boolean {
|
||||
val actual = item.marginStart
|
||||
return actual == marginStartExpected
|
||||
}
|
||||
}
|
||||
|
||||
class HasViewGroupChildViewWithText(
|
||||
private val pos: Int,
|
||||
val text: String
|
||||
) : BoundedMatcher<View, ViewGroup>(ViewGroup::class.java) {
|
||||
|
||||
private var actual: String? = null
|
||||
|
||||
|
@ -84,6 +100,48 @@ class HasViewGroupChildViewWithText(private val pos: Int, val text: String) :
|
|||
}
|
||||
}
|
||||
|
||||
class HasViewGroupChildWithBackground(
|
||||
private val pos: Int,
|
||||
private val background: Int
|
||||
) : BoundedMatcher<View, ViewGroup>(ViewGroup::class.java) {
|
||||
|
||||
private var actual: Int? = null
|
||||
|
||||
override fun matchesSafely(item: ViewGroup): Boolean {
|
||||
val child = item.getChildAt(pos)
|
||||
checkNotNull(child) { throw IllegalStateException("No view child at position: $pos") }
|
||||
actual = (child.background as ColorDrawable).color
|
||||
return actual == background
|
||||
}
|
||||
|
||||
override fun describeTo(description: Description) {
|
||||
if (actual != null) {
|
||||
description.appendText("Should have background [${background}] at position: $pos but was: [$actual]");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
class HasViewGroupChildWithMarginLeft(
|
||||
private val pos: Int,
|
||||
private val margin: Int
|
||||
) : BoundedMatcher<View, ViewGroup>(ViewGroup::class.java) {
|
||||
|
||||
private var actual: Int? = null
|
||||
|
||||
override fun matchesSafely(item: ViewGroup): Boolean {
|
||||
val child = item.getChildAt(pos)
|
||||
checkNotNull(child) { throw IllegalStateException("No view child at position: $pos") }
|
||||
actual = child.marginStart
|
||||
return actual == margin
|
||||
}
|
||||
|
||||
override fun describeTo(description: Description) {
|
||||
if (actual != null) {
|
||||
description.appendText("Should have margin [${margin}] at position: $pos but was: [$actual]");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
class HasChildViewWithText(private val pos: Int, val text: String, val target: Int) :
|
||||
BoundedMatcher<View, RecyclerView>(RecyclerView::class.java) {
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue