Skip to content

Commit

Permalink
Render bmi when height and weight changes
Browse files Browse the repository at this point in the history
  • Loading branch information
Siddharth Agarwal committed Dec 19, 2024
1 parent d774e64 commit 5008054
Show file tree
Hide file tree
Showing 3 changed files with 66 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -4,4 +4,6 @@ interface BMIEntryUi {
fun closeSheet()
fun changeFocusToHeight()
fun changeFocusToWeight()
fun showBMI(bmi: String)
fun hideBMI()
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
package org.simple.clinic.patientattribute.entry

import org.simple.clinic.mobius.ViewRenderer
import org.simple.clinic.patientattribute.BMIReading

class BMIEntryUiRenderer(
val ui: BMIEntryUi
) : ViewRenderer<BMIEntryModel> {

override fun render(model: BMIEntryModel) {
if (model.height.isNotEmpty() && model.weight.isNotEmpty()) {
val bmi = BMIReading(
height = model.height,
weight = model.weight
).calculateBMI()

ui.showBMI(bmi.toString())
} else {
ui.hideBMI()
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
package org.simple.clinic.patientattribute.entry

import org.junit.Test
import org.mockito.kotlin.mock
import org.mockito.kotlin.verify
import org.mockito.kotlin.verifyNoMoreInteractions
import org.simple.clinic.patientattribute.BMIReading
import java.util.UUID

class BMIEntryUiRendererTest {
private val ui = mock<BMIEntryUi>()
private val uiRenderer = BMIEntryUiRenderer(ui)
private val patientUuid = UUID.fromString("d6dd1708-9061-4c6c-b5c7-47b132198862")
private val defaultModel = BMIEntryModel
.default(patientUuid)

@Test
fun `when the sheet is show for a new entry, then hide bmi`() {
// when
uiRenderer.render(defaultModel)

// then
verify(ui).hideBMI()
verifyNoMoreInteractions(ui)
}

@Test
fun `when the height and weight are entered, then show bmi`() {
//given
val height = "177"
val weight = "68"
val reading = BMIReading(height, weight)
val bmi = reading.calculateBMI().toString()

// when
uiRenderer.render(defaultModel.heightChanged(height).weightChanged(weight))

// then
verify(ui).showBMI(bmi)
verifyNoMoreInteractions(ui)
}
}

0 comments on commit 5008054

Please sign in to comment.