Add commonUI test
Some checks failed
SonarQube Scan / SonarQube Trigger (push) Failing after 7m17s

This commit is contained in:
2025-10-12 23:51:12 +02:00
parent 054d229b97
commit efac02216e
10 changed files with 104 additions and 48 deletions

View File

@@ -0,0 +1,5 @@
package ch.dissem.yaep.ui.common
@Suppress("EXPECT_ACTUAL_CLASSIFIERS_ARE_IN_BETA_WARNING")
@Target(allowedTargets = [AnnotationTarget.CLASS, AnnotationTarget.FUNCTION])
actual annotation class IgnoreAndroidUnitTest actual constructor()

View File

@@ -0,0 +1,4 @@
package ch.dissem.yaep.ui.common
@Suppress("EXPECT_ACTUAL_CLASSIFIERS_ARE_IN_BETA_WARNING")
actual typealias IgnoreAndroidUnitTest = org.junit.Ignore

View File

@@ -19,6 +19,7 @@ import androidx.compose.ui.Modifier
import androidx.compose.ui.draw.drawBehind
import androidx.compose.ui.graphics.BlurEffect
import androidx.compose.ui.graphics.graphicsLayer
import androidx.compose.ui.platform.testTag
import androidx.compose.ui.text.style.TextAlign
import androidx.compose.ui.unit.dp
import androidx.compose.ui.unit.sp
@@ -42,11 +43,12 @@ fun EndOfGame(
exit = fadeOut()
) {
val background = MaterialTheme.colorScheme.background
Box(modifier = Modifier
.fillMaxSize()
.drawBehind {
drawRect(color = background.copy(alpha = 0.8f))
}
Box(
modifier = Modifier
.fillMaxSize()
.drawBehind {
drawRect(color = background.copy(alpha = 0.8f))
}
) {
Column(
modifier = Modifier
@@ -57,6 +59,7 @@ fun EndOfGame(
fontSize = 128.sp,
textAlign = TextAlign.Center,
modifier = Modifier.fillMaxWidth()
.testTag("EndOfGame.solved_congrats")
)
Spacer(modifier = Modifier.height(16.dp))
Text(
@@ -64,10 +67,12 @@ fun EndOfGame(
fontSize = 64.sp,
textAlign = TextAlign.Center,
modifier = Modifier.fillMaxWidth()
.testTag("EndOfGame.solved_time")
)
Spacer(modifier = Modifier.height(32.dp))
Button(
modifier = Modifier.align(CenterHorizontally),
modifier = Modifier.align(CenterHorizontally)
.testTag("EndOfGame.restart"),
onClick = onRestart
) {
Text(stringResource(Res.string.restart))

View File

@@ -1,10 +0,0 @@
import ch.tutteli.atrium.api.fluent.en_GB.toEqual
import ch.tutteli.atrium.api.verbs.expect
import kotlin.test.Test
class DummyTest {
@Test
fun `ensure there is a test`() {
expect(true).toEqual(true)
}
}

View File

@@ -0,0 +1,33 @@
import androidx.compose.ui.test.ExperimentalTestApi
import androidx.compose.ui.test.assertTextContains
import androidx.compose.ui.test.onNodeWithTag
import androidx.compose.ui.test.performClick
import androidx.compose.ui.test.runComposeUiTest
import ch.dissem.yaep.ui.common.EndOfGame
import ch.dissem.yaep.ui.common.IgnoreAndroidUnitTest
import ch.tutteli.atrium.api.fluent.en_GB.toEqual
import ch.tutteli.atrium.api.verbs.expect
import kotlin.test.Test
@IgnoreAndroidUnitTest
@OptIn(ExperimentalTestApi::class)
class EndOfGameTest {
@Test
fun `ensure end of game works correctly`() = runComposeUiTest {
var restart = false
setContent {
EndOfGame(
isSolved = true,
time = "42:42",
onRestart = { restart = true }
)
}
onNodeWithTag("EndOfGame.solved_time").assertTextContains(value = "42:42", substring = true)
onNodeWithTag("EndOfGame.restart").performClick()
expect(restart).toEqual(true)
}
}

View File

@@ -0,0 +1,5 @@
package ch.dissem.yaep.ui.common
@Suppress("EXPECT_ACTUAL_CLASSIFIERS_ARE_IN_BETA_WARNING")
@Target(AnnotationTarget.CLASS, AnnotationTarget.FUNCTION)
expect annotation class IgnoreAndroidUnitTest()

View File

@@ -0,0 +1,5 @@
package ch.dissem.yaep.ui.common
@Suppress("EXPECT_ACTUAL_CLASSIFIERS_ARE_IN_BETA_WARNING")
@Target(allowedTargets = [AnnotationTarget.CLASS, AnnotationTarget.FUNCTION])
actual annotation class IgnoreAndroidUnitTest actual constructor()