[#322] Restore Wallet "greedy" autocompletion
- Changed order of conditions of automatic autocompletion. - Added a test for validation of autocompletion functionality - Changed type of test tag on ChipLayout component, as it seems its not necessary to have this one for proper component functionality. The one from the test package is needed here for the newly added test. And other screen components also use only those from the test package.
This commit is contained in:
parent
482a48edb7
commit
f091da51ee
|
@ -10,6 +10,10 @@ import org.junit.Test
|
|||
class ParseResultTest {
|
||||
companion object {
|
||||
private val SAMPLE_WORD_LIST = setOf("bar", "baz", "foo")
|
||||
private val SAMPLE_WORD_LIST_EXT = buildSet {
|
||||
addAll(SAMPLE_WORD_LIST)
|
||||
add("bazooka")
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
|
@ -69,6 +73,29 @@ class ParseResultTest {
|
|||
assertEquals(ParseResult.Autocomplete(listOf("bar", "baz")), actual)
|
||||
}
|
||||
|
||||
@Test
|
||||
@SmallTest
|
||||
fun autocomplete_multiple_same_base() {
|
||||
ParseResult.new(SAMPLE_WORD_LIST_EXT, "baz").also {
|
||||
assertTrue(it is ParseResult.Autocomplete)
|
||||
assertTrue((it as ParseResult.Autocomplete).suggestions.size == 2)
|
||||
assertTrue((it).suggestions.contains("baz"))
|
||||
assertTrue((it).suggestions.contains("bazooka"))
|
||||
}
|
||||
|
||||
ParseResult.new(SAMPLE_WORD_LIST_EXT, "bazo").also {
|
||||
assertTrue(it is ParseResult.Autocomplete)
|
||||
assertTrue((it as ParseResult.Autocomplete).suggestions.size == 1)
|
||||
assertTrue((it).suggestions.contains("bazooka"))
|
||||
}
|
||||
|
||||
ParseResult.new(SAMPLE_WORD_LIST_EXT, "bazooka").also {
|
||||
assertTrue(it is ParseResult.Add)
|
||||
assertTrue((it as ParseResult.Add).words.size == 1)
|
||||
assertTrue(it.words.contains("bazooka"))
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
@SmallTest
|
||||
fun autocomplete_security() {
|
||||
|
|
|
@ -31,11 +31,13 @@ internal sealed class ParseResult {
|
|||
return Continue
|
||||
}
|
||||
|
||||
if (completeWordList.contains(trimmed)) {
|
||||
val autocomplete = completeWordList.filter { it.startsWith(trimmed) }
|
||||
|
||||
// we accept the word only in case that there is no other available
|
||||
if (completeWordList.contains(trimmed) && autocomplete.size == 1) {
|
||||
return Add(listOf(trimmed))
|
||||
}
|
||||
|
||||
val autocomplete = completeWordList.filter { it.startsWith(trimmed) }
|
||||
if (autocomplete.isNotEmpty()) {
|
||||
return Autocomplete(autocomplete)
|
||||
}
|
||||
|
|
|
@ -53,7 +53,6 @@ import co.electriccoin.zcash.ui.design.MINIMAL_WEIGHT
|
|||
import co.electriccoin.zcash.ui.design.component.Body
|
||||
import co.electriccoin.zcash.ui.design.component.CHIP_GRID_ROW_SIZE
|
||||
import co.electriccoin.zcash.ui.design.component.Chip
|
||||
import co.electriccoin.zcash.ui.design.component.CommonTag
|
||||
import co.electriccoin.zcash.ui.design.component.GradientSurface
|
||||
import co.electriccoin.zcash.ui.design.component.Header
|
||||
import co.electriccoin.zcash.ui.design.component.NavigationButton
|
||||
|
@ -78,7 +77,9 @@ fun PreviewRestore() {
|
|||
"above",
|
||||
"absent",
|
||||
"absorb",
|
||||
"abstract"
|
||||
"abstract",
|
||||
"rib",
|
||||
"ribbon"
|
||||
),
|
||||
userWordList = WordList(listOf("abandon", "absorb")),
|
||||
onBack = {},
|
||||
|
@ -215,7 +216,7 @@ private fun ChipGridWithText(
|
|||
Column(
|
||||
Modifier
|
||||
.verticalScroll(scrollState)
|
||||
.testTag(CommonTag.CHIP_LAYOUT)
|
||||
.testTag(RestoreTag.CHIP_LAYOUT)
|
||||
) {
|
||||
userWordList.chunked(CHIP_GRID_ROW_SIZE).forEachIndexed { chunkIndex, chunk ->
|
||||
Row(Modifier.fillMaxWidth()) {
|
||||
|
|
Loading…
Reference in New Issue