2024-05-23 08:08:18 +00:00
|
|
|
import QtQuick 2.15
|
|
|
|
import QtTest 1.15
|
|
|
|
|
|
|
|
import StatusQ.Controls 0.1
|
|
|
|
|
|
|
|
import shared.controls 1.0
|
|
|
|
|
|
|
|
Item {
|
|
|
|
id: root
|
|
|
|
width: 600
|
|
|
|
height: 400
|
|
|
|
|
|
|
|
Component {
|
|
|
|
id: componentUnderTest
|
2024-05-27 17:37:22 +00:00
|
|
|
SlippageSelector {
|
2024-05-23 08:08:18 +00:00
|
|
|
anchors.centerIn: parent
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2024-05-27 17:37:22 +00:00
|
|
|
property SlippageSelector controlUnderTest: null
|
2024-05-23 08:08:18 +00:00
|
|
|
|
|
|
|
TestCase {
|
2024-05-27 17:37:22 +00:00
|
|
|
name: "SlippageSelector"
|
2024-05-23 08:08:18 +00:00
|
|
|
when: windowShown
|
|
|
|
|
|
|
|
function init() {
|
|
|
|
controlUnderTest = createTemporaryObject(componentUnderTest, root)
|
|
|
|
}
|
|
|
|
|
2024-05-27 17:37:22 +00:00
|
|
|
function test_basicSetup() {
|
2024-05-23 08:08:18 +00:00
|
|
|
verify(!!controlUnderTest)
|
|
|
|
verify(controlUnderTest.width > 0)
|
|
|
|
verify(controlUnderTest.height > 0)
|
|
|
|
verify(controlUnderTest.valid)
|
|
|
|
}
|
|
|
|
|
|
|
|
function test_selectPresetValues() {
|
|
|
|
verify(!!controlUnderTest)
|
|
|
|
const buttonsRepeater = findChild(controlUnderTest, "buttonsRepeater")
|
|
|
|
verify(!!buttonsRepeater)
|
2024-05-27 17:37:22 +00:00
|
|
|
waitForRendering(buttonsRepeater)
|
2024-05-23 08:08:18 +00:00
|
|
|
for (let i = 0; i < buttonsRepeater.count; i++) {
|
|
|
|
const button = buttonsRepeater.itemAt(i)
|
|
|
|
verify(!!button)
|
|
|
|
mouseClick(button)
|
|
|
|
tryCompare(button, "checked", true)
|
|
|
|
tryCompare(button, "type", StatusBaseButton.Type.Primary)
|
2024-05-27 17:37:22 +00:00
|
|
|
tryCompare(controlUnderTest, "value", button.value)
|
2024-05-23 08:08:18 +00:00
|
|
|
verify(controlUnderTest.valid)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
function test_setAndTypeCustomValue() {
|
|
|
|
verify(!!controlUnderTest)
|
|
|
|
const customButton = findChild(controlUnderTest, "customButton")
|
|
|
|
verify(!!customButton)
|
|
|
|
mouseClick(customButton)
|
|
|
|
const customInput = findChild(controlUnderTest, "customInput")
|
|
|
|
verify(!!customInput)
|
|
|
|
tryCompare(customInput, "cursorVisible", true)
|
|
|
|
|
|
|
|
// input "1.42"
|
|
|
|
keyClick(Qt.Key_1)
|
|
|
|
keyClick(Qt.Key_Period)
|
|
|
|
keyClick(Qt.Key_4)
|
|
|
|
keyClick(Qt.Key_2)
|
|
|
|
|
2024-05-27 17:37:22 +00:00
|
|
|
tryCompare(controlUnderTest, "value", 1.42)
|
2024-05-23 08:08:18 +00:00
|
|
|
verify(controlUnderTest.valid)
|
|
|
|
|
|
|
|
// delete contents (4x)
|
|
|
|
keyClick(Qt.Key_Backspace)
|
|
|
|
keyClick(Qt.Key_Backspace)
|
|
|
|
keyClick(Qt.Key_Backspace)
|
|
|
|
keyClick(Qt.Key_Backspace)
|
|
|
|
|
|
|
|
tryCompare(customInput, "text", "")
|
|
|
|
tryCompare(customInput, "valid", false)
|
|
|
|
tryCompare(controlUnderTest, "valid", false)
|
|
|
|
|
|
|
|
// click again the first button
|
|
|
|
const buttonsRepeater = findChild(controlUnderTest, "buttonsRepeater")
|
|
|
|
verify(!!buttonsRepeater)
|
2024-05-27 17:37:22 +00:00
|
|
|
waitForRendering(buttonsRepeater)
|
2024-05-23 08:08:18 +00:00
|
|
|
const firstButton = buttonsRepeater.itemAt(0)
|
|
|
|
verify(!!firstButton)
|
|
|
|
mouseClick(firstButton)
|
2024-05-27 17:37:22 +00:00
|
|
|
tryCompare(controlUnderTest, "value", firstButton.value)
|
2024-05-23 08:08:18 +00:00
|
|
|
verify(controlUnderTest.valid)
|
2024-08-30 19:00:39 +00:00
|
|
|
tryCompare(customButton, "visible", true)
|
|
|
|
tryCompare(customInput, "visible", false)
|
2024-05-23 08:08:18 +00:00
|
|
|
}
|
|
|
|
|
2024-08-30 19:00:39 +00:00
|
|
|
function test_setCustomValue_data() {
|
|
|
|
return [
|
|
|
|
{tag: "valid", value: 1.42, valid: true},
|
|
|
|
{tag: "invalid", value: 111.42, valid: false},
|
|
|
|
]
|
|
|
|
}
|
|
|
|
|
|
|
|
function test_setCustomValue(data) {
|
|
|
|
const theValue = data.value
|
2024-05-23 08:08:18 +00:00
|
|
|
|
|
|
|
verify(!!controlUnderTest)
|
|
|
|
verify(controlUnderTest.valid)
|
2024-05-27 17:37:22 +00:00
|
|
|
controlUnderTest.value = theValue
|
|
|
|
|
2024-05-23 08:08:18 +00:00
|
|
|
const customInput = findChild(controlUnderTest, "customInput")
|
|
|
|
verify(!!customInput)
|
|
|
|
tryCompare(customInput, "cursorVisible", true)
|
2024-05-27 17:37:22 +00:00
|
|
|
tryCompare(customInput, "value", theValue)
|
2024-08-30 19:00:39 +00:00
|
|
|
tryCompare(customInput, "text", customInput.asString)
|
2024-05-27 17:37:22 +00:00
|
|
|
|
|
|
|
verify(controlUnderTest.value, theValue)
|
2024-08-30 19:00:39 +00:00
|
|
|
compare(controlUnderTest.valid, data.valid)
|
|
|
|
}
|
|
|
|
|
|
|
|
function test_setCustomValueAndReset_data() {
|
|
|
|
return [
|
|
|
|
{tag: "valid", value: 1.42, valid: true, isDefault: false},
|
|
|
|
{tag: "default", value: 0.5, valid: true, isDefault: true},
|
|
|
|
{tag: "invalid", value: 111.42, valid: false, isDefault: false},
|
|
|
|
]
|
|
|
|
}
|
|
|
|
|
|
|
|
function test_setCustomValueAndReset(data) {
|
|
|
|
verify(!!controlUnderTest)
|
|
|
|
|
|
|
|
let defaultValue = NaN
|
|
|
|
let defaultButton = null
|
|
|
|
const isDefault = data.isDefault
|
|
|
|
|
|
|
|
// get the default (checked/selected) button and value
|
|
|
|
const buttonsRepeater = findChild(controlUnderTest, "buttonsRepeater")
|
|
|
|
verify(!!buttonsRepeater)
|
|
|
|
for (let i = 0; i < buttonsRepeater.count; i++) {
|
|
|
|
const button = buttonsRepeater.itemAt(i)
|
|
|
|
if (button && button.checked) {
|
|
|
|
defaultButton = button
|
|
|
|
defaultValue = button.value
|
|
|
|
break
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
verify(!!defaultButton)
|
|
|
|
verify(defaultValue !== NaN)
|
|
|
|
|
|
|
|
// verify that by default, the custom button is visible, and custom input not
|
|
|
|
const customButton = findChild(controlUnderTest, "customButton")
|
|
|
|
verify(!!customButton)
|
|
|
|
tryCompare(customButton, "visible", true)
|
|
|
|
const customInput = findChild(controlUnderTest, "customInput")
|
|
|
|
verify(!!customInput)
|
|
|
|
tryCompare(customInput, "visible", false)
|
|
|
|
tryCompare(controlUnderTest, "valid", true)
|
|
|
|
|
|
|
|
// assign a new (custom) value
|
|
|
|
const theValue = data.value
|
|
|
|
controlUnderTest.value = theValue
|
|
|
|
tryCompare(controlUnderTest, "valid", data.valid)
|
|
|
|
|
|
|
|
// verify the custom input has the new value (and text), and Custom button is not visible
|
|
|
|
tryCompare(customInput, "visible", !isDefault)
|
|
|
|
tryCompare(customInput, "activeFocus", !isDefault)
|
|
|
|
tryCompare(customButton, "visible", isDefault)
|
|
|
|
if (!isDefault) {
|
|
|
|
tryCompare(customInput, "value", theValue)
|
|
|
|
tryCompare(customInput, "text", customInput.asString)
|
|
|
|
}
|
|
|
|
|
|
|
|
// call reset()
|
|
|
|
controlUnderTest.reset()
|
|
|
|
|
|
|
|
// verify that after reset, the Custom button is back
|
|
|
|
tryCompare(customInput, "visible", false)
|
|
|
|
tryCompare(customInput, "activeFocus", false)
|
|
|
|
tryCompare(customButton, "visible", true)
|
|
|
|
|
|
|
|
// verify that the button with default value is selected again
|
|
|
|
tryCompare(defaultButton, "checked", true)
|
|
|
|
tryCompare(controlUnderTest, "value", defaultValue)
|
|
|
|
tryCompare(controlUnderTest, "valid", true)
|
2024-05-23 08:08:18 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
function test_resetDefaults() {
|
|
|
|
verify(!!controlUnderTest)
|
2024-05-27 17:37:22 +00:00
|
|
|
const initialValue = controlUnderTest.value
|
2024-05-23 08:08:18 +00:00
|
|
|
const buttonsRepeater = findChild(controlUnderTest, "buttonsRepeater")
|
|
|
|
verify(!!buttonsRepeater)
|
2024-05-27 17:37:22 +00:00
|
|
|
waitForRendering(buttonsRepeater)
|
2024-05-23 08:08:18 +00:00
|
|
|
const firstButton = buttonsRepeater.itemAt(0)
|
2024-05-27 17:37:22 +00:00
|
|
|
waitForRendering(firstButton)
|
|
|
|
tryCompare(firstButton, "visible", true)
|
2024-05-23 08:08:18 +00:00
|
|
|
mouseClick(firstButton)
|
2024-05-27 17:37:22 +00:00
|
|
|
tryCompare(controlUnderTest, "value", firstButton.value)
|
2024-05-23 08:08:18 +00:00
|
|
|
|
|
|
|
controlUnderTest.reset()
|
2024-05-27 17:37:22 +00:00
|
|
|
tryCompare(controlUnderTest, "value", initialValue)
|
2024-05-23 08:08:18 +00:00
|
|
|
verify(controlUnderTest.valid)
|
|
|
|
|
|
|
|
const customButton = findChild(controlUnderTest, "customButton")
|
2024-05-27 17:37:22 +00:00
|
|
|
tryCompare(customButton, "visible", true)
|
2024-05-23 08:08:18 +00:00
|
|
|
|
2024-05-27 17:37:22 +00:00
|
|
|
const customInput = findChild(controlUnderTest, "customInput")
|
|
|
|
tryCompare(customInput, "visible", false)
|
2024-05-23 08:08:18 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|