2022-03-10 18:49:42 +00:00
|
|
|
import QtQuick 2.0
|
|
|
|
import QtTest 1.0
|
|
|
|
|
|
|
|
import StatusQ.Controls 0.1
|
|
|
|
import StatusQ.Controls.Validators 0.1
|
|
|
|
|
2022-03-21 11:04:11 +00:00
|
|
|
import StatusQ.TestHelpers 0.1
|
|
|
|
|
2022-03-10 18:49:42 +00:00
|
|
|
Item {
|
|
|
|
width: 300
|
|
|
|
height: 100
|
|
|
|
|
|
|
|
property int _defaultValidationMode
|
|
|
|
|
|
|
|
Component.onCompleted: {
|
|
|
|
_defaultValidationMode = statusInput.validationMode
|
|
|
|
}
|
|
|
|
StatusInput {
|
|
|
|
id: statusInput
|
|
|
|
label: "Control under test"
|
|
|
|
charLimit: 30
|
|
|
|
input.placeholderText: `Must match regex(${validators[0].regularExpression.toString()}) and <= 30 chars`
|
|
|
|
focus: true
|
|
|
|
|
|
|
|
validators: [
|
|
|
|
StatusRegularExpressionValidator {
|
|
|
|
regularExpression: /^[0-9A-Za-z_\$-\s]*$/
|
|
|
|
}
|
|
|
|
]
|
|
|
|
}
|
|
|
|
|
|
|
|
TestCase {
|
2022-03-21 11:04:11 +00:00
|
|
|
id: regexTC
|
|
|
|
|
2022-03-10 18:49:42 +00:00
|
|
|
name: "RegexValidationTest"
|
|
|
|
|
|
|
|
when: windowShown
|
|
|
|
|
|
|
|
//
|
|
|
|
// Test guards
|
2022-04-19 17:45:26 +00:00
|
|
|
function init() {
|
|
|
|
qtOuput.restartCapturing()
|
2022-03-10 18:49:42 +00:00
|
|
|
mouseClick(statusInput)
|
|
|
|
}
|
|
|
|
|
|
|
|
function cleanup() {
|
|
|
|
statusInput.text = ""
|
|
|
|
statusInput.validationMode = _defaultValidationMode
|
|
|
|
}
|
|
|
|
|
|
|
|
//
|
|
|
|
// Tests
|
|
|
|
function test_initial_empty_is_valid() {
|
|
|
|
verify(statusInput.valid, "Expected valid input")
|
|
|
|
}
|
|
|
|
|
|
|
|
function test_regex_validation() {
|
2022-03-21 11:04:11 +00:00
|
|
|
TestUtils.pressKeyAndWait(regexTC, statusInput, Qt.Key_1)
|
2022-03-10 18:49:42 +00:00
|
|
|
verify(statusInput.valid, "Expected valid input")
|
2022-03-21 11:04:11 +00:00
|
|
|
TestUtils.pressKeyAndWait(regexTC, statusInput, Qt.Key_Ampersand)
|
2022-03-10 18:49:42 +00:00
|
|
|
verify(!statusInput.valid, "Expected invalid input")
|
|
|
|
}
|
|
|
|
|
|
|
|
function test_no_invalid_input() {
|
|
|
|
statusInput.validationMode = StatusInput.ValidationMode.IgnoreInvalidInput
|
|
|
|
|
|
|
|
verify(statusInput.valid, "Expected valid input")
|
|
|
|
verify(statusInput.text.length === 0, "Expected no input")
|
2022-03-21 11:04:11 +00:00
|
|
|
TestUtils.pressKeyAndWait(regexTC, statusInput, Qt.Key_2)
|
2022-03-10 18:49:42 +00:00
|
|
|
verify(statusInput.valid, "Expected valid input")
|
|
|
|
verify(statusInput.text === "2", "Expect one character")
|
2022-03-21 11:04:11 +00:00
|
|
|
TestUtils.pressKeyAndWait(regexTC, statusInput, Qt.Key_Ampersand)
|
2022-03-10 18:49:42 +00:00
|
|
|
verify(statusInput.valid, "Expected invalid input")
|
|
|
|
verify(statusInput.text === "2", "Expect the same input")
|
|
|
|
}
|
|
|
|
|
|
|
|
// Use case expected in case new validation changes are enabled with old unvalid data
|
|
|
|
function test_user_can_delete_initial_invalid_input() {
|
|
|
|
const appendInvalidChars = "#@!*"
|
|
|
|
|
|
|
|
statusInput.text = "invalid $" + appendInvalidChars
|
2022-03-21 11:04:11 +00:00
|
|
|
TestUtils.pressKeyAndWait(regexTC, statusInput, Qt.Key_End)
|
2022-03-10 18:49:42 +00:00
|
|
|
verify(!statusInput.valid, "Expected invalid input due to characters not matching")
|
|
|
|
// Delete invalid characters to get a valid text
|
|
|
|
for(let i = 0; i < appendInvalidChars.length; ++i)
|
2022-03-21 11:04:11 +00:00
|
|
|
TestUtils.pressKeyAndWait(regexTC, statusInput, Qt.Key_Backspace)
|
2022-03-10 18:49:42 +00:00
|
|
|
verify(statusInput.valid, "Expected valid input")
|
|
|
|
}
|
|
|
|
}
|
2022-03-21 11:04:11 +00:00
|
|
|
|
|
|
|
TestCase {
|
|
|
|
id: qmlWarnTC
|
|
|
|
|
2022-05-03 12:16:22 +00:00
|
|
|
name: "StatusInput"
|
2022-03-21 11:04:11 +00:00
|
|
|
|
|
|
|
when: windowShown
|
|
|
|
|
|
|
|
//
|
|
|
|
// Test guards
|
|
|
|
|
|
|
|
function initTestCase() {
|
|
|
|
}
|
|
|
|
|
|
|
|
function cleanup() {
|
|
|
|
statusInput.text = ""
|
|
|
|
statusInput.validationMode = _defaultValidationMode
|
|
|
|
}
|
|
|
|
|
|
|
|
//
|
|
|
|
// Tests
|
|
|
|
|
|
|
|
function test_initial_empty_is_valid() {
|
|
|
|
mouseClick(statusInput)
|
|
|
|
verify(qtOuput.qtOuput().length === 0, `No output expected. Found:\n"${qtOuput.qtOuput()}"\n`)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
MonitorQtOutput {
|
|
|
|
id: qtOuput
|
|
|
|
}
|
2022-03-10 18:49:42 +00:00
|
|
|
}
|