Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -8,12 +8,11 @@ import com.motionapps.sensorbox.domain.sensors.SensorDescriptor
import com.motionapps.sensorbox.ui.theme.SensorBoxTheme

class MeasurementSetupScreenRobot(private val rule: ComposeContentTestRule) {
fun givenMeasurementSetup(onIntent: (MainIntent) -> Unit = {}) = apply {
fun givenMeasurementSetup(onIntent: (RecordingIntent) -> Unit = {}) = apply {
rule.setContent {
SensorBoxTheme {
MeasurementSetupScreen(
state = MainState(
route = MainRoute.SETUP,
state = RecordingState(
sensors = listOf(SensorDescriptor(1, "Accelerometer", "Fixture", false)),
selectedSensorIds = setOf(1),
storagePath = "Fixture/SensorBox",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,14 +11,14 @@ class MeasurementSetupScreenTest {

@Test
fun givenConfiguredSetupWhenStartIsTappedThenMeasurementIntentIsSent() {
var actualIntent: MainIntent? = null
var actualIntent: RecordingIntent? = null
MeasurementSetupScreenRobot(composeRule)
.givenMeasurementSetup { actualIntent = it }
.thenFolderAndSettingsAreVisible()
.whenStartMeasurementIsTapped()

composeRule.runOnIdle {
assertEquals(MainIntent.StartMeasurement, actualIntent)
assertEquals(RecordingIntent.StartMeasurement, actualIntent)
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -14,20 +14,22 @@ import androidx.compose.ui.test.performClick
import com.motionapps.sensorbox.ui.theme.SensorBoxTheme

class OnboardingScreenRobot(private val rule: ComposeContentTestRule) {
var lastIntent: MainIntent? = null
var lastIntent: OnboardingIntent? = null
private set

fun givenInteractiveOnboarding(page: Int = 0, storagePath: String? = null) = apply {
rule.setContent {
var state by remember {
mutableStateOf(
MainState(route = MainRoute.ONBOARDING, onboardingPage = page, storagePath = storagePath),
)
mutableStateOf(OnboardingState(page = page, storagePath = storagePath))
}
SensorBoxTheme {
OnboardingScreen(state) { intent ->
lastIntent = intent
state = MainReducer.reduce(state, intent).state
state = when (intent) {
OnboardingIntent.AdvanceOnboarding -> state.copy(page = state.page + 1)
OnboardingIntent.RetreatOnboarding -> state.copy(page = (state.page - 1).coerceAtLeast(0))
else -> state
}
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,15 +16,15 @@ class OnboardingScreenTest {
robot.thenPageIsVisible("Welcome to SensorBox").whenNextIsTapped()
robot.thenPageIsVisible("Nothing is going out").whenNextIsTapped()
robot.thenPageIsVisible("Privacy and terms").whenPrivacyPolicyIsTapped()
assertEquals(MainIntent.OpenPrivacyPolicy, robot.lastIntent)
assertEquals(OnboardingIntent.OpenPrivacyPolicy, robot.lastIntent)
robot.whenTermsOfUseIsTapped()
assertEquals(MainIntent.OpenTermsOfUse, robot.lastIntent)
assertEquals(OnboardingIntent.OpenTermsOfUse, robot.lastIntent)
robot.whenNextIsTapped().thenPageIsVisible("Android may pause recordings").whenNextIsTapped()
robot.thenPageIsVisible("Allow reliable background work").whenBatterySettingsIsTapped()
assertEquals(MainIntent.RequestBatteryOptimizationExemption, robot.lastIntent)
assertEquals(OnboardingIntent.RequestBatteryOptimizationExemption, robot.lastIntent)
robot.whenNextIsTapped().thenPageIsVisible("Choose a recording folder")
robot.thenFinishIsDisabled().whenChooseFolderIsTapped()
assertEquals(MainIntent.ChooseStorage, robot.lastIntent)
assertEquals(OnboardingIntent.ChooseStorage, robot.lastIntent)
}

@Test
Expand All @@ -36,6 +36,6 @@ class OnboardingScreenTest {

robot.thenFinishIsEnabled().whenFinishIsTapped()

assertEquals(MainIntent.CompleteOnboarding, robot.lastIntent)
assertEquals(OnboardingIntent.CompleteOnboarding, robot.lastIntent)
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -12,13 +12,12 @@ class RecordScreenRobot(private val rule: ComposeContentTestRule) {
fun givenRecordScreen(
selected: Boolean = false,
gpsSelected: Boolean = false,
onIntent: (MainIntent) -> Unit = {},
onIntent: (RecordingIntent) -> Unit = {},
) = apply {
rule.setContent {
SensorBoxTheme {
RecordScreen(
state = MainState(
route = MainRoute.RECORD,
state = RecordingState(
sensors = listOf(SensorDescriptor(1, "Accelerometer", "Fixture", false)),
selectedSensorIds = if (selected) setOf(1) else emptySet(),
includesGps = gpsSelected,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,62 +11,62 @@ class RecordScreenTest {

@Test
fun givenRecordScreenWhenSensorIsTappedThenToggleIntentIsSent() {
var actualIntent: MainIntent? = null
var actualIntent: RecordingIntent? = null
RecordScreenRobot(composeRule)
.givenRecordScreen { actualIntent = it }
.thenRecordingActionIsVisible()
.whenAccelerometerIsTapped()

composeRule.runOnIdle {
assertEquals(MainIntent.ToggleSensor(1), actualIntent)
assertEquals(RecordingIntent.ToggleSensor(1), actualIntent)
}
}

@Test
fun givenRecordScreenWhenSensorInfoIsTappedThenDetailsIntentIsSent() {
var actualIntent: MainIntent? = null
var actualIntent: RecordingIntent? = null
RecordScreenRobot(composeRule)
.givenRecordScreen { actualIntent = it }
.whenAccelerometerInfoIsTapped()

composeRule.runOnIdle {
assertEquals(MainIntent.OpenSensorDetails(1), actualIntent)
assertEquals(RecordingIntent.OpenSensorDetails(1), actualIntent)
}
}

@Test
fun givenSelectedSensorWhenContinueIsTappedThenSetupIntentIsSent() {
var actualIntent: MainIntent? = null
var actualIntent: RecordingIntent? = null
RecordScreenRobot(composeRule)
.givenRecordScreen(selected = true) { actualIntent = it }
.whenContinueIsTapped()

composeRule.runOnIdle {
assertEquals(MainIntent.OpenMeasurementSetup, actualIntent)
assertEquals(RecordingIntent.OpenMeasurementSetup, actualIntent)
}
}

@Test
fun givenRecordScreenWhenGpsIsTappedThenToggleGpsIntentIsSent() {
var actualIntent: MainIntent? = null
var actualIntent: RecordingIntent? = null
RecordScreenRobot(composeRule)
.givenRecordScreen { actualIntent = it }
.whenGpsIsTapped()

composeRule.runOnIdle {
assertEquals(MainIntent.ToggleGps, actualIntent)
assertEquals(RecordingIntent.ToggleGps, actualIntent)
}
}

@Test
fun givenOnlyGpsSelectedWhenContinueIsTappedThenSetupIntentIsSent() {
var actualIntent: MainIntent? = null
var actualIntent: RecordingIntent? = null
RecordScreenRobot(composeRule)
.givenRecordScreen(gpsSelected = true) { actualIntent = it }
.whenContinueIsTapped()

composeRule.runOnIdle {
assertEquals(MainIntent.OpenMeasurementSetup, actualIntent)
assertEquals(RecordingIntent.OpenMeasurementSetup, actualIntent)
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ import androidx.compose.ui.res.stringResource
import androidx.compose.ui.unit.dp
import com.motionapps.sensorbox.BuildConfig
import com.motionapps.sensorbox.R
import com.motionapps.sensorbox.core.error.AppError
import com.motionapps.sensorbox.core.error.AppErrorCode
import com.motionapps.sensorbox.core.error.appResult

@Composable
Expand Down Expand Up @@ -83,7 +83,7 @@ private fun AboutDialogBody(onPrivacy: () -> Unit) {
fun OpenSourceLicensesScreen(onBack: () -> Unit, modifier: Modifier = Modifier) {
val resources = LocalContext.current.resources
val licenses = remember(resources) {
appResult(AppError.Kind.STORAGE, "Load open source licenses") {
appResult(AppErrorCode.STORAGE, "Load open source licenses") {
loadOpenSourceLicenses(resources)
}.getOrDefault(emptyList())
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ import com.motionapps.sensorbox.ui.theme.SensorBoxRecording
import com.motionapps.sensorservices.session.MeasurementSessionState

@Composable
fun ActiveMeasurementScreen(state: MainState, onIntent: (MainIntent) -> Unit, modifier: Modifier = Modifier) {
fun ActiveMeasurementScreen(state: RecordingState, onIntent: (RecordingIntent) -> Unit, modifier: Modifier = Modifier) {
val session = state.session as? MeasurementSessionState.Running ?: return
Column(
modifier = modifier.fillMaxSize().padding(horizontal = 20.dp, vertical = 24.dp),
Expand All @@ -74,14 +74,14 @@ fun ActiveMeasurementScreen(state: MainState, onIntent: (MainIntent) -> Unit, mo
}
SensorBoxDangerButton(
label = stringResource(R.string.stop_and_save),
onClick = { onIntent(MainIntent.StopMeasurement) },
onClick = { onIntent(RecordingIntent.StopMeasurement) },
modifier = Modifier.fillMaxWidth(),
)
}
}

@Composable
private fun AnnotationEditor(onIntent: (MainIntent) -> Unit) {
private fun AnnotationEditor(onIntent: (RecordingIntent) -> Unit) {
var annotation by remember { mutableStateOf("") }
SensorBoxPanel {
Column(Modifier.fillMaxWidth().padding(16.dp), verticalArrangement = Arrangement.spacedBy(10.dp)) {
Expand All @@ -97,7 +97,7 @@ private fun AnnotationEditor(onIntent: (MainIntent) -> Unit) {
label = stringResource(R.string.add_annotation),
onClick = {
annotation.trim().takeIf(String::isNotEmpty)?.let {
onIntent(MainIntent.AddAnnotation(it))
onIntent(RecordingIntent.AddAnnotation(it))
annotation = ""
}
},
Expand Down Expand Up @@ -168,7 +168,7 @@ private fun MeasurementTimer(elapsedSeconds: Long, folderName: String) {
}

@Composable
private fun MeasurementSummary(state: MainState, session: MeasurementSessionState.Running) {
private fun MeasurementSummary(state: RecordingState, session: MeasurementSessionState.Running) {
var expanded by remember { mutableStateOf(false) }
val sources = recordingSourceNames(state, session, LocalContext.current.resources)
SensorBoxPanel {
Expand Down Expand Up @@ -230,7 +230,7 @@ private fun RecordingSourceList(sources: List<String>) {
}

private fun recordingSourceNames(
state: MainState,
state: RecordingState,
session: MeasurementSessionState.Running,
resources: Resources,
): List<String> = buildList {
Expand Down
Loading