I have a custom canvas component. I want to test canvas UI objects like rect, line, text, etc. How should I test this sample UI?
Canvas(
modifier = Modifier
.fillMaxWidth()
.height(canvasHeight.dp)
.pointerInput(Unit) {
detectTapGestures { offset ->
touchPosition.value = offset
}
}
)
{
drawArc(
color = Color(0xFFf04231),
startAngle = -90f,
sweepAngle = 180f,
useCenter = true,
size = Size(size.width * .50f, size.height * .50f),
topLeft = Offset(size.width * .25f, 0f)
)
drawPath(path = path, color = Color.White.copy(alpha = .90f))
drawCircle(
brush = Brush.verticalGradient(sunColor),
radius = width.times(.17f),
center = Offset(width.times(.35f), height.times(.35f))
)
}
The best way, for me, to make the UI test for a canvas fun is to use the screenshot test. In my case, I used Paparazzi, here is the link to the GitHub page: https://github.com/cashapp/paparazzi