Created
September 5, 2025 14:33
-
-
Save oliverspryn/810e2630deef76b3e8ddab91bf48d37a to your computer and use it in GitHub Desktop.
Custom assertions for testing Jetpack Compose custom action labels and callbacks
This file contains hidden or 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
fun SemanticsNodeInteraction.assertHasCustomActionLabel( | |
label: String, // Assert the label matches | |
actionIndex: Int = 0 // Which action to verify, if you have more than one | |
): SemanticsNodeInteraction = assert(SemanticsMatcher("The custom accessibility action label is set to $label") { | |
it.config | |
.getOrNull(SemanticsActions.CustomActions) | |
?.get(actionIndex)?.label == label | |
}) | |
fun SemanticsNodeInteraction.invokeCustomAction( | |
actionIndex: Int = 0 // Which action to invoke, if you have more than one | |
): SemanticsNodeInteraction = assert(SemanticsMatcher("The custom accessibility action is invoked") { | |
val action = it.config | |
.getOrNull(SemanticsActions.CustomActions) | |
?.get(actionIndex)?.action ?: return@SemanticsMatcher false | |
action.invoke() | |
}) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment