Commit 6705553a authored by Ronan Abhamon's avatar Ronan Abhamon

feat(Form/ExclusiveButtons): add spec file to test emitted signals

parent 4694dbdb
...@@ -8,20 +8,15 @@ TestCase { ...@@ -8,20 +8,15 @@ TestCase {
name: 'ConfirmDialogTests' name: 'ConfirmDialogTests'
function createDialog () { Component {
var component = Qt.createComponent( id: builder
'./ConfirmDialog.qml'
) ConfirmDialog {}
}
if (component.status !== Component.Ready) {
if(component.status === Component.Error) { function buildConfirmDialog () {
fail('Error:' + component.errorString()) var dialog = builder.createObject(testCase)
} else { verify(dialog)
fail('Dialog not ready.')
}
}
var dialog = component.createObject(testCase)
dialog.closing.connect(dialog.destroy.bind(dialog)) dialog.closing.connect(dialog.destroy.bind(dialog))
return dialog return dialog
} }
...@@ -34,7 +29,7 @@ TestCase { ...@@ -34,7 +29,7 @@ TestCase {
} }
function test_exitStatusViaButtons (data) { function test_exitStatusViaButtons (data) {
var dialog = createDialog() var dialog = buildConfirmDialog()
dialog.exitStatus.connect(function (status) { dialog.exitStatus.connect(function (status) {
compare(status, data.expectedStatus) compare(status, data.expectedStatus)
...@@ -44,7 +39,7 @@ TestCase { ...@@ -44,7 +39,7 @@ TestCase {
} }
function test_exitStatusViaClose () { function test_exitStatusViaClose () {
var dialog = createDialog() var dialog = buildConfirmDialog()
dialog.exitStatus.connect(function (status) { dialog.exitStatus.connect(function (status) {
compare(status, 0) compare(status, 0)
......
...@@ -9,7 +9,7 @@ Row { ...@@ -9,7 +9,7 @@ Row {
property var texts property var texts
property int _selectedButton: 0 property int selectedButton: 0
signal clicked (int button) signal clicked (int button)
...@@ -20,7 +20,7 @@ Row { ...@@ -20,7 +20,7 @@ Row {
SmallButton { SmallButton {
anchors.verticalCenter: parent.verticalCenter anchors.verticalCenter: parent.verticalCenter
backgroundColor: _selectedButton === index backgroundColor: selectedButton === index
? ExclusiveButtonsStyle.button.color.selected ? ExclusiveButtonsStyle.button.color.selected
: (down : (down
? ExclusiveButtonsStyle.button.color.pressed ? ExclusiveButtonsStyle.button.color.pressed
...@@ -32,8 +32,8 @@ Row { ...@@ -32,8 +32,8 @@ Row {
text: modelData text: modelData
onClicked: { onClicked: {
if (_selectedButton !== index) { if (selectedButton !== index) {
_selectedButton = index selectedButton = index
item.clicked(index) item.clicked(index)
} }
} }
......
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 { ...@@ -16,7 +16,7 @@ Item {
function _createMouseArea () { function _createMouseArea () {
if (_mouseArea == null) { if (_mouseArea == null) {
_mouseArea = builder.createObject(this) _mouseArea = builder.createObject()
} }
_mouseArea.parent = (function () { _mouseArea.parent = (function () {
......
...@@ -38,7 +38,7 @@ Rectangle { ...@@ -38,7 +38,7 @@ Rectangle {
layer { layer {
enabled: true enabled: true
effect: PopupShadow { } effect: PopupShadow {}
} }
} }
} }
...@@ -6,7 +6,7 @@ import Common 1.0 ...@@ -6,7 +6,7 @@ import Common 1.0
// =================================================================== // ===================================================================
ListView { ListView {
ScrollBar.vertical: ForceScrollBar { } ScrollBar.vertical: ForceScrollBar {}
boundsBehavior: Flickable.StopAtBounds boundsBehavior: Flickable.StopAtBounds
clip: true clip: true
spacing: 0 spacing: 0
......
...@@ -68,7 +68,7 @@ ColumnLayout { ...@@ -68,7 +68,7 @@ ColumnLayout {
Flickable { Flickable {
Layout.fillHeight: true Layout.fillHeight: true
Layout.fillWidth: true Layout.fillWidth: true
ScrollBar.vertical: ForceScrollBar { } ScrollBar.vertical: ForceScrollBar {}
boundsBehavior: Flickable.StopAtBounds boundsBehavior: Flickable.StopAtBounds
clip: true clip: true
contentHeight: content.height contentHeight: content.height
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment