Bradleycorn
11/19/2021, 1:42 AMClickableText
(with an annotated string), and I only handle clicks on a certain portion of the string, like this:
onClick = { pos ->
if (pos in linkStart..linkEnd) {
onLoginClicked()
}
}
How can I test this?
I need a way in the test to click on a certain position (string index) in the text.
performClick()
doesn’t take any parameters that I could use to click at a certain position.
Using performTouchInput()
let’s me move by a number of pixels, but I’m not sure how that helps since I need to click based on string position.Brian G
11/19/2021, 3:25 PMBradleycorn
11/19/2021, 4:06 PMonLoginClicked()
callback it’s given is called appropriately.
For example, if another dev on the team comes along and makes this change:
onClick = { pos ->
if (pos in linkStart..linkEnd) {
//Removing this, we don't want to do anything when the text is clicked.
//onLoginClicked()
}
}
Then I want a test somewhere to fail because the callback was not calledBradleycorn
11/19/2021, 4:09 PM@Test
fun LoginClickCallbackIsCalled() {
var loginClicked = false
composeTestRule.setContent {
MyComposable(onLoginClicked = { loginClicked = true })
}
composeTestRule.onNodeWithContentDescription("The ClickableText").performClick()
assertTrue("Login callback should be called when login is clicked", loginClicked)
}
Brian G
11/19/2021, 10:28 PMBrian G
11/20/2021, 9:22 AMBrian G
11/20/2021, 9:26 AMfun onTextClick(index: Int)
containing that logic, and test THAT function in your unit test.Bradleycorn
11/22/2021, 1:36 PMperofrmClick
on a certain character position in a ClickableTextZach Klippenstein (he/him) [MOD]
11/22/2021, 4:15 PMZach Klippenstein (he/him) [MOD]
11/22/2021, 4:16 PMBradleycorn
11/22/2021, 4:20 PMClickableText
does it and gives me a string position in the callback and not an x/y point.Zach Klippenstein (he/him) [MOD]
11/22/2021, 4:26 PMBradleycorn
11/22/2021, 4:28 PMBradleycorn
11/22/2021, 5:08 PMClickableText
itself (which does exactly what I need).
https://issuetracker.google.com/issues/207325144Zach Klippenstein (he/him) [MOD]
11/22/2021, 5:16 PMchatterInDaSkull
04/10/2023, 6:11 PMZach Klippenstein (he/him) [MOD]
04/10/2023, 10:20 PM