mirror of
https://gitlab.linphone.org/BC/public/linphone-desktop.git
synced 2026-05-07 14:44:01 +00:00
feat(Form/ExclusiveButtons): add spec file to test emitted signals
This commit is contained in:
parent
4694dbdb73
commit
6705553a40
7 changed files with 97 additions and 22 deletions
|
|
@ -8,20 +8,15 @@ TestCase {
|
|||
|
||||
name: 'ConfirmDialogTests'
|
||||
|
||||
function createDialog () {
|
||||
var component = Qt.createComponent(
|
||||
'./ConfirmDialog.qml'
|
||||
)
|
||||
Component {
|
||||
id: builder
|
||||
|
||||
if (component.status !== Component.Ready) {
|
||||
if(component.status === Component.Error) {
|
||||
fail('Error:' + component.errorString())
|
||||
} else {
|
||||
fail('Dialog not ready.')
|
||||
}
|
||||
}
|
||||
ConfirmDialog {}
|
||||
}
|
||||
|
||||
var dialog = component.createObject(testCase)
|
||||
function buildConfirmDialog () {
|
||||
var dialog = builder.createObject(testCase)
|
||||
verify(dialog)
|
||||
dialog.closing.connect(dialog.destroy.bind(dialog))
|
||||
return dialog
|
||||
}
|
||||
|
|
@ -34,7 +29,7 @@ TestCase {
|
|||
}
|
||||
|
||||
function test_exitStatusViaButtons (data) {
|
||||
var dialog = createDialog()
|
||||
var dialog = buildConfirmDialog()
|
||||
|
||||
dialog.exitStatus.connect(function (status) {
|
||||
compare(status, data.expectedStatus)
|
||||
|
|
@ -44,7 +39,7 @@ TestCase {
|
|||
}
|
||||
|
||||
function test_exitStatusViaClose () {
|
||||
var dialog = createDialog()
|
||||
var dialog = buildConfirmDialog()
|
||||
|
||||
dialog.exitStatus.connect(function (status) {
|
||||
compare(status, 0)
|
||||
|
|
|
|||
|
|
@ -9,7 +9,7 @@ Row {
|
|||
|
||||
property var texts
|
||||
|
||||
property int _selectedButton: 0
|
||||
property int selectedButton: 0
|
||||
|
||||
signal clicked (int button)
|
||||
|
||||
|
|
@ -20,7 +20,7 @@ Row {
|
|||
|
||||
SmallButton {
|
||||
anchors.verticalCenter: parent.verticalCenter
|
||||
backgroundColor: _selectedButton === index
|
||||
backgroundColor: selectedButton === index
|
||||
? ExclusiveButtonsStyle.button.color.selected
|
||||
: (down
|
||||
? ExclusiveButtonsStyle.button.color.pressed
|
||||
|
|
@ -32,8 +32,8 @@ Row {
|
|||
text: modelData
|
||||
|
||||
onClicked: {
|
||||
if (_selectedButton !== index) {
|
||||
_selectedButton = index
|
||||
if (selectedButton !== index) {
|
||||
selectedButton = index
|
||||
item.clicked(index)
|
||||
}
|
||||
}
|
||||
|
|
|
|||
80
tests/ui/modules/Common/Form/ExclusiveButtons.spec.qml
Normal file
80
tests/ui/modules/Common/Form/ExclusiveButtons.spec.qml
Normal file
|
|
@ -0,0 +1,80 @@
|
|||
import QtQuick 2.7
|
||||
import QtTest 1.1
|
||||
|
||||
// ===================================================================
|
||||
|
||||
Item {
|
||||
id: root
|
||||
|
||||
Component {
|
||||
id: builder
|
||||
|
||||
Item {
|
||||
ExclusiveButtons {
|
||||
id: exclusiveButtons
|
||||
|
||||
texts: [
|
||||
qsTr('A'),
|
||||
qsTr('B'),
|
||||
qsTr('C'),
|
||||
qsTr('D'),
|
||||
qsTr('E')
|
||||
]
|
||||
}
|
||||
|
||||
SignalSpy {
|
||||
id: spy
|
||||
|
||||
signalName: 'clicked'
|
||||
target: exclusiveButtons
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
function buildExclusiveButtons (defaultSelectedButton) {
|
||||
var container = builder.createObject(root)
|
||||
testCase.verify(container)
|
||||
container.data[0].selectedButton = defaultSelectedButton
|
||||
return container
|
||||
}
|
||||
|
||||
TestCase {
|
||||
id: testCase
|
||||
|
||||
name: 'ExclusiveButtonsTests'
|
||||
when: windowShown
|
||||
|
||||
function test_signals_data () {
|
||||
return [
|
||||
{ defaultSelectedButton: 0, buttonToClick: 2 },
|
||||
{ defaultSelectedButton: 1, buttonToClick: 4 },
|
||||
{ defaultSelectedButton: 3, buttonToClick: 1 },
|
||||
{ defaultSelectedButton: 4, buttonToClick: 0 }
|
||||
]
|
||||
}
|
||||
|
||||
function test_signals (data) {
|
||||
var container = buildExclusiveButtons(data.defaultSelectedButton)
|
||||
var spy = container.data[1]
|
||||
var exclusiveButtons = container.data[0]
|
||||
|
||||
var buttonToClick = data.buttonToClick
|
||||
|
||||
// Test default selected button.
|
||||
compare(exclusiveButtons.selectedButton, data.defaultSelectedButton)
|
||||
|
||||
// Test a click to change the selected button.
|
||||
mouseClick(exclusiveButtons.data[buttonToClick])
|
||||
spy.wait(100)
|
||||
compare(spy.signalArguments[0][0], buttonToClick)
|
||||
compare(exclusiveButtons.selectedButton, buttonToClick)
|
||||
|
||||
// No signal must be emitted.
|
||||
mouseClick(exclusiveButtons.data[buttonToClick])
|
||||
wait(100)
|
||||
compare(spy.count, 1)
|
||||
|
||||
container.destroy()
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -16,7 +16,7 @@ Item {
|
|||
|
||||
function _createMouseArea () {
|
||||
if (_mouseArea == null) {
|
||||
_mouseArea = builder.createObject(this)
|
||||
_mouseArea = builder.createObject()
|
||||
}
|
||||
|
||||
_mouseArea.parent = (function () {
|
||||
|
|
|
|||
|
|
@ -38,7 +38,7 @@ Rectangle {
|
|||
|
||||
layer {
|
||||
enabled: true
|
||||
effect: PopupShadow { }
|
||||
effect: PopupShadow {}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -6,7 +6,7 @@ import Common 1.0
|
|||
// ===================================================================
|
||||
|
||||
ListView {
|
||||
ScrollBar.vertical: ForceScrollBar { }
|
||||
ScrollBar.vertical: ForceScrollBar {}
|
||||
boundsBehavior: Flickable.StopAtBounds
|
||||
clip: true
|
||||
spacing: 0
|
||||
|
|
|
|||
|
|
@ -68,7 +68,7 @@ ColumnLayout {
|
|||
Flickable {
|
||||
Layout.fillHeight: true
|
||||
Layout.fillWidth: true
|
||||
ScrollBar.vertical: ForceScrollBar { }
|
||||
ScrollBar.vertical: ForceScrollBar {}
|
||||
boundsBehavior: Flickable.StopAtBounds
|
||||
clip: true
|
||||
contentHeight: content.height
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue