-
Notifications
You must be signed in to change notification settings - Fork 73
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Render bmi when height and weight changes
- Loading branch information
Siddharth Agarwal
committed
Dec 19, 2024
1 parent
d774e64
commit 5008054
Showing
3 changed files
with
66 additions
and
0 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
22 changes: 22 additions & 0 deletions
22
app/src/main/java/org/simple/clinic/patientattribute/entry/BMIEntryUiRenderer.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,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() | ||
} | ||
} | ||
} |
42 changes: 42 additions & 0 deletions
42
app/src/test/java/org/simple/clinic/patientattribute/entry/BMIEntryUiRendererTest.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,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) | ||
} | ||
} |