Skip to content

Commit

Permalink
Feature: save and load measurements (#53)
Browse files Browse the repository at this point in the history
# *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
Basler182 and eldcn authored Jul 20, 2024
1 parent 9ed34f6 commit 7757129
Show file tree
Hide file tree
Showing 69 changed files with 3,342 additions and 157 deletions.
3 changes: 3 additions & 0 deletions app/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,8 @@ android {
buildConfigField("boolean", "USE_FIREBASE_EMULATOR", "false")
}
debug {
// Disabling coverage due to: https://github.com/hapifhir/org.hl7.fhir.core/issues/1688
enableAndroidTestCoverage = false
buildConfigField("boolean", "USE_FIREBASE_EMULATOR", "true")
}
}
Expand All @@ -44,6 +46,7 @@ dependencies {
implementation(project(":modules:account"))
implementation(project(":modules:education"))
implementation(project(":modules:onboarding"))
implementation(project(":modules:measurements"))

implementation(libs.firebase.firestore.ktx)

Expand Down
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)
}
}
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)
}
}
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)
}
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)
}
}
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()
}
}
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))
}
}
Loading

0 comments on commit 7757129

Please sign in to comment.