-
-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Feature: save and load measurements (#53)
# *save and load measurements* ## ⚙️ Release Notes ![image](https://github.com/StanfordSpezi/SpeziKt/assets/48420258/f030865c-a884-42bc-8249-5f59e20d666a) - save measurements - load latest measurements - Fixes #52 ## ✅ Testing as soon as it is confirmed that the functionality fits, further tests will be added ## 📝 Code of Conduct & Contributing Guidelines By submitting creating this pull request, you agree to follow our [Code of Conduct](https://github.com/StanfordSpezi/.github/blob/main/CODE_OF_CONDUCT.md) and [Contributing Guidelines](https://github.com/StanfordSpezi/.github/blob/main/CONTRIBUTING.md): - [x] I agree to follow the [Code of Conduct](https://github.com/StanfordSpezi/.github/blob/main/CODE_OF_CONDUCT.md) and [Contributing Guidelines](https://github.com/StanfordSpezi/.github/blob/main/CONTRIBUTING.md). --------- Signed-off-by: Basler182 <[email protected]> Co-authored-by: Eldi Cano <[email protected]>
- Loading branch information
Showing
69 changed files
with
3,342 additions
and
157 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
59 changes: 59 additions & 0 deletions
59
...kotlin/edu/stanford/bdh/engagehf/bluetooth/component/DoNewMeasurementBottomSheetKtTest.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,59 @@ | ||
package edu.stanford.bdh.engagehf.bluetooth.component | ||
|
||
import androidx.compose.ui.test.junit4.createComposeRule | ||
import edu.stanford.bdh.engagehf.simulator.DoNewMeasurementBottomSheetSimulator | ||
import org.junit.Before | ||
import org.junit.Rule | ||
import org.junit.Test | ||
|
||
class DoNewMeasurementBottomSheetKtTest { | ||
|
||
@get:Rule | ||
val composeTestRule = createComposeRule() | ||
|
||
@Before | ||
fun init() { | ||
composeTestRule.setContent { | ||
DoNewMeasurementBottomSheet() | ||
} | ||
} | ||
|
||
@Test | ||
fun `it should display the title correctly`() { | ||
doNewMeasurementBottomSheet { | ||
assertTitleIsDisplayed() | ||
} | ||
} | ||
|
||
@Test | ||
fun `it should display the progress bar correctly`() { | ||
doNewMeasurementBottomSheet { | ||
assertProgressBarIsDisplayed() | ||
} | ||
} | ||
|
||
@Test | ||
fun `it should display the description correctly`() { | ||
doNewMeasurementBottomSheet { | ||
assertDescriptionIsDisplayed() | ||
} | ||
} | ||
|
||
@Test | ||
fun `it should display the blood pressure icon correctly`() { | ||
doNewMeasurementBottomSheet { | ||
assertBloodPressureIconIsDisplayed() | ||
} | ||
} | ||
|
||
@Test | ||
fun `it should display the weight icon correctly`() { | ||
doNewMeasurementBottomSheet { | ||
assertWeightIconIsDisplayed() | ||
} | ||
} | ||
|
||
private fun doNewMeasurementBottomSheet(block: DoNewMeasurementBottomSheetSimulator.() -> Unit) { | ||
DoNewMeasurementBottomSheetSimulator(composeTestRule).apply(block) | ||
} | ||
} |
64 changes: 64 additions & 0 deletions
64
app/src/androidTest/kotlin/edu/stanford/bdh/engagehf/bluetooth/screen/BluetoothScreenTest.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,64 @@ | ||
package edu.stanford.bdh.engagehf.bluetooth.screen | ||
|
||
import androidx.compose.ui.test.junit4.createAndroidComposeRule | ||
import dagger.hilt.android.testing.HiltAndroidRule | ||
import dagger.hilt.android.testing.HiltAndroidTest | ||
import edu.stanford.bdh.engagehf.R | ||
import edu.stanford.bdh.engagehf.bluetooth.data.models.UiState | ||
import edu.stanford.bdh.engagehf.simulator.BluetoothScreenSimulator | ||
import edu.stanford.spezi.core.design.component.ComposeContentActivity | ||
import org.junit.Before | ||
import org.junit.Rule | ||
import org.junit.Test | ||
|
||
@HiltAndroidTest | ||
class BluetoothScreenTest { | ||
|
||
@get:Rule | ||
val hiltRule = HiltAndroidRule(this) | ||
|
||
@get:Rule | ||
val composeTestRule = createAndroidComposeRule<ComposeContentActivity>() | ||
|
||
@Before | ||
fun init() { | ||
composeTestRule.activity.setScreen { | ||
BluetoothScreen() | ||
} | ||
} | ||
|
||
@Test | ||
fun `test bluetooth screen root is displayed`() { | ||
bluetoothScreen { | ||
assertIsDisplayed() | ||
} | ||
} | ||
|
||
@Test | ||
fun `test bluetooth screen message title is displayed`() { | ||
bluetoothScreen { | ||
assertMessageTitle(composeTestRule.activity.getString(R.string.messages)) | ||
} | ||
} | ||
|
||
@Test | ||
fun `test bluetooth screen vital title is displayed`() { | ||
bluetoothScreen { | ||
assertVitalTitle(composeTestRule.activity.getString(R.string.vitals)) | ||
} | ||
} | ||
|
||
@Test | ||
fun `test bluetooth screen vital is displayed`() { | ||
bluetoothScreen { | ||
val uiState = UiState() | ||
assertVital(uiState.weight.title) | ||
assertVital(uiState.heartRate.title) | ||
assertVital(uiState.bloodPressure.title) | ||
} | ||
} | ||
|
||
private fun bluetoothScreen(block: BluetoothScreenSimulator.() -> Unit) { | ||
BluetoothScreenSimulator(composeTestRule).apply(block) | ||
} | ||
} |
106 changes: 106 additions & 0 deletions
106
...rc/androidTest/kotlin/edu/stanford/bdh/engagehf/bluetooth/screen/MeasurementDialogTest.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,106 @@ | ||
package edu.stanford.bdh.engagehf.bluetooth.screen | ||
|
||
import androidx.compose.ui.test.junit4.createComposeRule | ||
import edu.stanford.bdh.engagehf.bluetooth.data.models.MeasurementDialogUiState | ||
import edu.stanford.bdh.engagehf.simulator.MeasurementDialogSimulator | ||
import edu.stanford.spezi.core.bluetooth.data.model.Measurement | ||
import org.junit.Rule | ||
import org.junit.Test | ||
import java.time.ZonedDateTime | ||
|
||
class MeasurementDialogTest { | ||
|
||
@get:Rule | ||
val composeTestRule = createComposeRule() | ||
|
||
@Test | ||
fun `it should display the weight measurement data correctly`() { | ||
composeTestRule.setContent { | ||
MeasurementDialog( | ||
uiState = MeasurementDialogUiStateFactory.createDefaultWeightMeasurementUiState(), | ||
onAction = {} | ||
) | ||
} | ||
measurementDialog { | ||
assertDisplayed() | ||
assertTitle("New Measurement") | ||
assertLabel("Weight:") | ||
assertValue("70.0 kg") | ||
} | ||
} | ||
|
||
@Test | ||
fun `it should display the blood pressure measurement data correctly`() { | ||
composeTestRule.setContent { | ||
MeasurementDialog( | ||
uiState = MeasurementDialogUiStateFactory.createDefaultBloodPressureMeasurementUiState(), | ||
onAction = {} | ||
) | ||
} | ||
measurementDialog { | ||
assertDisplayed() | ||
assertTitle("New Measurement") | ||
assertLabel("Systolic:") | ||
assertValue("120.0 mmHg") | ||
assertLabel("Diastolic:") | ||
assertValue("80.0 mmHg") | ||
assertLabel("Pulse rate:") | ||
assertValue("60.0 bpm") | ||
} | ||
} | ||
|
||
object MeasurementDialogUiStateFactory { | ||
fun createDefaultWeightMeasurementUiState(): MeasurementDialogUiState { | ||
return MeasurementDialogUiState( | ||
isVisible = true, | ||
measurement = Measurement.Weight( | ||
weight = 70.0, | ||
zonedDateTime = ZonedDateTime.now(), | ||
userId = 1, | ||
bmi = 25.0, | ||
height = 190.0 | ||
), | ||
formattedWeight = "70.0 kg" | ||
) | ||
} | ||
|
||
fun createDefaultBloodPressureMeasurementUiState(): MeasurementDialogUiState { | ||
return MeasurementDialogUiState( | ||
isVisible = true, | ||
formattedSystolic = "120.0 mmHg", | ||
formattedDiastolic = "80.0 mmHg", | ||
formattedHeartRate = "60.0 bpm", | ||
measurement = Measurement.BloodPressure( | ||
flags = Measurement.BloodPressure.Flags( | ||
bloodPressureUnitsFlag = false, | ||
timeStampFlag = true, | ||
pulseRateFlag = true, | ||
userIdFlag = true, | ||
measurementStatusFlag = true | ||
), | ||
systolic = 120f, | ||
diastolic = 80f, | ||
meanArterialPressure = 90f, | ||
timestampYear = 2022, | ||
timestampMonth = 12, | ||
timestampDay = 31, | ||
timeStampHour = 23, | ||
timeStampMinute = 59, | ||
timeStampSecond = 59, | ||
pulseRate = 60f, | ||
userId = 1, | ||
measurementStatus = Measurement.BloodPressure.Status( | ||
bodyMovementDetectionFlag = false, | ||
cuffFitDetectionFlag = false, | ||
irregularPulseDetectionFlag = false, | ||
pulseRateRangeDetectionFlags = 0, | ||
measurementPositionDetectionFlag = false | ||
) | ||
) | ||
) | ||
} | ||
} | ||
|
||
private fun measurementDialog(block: MeasurementDialogSimulator.() -> Unit) = | ||
MeasurementDialogSimulator(composeTestRule).apply(block) | ||
} |
36 changes: 36 additions & 0 deletions
36
app/src/androidTest/kotlin/edu/stanford/bdh/engagehf/simulator/BluetoothScreenSimulator.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
package edu.stanford.bdh.engagehf.simulator | ||
|
||
import androidx.compose.ui.test.assertIsDisplayed | ||
import androidx.compose.ui.test.assertTextEquals | ||
import androidx.compose.ui.test.junit4.ComposeTestRule | ||
import edu.stanford.bdh.engagehf.bluetooth.screen.BluetoothScreenTestIdentifier | ||
import edu.stanford.spezi.core.testing.onNodeWithIdentifier | ||
|
||
class BluetoothScreenSimulator( | ||
private val composeTestRule: ComposeTestRule, | ||
) { | ||
private val root = composeTestRule.onNodeWithIdentifier(BluetoothScreenTestIdentifier.ROOT) | ||
|
||
private val messageTitle = | ||
composeTestRule.onNodeWithIdentifier(BluetoothScreenTestIdentifier.MESSAGE_TITLE) | ||
|
||
private val vitalTitle = | ||
composeTestRule.onNodeWithIdentifier(BluetoothScreenTestIdentifier.VITAL_TITLE) | ||
|
||
fun assertVital(vitalTitle: String) { | ||
composeTestRule.onNodeWithIdentifier(BluetoothScreenTestIdentifier.VITALS, vitalTitle) | ||
.assertIsDisplayed() | ||
} | ||
|
||
fun assertIsDisplayed() { | ||
root.assertIsDisplayed() | ||
} | ||
|
||
fun assertMessageTitle(text: String) { | ||
messageTitle.assertIsDisplayed().assertTextEquals(text) | ||
} | ||
|
||
fun assertVitalTitle(text: String) { | ||
vitalTitle.assertIsDisplayed().assertTextEquals(text) | ||
} | ||
} |
45 changes: 45 additions & 0 deletions
45
...idTest/kotlin/edu/stanford/bdh/engagehf/simulator/DoNewMeasurementBottomSheetSimulator.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
package edu.stanford.bdh.engagehf.simulator | ||
|
||
import androidx.compose.ui.test.assertIsDisplayed | ||
import androidx.compose.ui.test.junit4.ComposeTestRule | ||
import edu.stanford.bdh.engagehf.bluetooth.component.DoNewMeasurementBottomSheetTestIdentifier | ||
import edu.stanford.spezi.core.testing.onNodeWithIdentifier | ||
|
||
class DoNewMeasurementBottomSheetSimulator( | ||
composeTestRule: ComposeTestRule, | ||
) { | ||
private val title = | ||
composeTestRule.onNodeWithIdentifier(DoNewMeasurementBottomSheetTestIdentifier.TITLE) | ||
|
||
private val progressBar = | ||
composeTestRule.onNodeWithIdentifier(DoNewMeasurementBottomSheetTestIdentifier.PROGRESS_BAR) | ||
|
||
private val description = | ||
composeTestRule.onNodeWithIdentifier(DoNewMeasurementBottomSheetTestIdentifier.DESCRIPTION) | ||
|
||
private val bloodPressureIcon = | ||
composeTestRule.onNodeWithIdentifier(DoNewMeasurementBottomSheetTestIdentifier.BLOOD_PRESSURE_ICON) | ||
|
||
private val weightIcon = | ||
composeTestRule.onNodeWithIdentifier(DoNewMeasurementBottomSheetTestIdentifier.WEIGHT_ICON) | ||
|
||
fun assertTitleIsDisplayed() { | ||
title.assertIsDisplayed() | ||
} | ||
|
||
fun assertProgressBarIsDisplayed() { | ||
progressBar.assertIsDisplayed() | ||
} | ||
|
||
fun assertDescriptionIsDisplayed() { | ||
description.assertIsDisplayed() | ||
} | ||
|
||
fun assertBloodPressureIconIsDisplayed() { | ||
bloodPressureIcon.assertIsDisplayed() | ||
} | ||
|
||
fun assertWeightIconIsDisplayed() { | ||
weightIcon.assertIsDisplayed() | ||
} | ||
} |
35 changes: 35 additions & 0 deletions
35
app/src/androidTest/kotlin/edu/stanford/bdh/engagehf/simulator/MeasurementDialogSimulator.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
package edu.stanford.bdh.engagehf.simulator | ||
|
||
import androidx.compose.ui.test.assertAny | ||
import androidx.compose.ui.test.assertIsDisplayed | ||
import androidx.compose.ui.test.assertTextEquals | ||
import androidx.compose.ui.test.hasText | ||
import androidx.compose.ui.test.junit4.ComposeTestRule | ||
import edu.stanford.bdh.engagehf.bluetooth.screen.MeasurementDialogTestIdentifier | ||
import edu.stanford.spezi.core.testing.onAllNodes | ||
import edu.stanford.spezi.core.testing.onNodeWithIdentifier | ||
|
||
class MeasurementDialogSimulator(composeTestRule: ComposeTestRule) { | ||
private val root = composeTestRule.onNodeWithIdentifier(MeasurementDialogTestIdentifier.ROOT) | ||
private val title = composeTestRule.onNodeWithIdentifier(MeasurementDialogTestIdentifier.TITLE) | ||
private val measurementLabel = | ||
composeTestRule.onAllNodes(MeasurementDialogTestIdentifier.MEASUREMENT_LABEL) | ||
private val measurementValue = | ||
composeTestRule.onAllNodes(MeasurementDialogTestIdentifier.MEASUREMENT_VALUE) | ||
|
||
fun assertDisplayed() { | ||
root.assertIsDisplayed() | ||
} | ||
|
||
fun assertTitle(text: String) { | ||
title.assertIsDisplayed().assertTextEquals(text) | ||
} | ||
|
||
fun assertLabel(text: String) { | ||
measurementLabel.assertAny(hasText(text)) | ||
} | ||
|
||
fun assertValue(text: String) { | ||
measurementValue.assertAny(hasText(text)) | ||
} | ||
} |
Oops, something went wrong.