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-05-27 17:37:22 +00:00
|
|
|
function test_setCustomValue() {
|
|
|
|
const theValue = 1.42
|
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)
|
|
|
|
|
|
|
|
verify(controlUnderTest.value, theValue)
|
|
|
|
verify(controlUnderTest.valid)
|
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
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|