Adding UI tests for the Basic Menu settings. 🎲 !!!! (#6346)
* Added UI tests for the basic settings menu * Disabled toggleSearchSuggestions testfennec/nightly
parent
6019adafac
commit
095477e0ef
@ -0,0 +1,36 @@
|
|||||||
|
package org.mozilla.fenix.helpers.assertions
|
||||||
|
|
||||||
|
import android.view.View
|
||||||
|
import androidx.test.espresso.ViewAssertion
|
||||||
|
import mozilla.components.browser.awesomebar.BrowserAwesomeBar
|
||||||
|
|
||||||
|
class AwesomeBarAssertion {
|
||||||
|
companion object {
|
||||||
|
fun suggestionsAreGreaterThan(minimumSuggestions: Int): ViewAssertion {
|
||||||
|
return ViewAssertion { view, noViewFoundException ->
|
||||||
|
if (noViewFoundException != null) throw noViewFoundException
|
||||||
|
|
||||||
|
val suggestionsCount = getSuggestionCountFromView(view)
|
||||||
|
|
||||||
|
if (suggestionsCount <= minimumSuggestions)
|
||||||
|
throw AssertionError("The suggestion count is less than or equal to the minimum suggestions")
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
fun suggestionsAreEqualTo(expectedItemCount: Int): ViewAssertion {
|
||||||
|
return ViewAssertion { view, noViewFoundException ->
|
||||||
|
if (noViewFoundException != null) throw noViewFoundException
|
||||||
|
|
||||||
|
val suggestionsCount = getSuggestionCountFromView(view)
|
||||||
|
|
||||||
|
if (suggestionsCount != expectedItemCount)
|
||||||
|
throw AssertionError("The expected item count is $expectedItemCount, and the suggestions count within the AwesomeBar is $suggestionsCount")
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private fun getSuggestionCountFromView(view: View): Int {
|
||||||
|
return (view as BrowserAwesomeBar).adapter?.itemCount
|
||||||
|
?: throw AssertionError("This view is not of type BrowserAwesomeBar")
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1,35 @@
|
|||||||
|
package org.mozilla.fenix.helpers.matchers
|
||||||
|
|
||||||
|
import android.graphics.Bitmap
|
||||||
|
import android.view.View
|
||||||
|
import android.widget.ImageView
|
||||||
|
import androidx.test.espresso.matcher.BoundedMatcher
|
||||||
|
import org.hamcrest.Description
|
||||||
|
import android.graphics.drawable.BitmapDrawable
|
||||||
|
import android.graphics.drawable.StateListDrawable
|
||||||
|
import android.graphics.drawable.Drawable
|
||||||
|
|
||||||
|
class BitmapDrawableMatcher(private val bitmap: Bitmap, private val name: String) :
|
||||||
|
BoundedMatcher<View, ImageView>(ImageView::class.java) {
|
||||||
|
|
||||||
|
override fun describeTo(description: Description?) {
|
||||||
|
description?.appendText("has image drawable resource $name")
|
||||||
|
}
|
||||||
|
|
||||||
|
override fun matchesSafely(item: ImageView): Boolean {
|
||||||
|
return sameBitmap(item.drawable, bitmap)
|
||||||
|
}
|
||||||
|
|
||||||
|
private fun sameBitmap(drawable: Drawable?, otherBitmap: Bitmap): Boolean {
|
||||||
|
var currentDrawable = drawable ?: return false
|
||||||
|
|
||||||
|
if (currentDrawable is StateListDrawable) {
|
||||||
|
currentDrawable = currentDrawable.current
|
||||||
|
}
|
||||||
|
if (currentDrawable is BitmapDrawable) {
|
||||||
|
val bitmap = currentDrawable.bitmap
|
||||||
|
return bitmap.sameAs(otherBitmap)
|
||||||
|
}
|
||||||
|
return false
|
||||||
|
}
|
||||||
|
}
|
Loading…
Reference in New Issue