diff options
Diffstat (limited to 'tests/auto/controls/data/tst_combobox.qml')
-rw-r--r-- | tests/auto/controls/data/tst_combobox.qml | 193 |
1 files changed, 187 insertions, 6 deletions
diff --git a/tests/auto/controls/data/tst_combobox.qml b/tests/auto/controls/data/tst_combobox.qml index 2d5069b3..9bbea26d 100644 --- a/tests/auto/controls/data/tst_combobox.qml +++ b/tests/auto/controls/data/tst_combobox.qml @@ -157,6 +157,8 @@ TestCase { verify(control.delegate) verify(control.indicator) verify(control.popup) + verify(control.acceptableInput) + compare(control.inputMethodHints, Qt.ImhNoPredictiveText) } function test_array() { @@ -296,12 +298,30 @@ TestCase { ListElement { name: "Banana"; color: "yellow" } } + Component { + id: fruitModelComponent + ListModel { + ListElement { name: "Apple"; color: "red" } + ListElement { name: "Orange"; color: "orange" } + ListElement { name: "Banana"; color: "yellow" } + } + } + property var fruitarray: [ { name: "Apple", color: "red" }, { name: "Orange", color: "orange" }, { name: "Banana", color: "yellow" } ] + Component { + id: birdModelComponent + ListModel { + ListElement { name: "Galah"; color: "pink" } + ListElement { name: "Kookaburra"; color: "brown" } + ListElement { name: "Magpie"; color: "black" } + } + } + function test_textRole_data() { return [ { tag: "ListModel", model: fruitmodel }, @@ -447,6 +467,37 @@ TestCase { compare(control.indexOfValue(data.tag), data.expectedIndex) } + function test_currentValueAfterModelChanged() { + let fruitModel = createTemporaryObject(fruitModelComponent, testCase) + verify(fruitModel) + + let control = createTemporaryObject(comboBox, testCase, + { model: fruitModel, textRole: "name", valueRole: "color", currentIndex: 1 }) + verify(control) + compare(control.currentText, "Orange") + compare(control.currentValue, "orange") + + // Remove "Apple"; the current item should now be "Banana", so currentValue should be "yellow". + fruitModel.remove(0) + compare(control.currentText, "Banana") + compare(control.currentValue, "yellow") + } + + function test_currentValueAfterNewModelSet() { + let control = createTemporaryObject(comboBox, testCase, + { model: fruitmodel, textRole: "name", valueRole: "color", currentIndex: 0 }) + verify(control) + compare(control.currentText, "Apple") + compare(control.currentValue, "red") + + // Swap the model out entirely. Since the currentIndex was 0 and + // is reset to 0 when a new model is set, it remains 0. + let birdModel = createTemporaryObject(birdModelComponent, testCase) + verify(birdModel) + control.model = birdModel + compare(control.currentText, "Galah") + compare(control.currentValue, "pink") + } function test_arrowKeys() { var control = createTemporaryObject(comboBox, testCase, @@ -862,6 +913,28 @@ TestCase { compare(control.popup.visible, true) verify(control.popup.contentItem.y < control.y) + + // Account for when a transition of a scale from 0.9-1.0 that it is placed above right away and not below + // first just because there is room at the 0.9 scale + if (control.popup.enter !== null) { + // hide + mouseClick(control) + compare(control.pressed, false) + tryCompare(control.popup, "visible", false) + control.y = control.Window.height - (control.popup.contentItem.height * 0.99) + var popupYSpy = createTemporaryObject(signalSpy, testCase, {target: control.popup, signalName: "yChanged"}) + verify(popupYSpy.valid) + mousePress(control) + compare(control.pressed, true) + compare(control.popup.visible, false) + mouseRelease(control) + compare(control.pressed, false) + compare(control.popup.visible, true) + tryCompare(control.popup.enter, "running", false) + verify(control.popup.contentItem.y < control.y) + verify(popupYSpy.count === 1) + } + // follow the control outside the horizontal window bounds control.x = -control.width / 2 compare(control.x, -control.width / 2) @@ -877,6 +950,56 @@ TestCase { tryCompare(control.popup, "visible", false) } + Component { + id: reopenCombo + Window { + property alias innerCombo: innerCombo + visible: true + width: 300 + height: 300 + ComboBox { + id: innerCombo + model: 10 + anchors.verticalCenter: parent.verticalCenter + } + } + } + + // This test checks that when reopening the combobox that it is still appears at the same y position as + // previously + function test_reopen_popup() { + var control = createTemporaryObject(reopenCombo, testCase) + verify(control) + var y = 0; + for (var i = 0; i < 2; ++i) { + tryCompare(control.innerCombo.popup, "visible", false) + control.innerCombo.y = control.height - (control.innerCombo.popup.contentItem.height * 0.99) + var popupYSpy = createTemporaryObject(signalSpy, testCase, {target: control.innerCombo.popup, signalName: "yChanged"}) + verify(popupYSpy.valid) + mousePress(control.innerCombo) + compare(control.innerCombo.pressed, true) + compare(control.innerCombo.popup.visible, false) + mouseRelease(control.innerCombo) + compare(control.innerCombo.pressed, false) + compare(control.innerCombo.popup.visible, true) + if (control.innerCombo.popup.enter) + tryCompare(control.innerCombo.popup.enter, "running", false) + // Check on the second opening that it has the same y position as before + if (i !== 0) { + // y should not have changed again + verify(popupYSpy.count === 0) + verify(y === control.innerCombo.popup.y) + } else { + // In some cases on the initial show, y changes more than once + verify(popupYSpy.count >= 1) + y = control.innerCombo.popup.y + mouseClick(control.innerCombo) + compare(control.innerCombo.pressed, false) + tryCompare(control.innerCombo.popup, "visible", false) + } + } + } + function test_mouse() { var control = createTemporaryObject(comboBox, testCase, {model: 3, hoverEnabled: false}) verify(control) @@ -1425,7 +1548,7 @@ TestCase { control.editText = "" compare(control.acceptableInput, true) control.editText = "" - control.forceActiveFocus() + control.contentItem.forceActiveFocus() keyPress(Qt.Key_A) compare(control.editText, "") keyPress(Qt.Key_A) @@ -1462,7 +1585,7 @@ TestCase { compare(control.currentIndex, 0) compare(control.currentText, "first") - control.forceActiveFocus() + control.contentItem.forceActiveFocus() compare(control.activeFocus, true) control.selectAll() @@ -1485,7 +1608,7 @@ TestCase { var control = createTemporaryObject(comboBox, testCase, {editable: true, model: ["Banana", "Coco", "Coconut", "Apple", "Cocomuffin"]}) verify(control) - control.forceActiveFocus() + control.contentItem.forceActiveFocus() verify(control.activeFocus) var acceptCount = 0 @@ -1636,7 +1759,7 @@ TestCase { var control = createTemporaryObject(keysAttachedBox, testCase) verify(control) - control.forceActiveFocus() + control.contentItem.forceActiveFocus() verify(control.activeFocus) verify(!control.gotit) @@ -1891,7 +2014,7 @@ TestCase { // Give the first ComboBox focus and type in 0 to select "Item 10" (default is "Item 1"). waitForRendering(comboBox1) - comboBox1.forceActiveFocus() + comboBox1.contentItem.forceActiveFocus() verify(comboBox1.activeFocus) keyClick(Qt.Key_0) compare(comboBox1.editText, "Item 10") @@ -1909,7 +2032,7 @@ TestCase { // Give focus back to the first ComboBox, and try the same thing except // with non-existing text; the currentIndex should not change. - comboBox1.forceActiveFocus() + comboBox1.contentItem.forceActiveFocus() verify(comboBox1.activeFocus) keySequence(StandardKey.SelectAll) compare(comboBox1.contentItem.selectedText, "Item 10") @@ -1921,4 +2044,62 @@ TestCase { compare(comboBox1.currentIndex, 9) compare(currentIndexSpy.count, 1) } + + // QTBUG-61021: text line should not be focused by default + // It causes (e.g. on Android) showing virtual keyboard when it is not needed + function test_doNotFocusTextLineByDefault() { + var control = createTemporaryObject(comboBox, testCase) + // Focus not set after creating combobox + verify(!control.activeFocus) + verify(!control.contentItem.focus) + + // After setting focus on combobox, text line should not be focused + control.forceActiveFocus() + verify(control.activeFocus) + verify(!control.contentItem.focus) + + // Text line is focused after intentional setting focus on it + control.contentItem.forceActiveFocus() + verify(control.activeFocus) + verify(control.contentItem.focus) + } + + Component { + id: intValidatorComponent + IntValidator { + bottom: 0 + top: 255 + } + } + + function test_acceptableInput_QTBUG_94307() { + let items = [ + { text: "A" }, + { text: "2" }, + { text: "3" } + ] + let control = createTemporaryObject(comboBox, testCase, {model: items, editable: true}) + verify(control) + + verify(control.acceptableInput) + compare(control.displayText, "A") + + let acceptableInputSpy = signalSpy.createObject(control, {target: control, signalName: "acceptableInputChanged"}) + verify(acceptableInputSpy.valid) + + let intValidator = intValidatorComponent.createObject(testCase) + verify(intValidator) + + control.validator = intValidator + + compare(acceptableInputSpy.count, 1) + compare(control.displayText, "A") + compare(control.acceptableInput, false) + + control.currentIndex = 1 + + compare(acceptableInputSpy.count, 2) + compare(control.displayText, "2") + compare(control.acceptableInput, true) + } } |