You cannot select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
34 lines
1.2 KiB
Kotlin
34 lines
1.2 KiB
Kotlin
/* This Source Code Form is subject to the terms of the Mozilla Public
|
|
* License, v. 2.0. If a copy of the MPL was not distributed with this
|
|
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
|
|
|
|
package org.mozilla.fenix.helpers.matchers
|
|
|
|
import android.view.View
|
|
import androidx.recyclerview.widget.RecyclerView
|
|
import androidx.test.espresso.matcher.BoundedMatcher
|
|
import org.hamcrest.Description
|
|
import org.hamcrest.Matcher
|
|
|
|
fun hasItem(matcher: Matcher<View?>): Matcher<View?>? {
|
|
return object : BoundedMatcher<View?, RecyclerView>(RecyclerView::class.java) {
|
|
override fun describeTo(description: Description) {
|
|
description.appendText("has item: ")
|
|
matcher.describeTo(description)
|
|
}
|
|
|
|
override fun matchesSafely(view: RecyclerView): Boolean {
|
|
val adapter = view.adapter
|
|
for (position in 0 until adapter!!.itemCount) {
|
|
val type = adapter.getItemViewType(position)
|
|
val holder = adapter.createViewHolder(view, type)
|
|
adapter.onBindViewHolder(holder, position)
|
|
if (matcher.matches(holder.itemView)) {
|
|
return true
|
|
}
|
|
}
|
|
return false
|
|
}
|
|
}
|
|
}
|