Created
October 19, 2017 08:41
-
-
Save Chesteer89/d6bfe7383c287935ce938e9dfa98c0a1 to your computer and use it in GitHub Desktop.
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
class KToast : BaseActions, TextViewAssertions { | |
private val builder = ViewBuilder().apply( {withAnyText()} ) | |
val matcher = this.builder.getViewMatcher() | |
override val view = this.builder.getViewInteraction().inRoot(ToastMatcher()) | |
/** | |
* Operator that allows usage of DSL style | |
* | |
* @param function Tail lambda with receiver which is your view | |
*/ | |
operator fun invoke(function: KToast.() -> Unit) { | |
function(this) | |
} | |
} | |
class ToastMatcher : TypeSafeMatcher<Root>() { | |
override fun describeTo(description: Description) { | |
description.appendText("is toast") | |
} | |
override fun matchesSafely(root: Root): Boolean { | |
val type = root.windowLayoutParams.get().type | |
if (type == WindowManager.LayoutParams.TYPE_TOAST) { | |
val windowToken = root.decorView.windowToken | |
val appToken = root.decorView.applicationWindowToken | |
if (windowToken === appToken) { | |
//means this window isn't contained by any other windows. | |
return true | |
} | |
} | |
return false | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment