BIT-2442: check type before extracting autofill text (#3394)

This commit is contained in:
David Perez 2024-07-02 15:18:25 -05:00 committed by GitHub
parent b181d0d026
commit bb6a7af423
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
2 changed files with 25 additions and 4 deletions

View file

@ -26,7 +26,12 @@ fun AutofillValue.extractMonthValue(
/**
* Extract a text value from this [AutofillValue].
*/
fun AutofillValue.extractTextValue(): String? = this
.textValue
.takeIf { it.isNotBlank() }
?.toString()
fun AutofillValue.extractTextValue(): String? =
if (this.isText) {
this
.textValue
.takeIf { it.isNotBlank() }
?.toString()
} else {
null
}

View file

@ -79,6 +79,7 @@ class AutofillValueExtensionsTest {
fun `extractTextValue should return textValue when not blank`() {
// Setup
val autofillValue: AutofillValue = mockk {
every { isText } returns true
every { textValue } returns TEXT_VALUE
}
@ -93,6 +94,7 @@ class AutofillValueExtensionsTest {
fun `extractTextValue should return null when not blank`() {
// Setup
val autofillValue: AutofillValue = mockk {
every { isText } returns true
every { textValue } returns " "
}
@ -102,6 +104,20 @@ class AutofillValueExtensionsTest {
// Verify
assertNull(actual)
}
@Test
fun `extractTextValue should return null when not text`() {
// Setup
val autofillValue: AutofillValue = mockk {
every { isText } returns false
}
// Test
val actual = autofillValue.extractTextValue()
// Verify
assertNull(actual)
}
}
private const val LIST_VALUE: Int = 5