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 {
name: 'ConfirmDialogTests'
function createDialog () {
var component = Qt.createComponent(
'./ConfirmDialog.qml'
)
if (component.status !== Component.Ready) {
if(component.status === Component.Error) {
fail('Error:' + component.errorString())
} else {
fail('Dialog not ready.')
}
}
var dialog = component.createObject(testCase)
Component {
id: builder
ConfirmDialog {}
}
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)
}
}
......
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
......
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