Hi All, I have no idea why this test is passing. ...
# compose
b
Hi All, I have no idea why this test is passing. Can I get some guidance on understanding what is going on please. Thanks
Copy code
@RunWith(AndroidJUnit4::class)
class LoginTest {

    @get:Rule
    val composeTestRule = createAndroidComposeRule<MainActivity>()

    @Test
    fun logInButtonEnabledTest() {

        composeTestRule.setContent {
            WHApplicationTheme {
                LoginScreen({}, {}, {})
            }
        }

        val email = "sampl"
        val password = "Sa"

        val isValidEmail: Boolean = EmailValidator.isValid(email)
        val isValidPassword: Boolean = PasswordValidator.isValid(password)

        if (isValidEmail && isValidPassword) {
            composeTestRule
                .onNodeWithTag(EMAIL_TEXT_FIELD)
                .performTextInput(email)
            composeTestRule
                .onNodeWithTag(PASSWORD_TEXT_FIELD)
                .performTextInput(password)
        }

        composeTestRule
            .onNodeWithTag(LOG_IN_BUTTON)
            .performClick()
    }
}
interface FormValidator {
    fun isValid(value: String): Boolean
}
object PasswordValidator : FormValidator {

    override fun isValid(value: String): Boolean {
        return value.length > 5 && !value.contains(" ")
    }
}

object EmailValidator : FormValidator {

    override fun isValid(value: String): Boolean {
        val emailCheck = "^[A-Za-z](.*)([@])(.+)(\\.)(.+)"
        return emailCheck.toRegex().matches(value)
    }
}
🧵 2
p
I don't see any verification in the test. There's basically nothing that could fail it.
b
Am I not verifying the email and password with the if condition?
p
You are, but you are not failing the test based on that.
b
the original state of the LOG_IN_BUTTON disabled. I would only be able to click it if it met those 2 conditions
this test is passing, not failing
p
It sounds like `performClick()`does not care about if it's disabled, but I cannot confirm it.
b
I guess that’s why it is passing
p
That's what I would say too.
b
any ideas on how I can make this test pass the right way by validating the email and password and inputing the values inside of the input text field?
p
I recall that there is a way to assert if an element is enabled. That could be your verification after you have entered input.
b
ty I will look into it
👍 1
I think I got it, I changed .performClick() to .assertIsEnabled()