fix(EnterSeedPhrase): fix backspace or delete

- fields can be cleared by selecting a word and pressing backspace or
delete

Iterates: #17105
This commit is contained in:
Lukáš Tinkl 2025-02-03 12:23:30 +01:00 committed by Lukáš Tinkl
parent 241f21e4ea
commit c20662e6a4
3 changed files with 46 additions and 3 deletions

View File

@ -454,5 +454,50 @@ Item {
verify(itemUnderTest.seedPhraseUpdatedSpy.count >= expectedSeedPhrase.length, "seedPhraseUpdate signal was not emitted")
verify(itemUnderTest.submitSpy.count === 1, "submitSeedPhrase signal was emitted")
}
function test_doubleClickWordAndDelete_data() {
return [
{ tag: "Delete", key: Qt.Key_Delete, resultText: "" },
{ tag: "Backspace", key: Qt.Key_Backspace, resultText: "" },
{ tag: "x", key: Qt.Key_X, resultText: "x" }, // overwrite the text with "x"
]
}
// regression test for: https://github.com/status-im/status-desktop/issues/17105 (issue 20)
function test_doubleClickWordAndDelete(data) {
//generate a seed phrase
const expectedSeedPhrase = ["abandon", "ability", "able", "about", "above", "absent", "absorb", "abstract", "absurd", "abuse", "access", "asphalt"]
const baseDictionary = [...expectedSeedPhrase, "cow", "catalog", "catch", "category", "cattle"]
let isSeedPhraseValidCalled = false
itemUnderTest.isSeedPhraseValid = (seedPhrase) => {
verify(seedPhrase === expectedSeedPhrase.join(" "), "Seed phrase is not valid")
isSeedPhraseValidCalled = true
return true
}
itemUnderTest.dictionary.append(baseDictionary.map((word) => ({seedWord: word})))
// Type the seed phrase. No space is needed between words
const str = expectedSeedPhrase.join("")
for (let i = 0; i < str.length; i++) {
keyPress(str.charAt(i))
}
verify(isSeedPhraseValidCalled, "isSeedPhraseValid was not called")
// move to the first field, double click to select the whole text there
const firstInputField = findChild(itemUnderTest, "enterSeedPhraseInputField1")
verify(!!firstInputField)
mouseClick(firstInputField)
mouseDoubleClickSequence(firstInputField)
tryCompare(firstInputField, "activeFocus", true)
tryCompare(firstInputField, "selectedText", expectedSeedPhrase[0])
// try to delete or overwrite the selected text
keyPress(data.key)
tryCompare(firstInputField, "text", data.resultText)
tryCompare(firstInputField, "selectedText", "")
}
}
}

View File

@ -155,7 +155,7 @@ Item {
for (var i = 0; i < inputList.count; i++) {
const word = inputList.get(i).seedWord
if (word.startsWith(textToCheck)) {
filteredList.insert(filteredList.count, {"seedWord": word})
filteredList.append({"seedWord": word})
}
}

View File

@ -280,8 +280,6 @@ ColumnLayout {
grid.currentIndex = index
}
onKeyPressed: {
grid.currentIndex = index
if (event.key === Qt.Key_Backtab) {
for (let i = 0; i < grid.count; i++) {
if (grid.itemAtIndex(i).mnemonicIndex === ((mnemonicIndex - 1) >= 0 ? (mnemonicIndex - 1) : 0)) {