test(US-14): add instrumented UI tests for PacerScreen

Tests cover: app launch, START/STOP toggle, preset BPM button,
and service running/stopped state. Run with:
./gradlew connectedAndroidTest
This commit is contained in:
Jeena 2026-03-09 12:23:35 +00:00
parent 7f8a65d76b
commit 4647853ce7

View file

@ -0,0 +1,68 @@
package net.jeena.pacer
import androidx.compose.ui.test.assertIsDisplayed
import androidx.compose.ui.test.junit4.createAndroidComposeRule
import androidx.compose.ui.test.onNodeWithText
import androidx.compose.ui.test.performClick
import androidx.test.ext.junit.runners.AndroidJUnit4
import org.junit.Rule
import org.junit.Test
import org.junit.runner.RunWith
/**
* Instrumented UI tests for PacerScreen (US-14).
* Run with: ./gradlew connectedAndroidTest
*/
@RunWith(AndroidJUnit4::class)
class PacerScreenTest {
@get:Rule
val composeRule = createAndroidComposeRule<MainActivity>()
@Test
fun appLaunches_andShowsStartButton() {
composeRule.onNodeWithText("START").assertIsDisplayed()
}
@Test
fun appLaunches_andShowsTitle() {
composeRule.onNodeWithText("PACER").assertIsDisplayed()
}
@Test
fun tappingStart_changesButtonToStop() {
composeRule.onNodeWithText("START").performClick()
composeRule.onNodeWithText("STOP").assertIsDisplayed()
}
@Test
fun tappingStop_changesButtonBackToStart() {
composeRule.onNodeWithText("START").performClick()
composeRule.onNodeWithText("STOP").performClick()
composeRule.onNodeWithText("START").assertIsDisplayed()
}
@Test
fun presetButton_updatesBpmDisplay() {
// Tap the "100 / SLOW" preset
composeRule.onNodeWithText("100").performClick()
composeRule.onNodeWithText("100").assertIsDisplayed()
}
@Test
fun serviceRunning_afterTappingStart() {
composeRule.onNodeWithText("START").performClick()
composeRule.waitForIdle()
assert(PacerService.isRunning)
// Clean up
composeRule.onNodeWithText("STOP").performClick()
}
@Test
fun serviceStopped_afterTappingStop() {
composeRule.onNodeWithText("START").performClick()
composeRule.onNodeWithText("STOP").performClick()
composeRule.waitForIdle()
assert(!PacerService.isRunning)
}
}