Lets say I have a Composable that represents an in...
# compose
c
Lets say I have a Composable that represents an input field and this input field has some sort of restriction in what it can take in. It could be
@Composeable fun MyEmailInputField() { ... }
@Composeable fun MyPhoneInputField() { ... }
@Composeable fun MyPasswordInputField() { ... }
Would you have: 1️⃣ the validation/restriction of chars is built into the Composable 2️⃣ the validation/restriction of chars is built into your "ViewModel"
1️⃣ 5
2️⃣ 15
p
I prefer to test this logic in a JVM test instead of an UI Android test -> ViewModel
the less thing you need to test during an Android UI test the better
z
If I have to use the same validation in multiple places, I would go further and put the validation in another class / function - e.g. an Interactor / UseCase maybe. Then have the ViewModel call this class / function
3
s
3. Validation done by a Validator class that's hoisted appropriately (such as the ViewModel)
👍 2