This repository has been archived by the owner on Feb 20, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 1.3k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Added UI tests for the basic settings menu
- Loading branch information
Showing
12 changed files
with
618 additions
and
164 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
36 changes: 36 additions & 0 deletions
36
app/src/androidTest/java/org/mozilla/fenix/helpers/assertions/AwesomeBarAssertion.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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") | ||
} | ||
} | ||
} |
35 changes: 35 additions & 0 deletions
35
app/src/androidTest/java/org/mozilla/fenix/helpers/matchers/BitmapDrawableMatcher.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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 | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.