Commit 3a8bf11f authored by Ronan Abhamon's avatar Ronan Abhamon

feat(InvertedMouseArea.spec.qml): add fixed tests (outside/inside clicks)

parent 47c733bb
...@@ -32,18 +32,17 @@ Rectangle { ...@@ -32,18 +32,17 @@ Rectangle {
id: spy id: spy
signalName: 'pressed' signalName: 'pressed'
target: invertedMouseArea
} }
TestCase { TestCase {
when: windowShown when: windowShown
function test_randomInsideMouseArea () { function init () {
var failFun = function () { spy.clear()
fail('`pressed` signal was emitted.') }
}
invertedMouseArea.pressed.connect(failFun)
function test_randomClickInsideMouseArea () {
Utils.times(100, function () { Utils.times(100, function () {
var x = Math.floor(Utils.genRandomNumber(item.x, item.x + width)) var x = Math.floor(Utils.genRandomNumber(item.x, item.x + width))
var y = Math.floor(Utils.genRandomNumber(item.y, item.y + height)) var y = Math.floor(Utils.genRandomNumber(item.y, item.y + height))
...@@ -52,12 +51,12 @@ Rectangle { ...@@ -52,12 +51,12 @@ Rectangle {
}) })
wait(100) wait(100)
invertedMouseArea.pressed.disconnect(failFun) compare(spy.count, 0, '`pressed` signal was emitted')
} }
function test_randomOutsideMouseArea () { // ---------------------------------------------------------------
spy.target = invertedMouseArea
function test_randomClickOutsideMouseArea () {
Utils.times(50, function () { Utils.times(50, function () {
var x = Math.floor(Utils.genRandomNumberBetweenIntervals([ var x = Math.floor(Utils.genRandomNumberBetweenIntervals([
[ 0, item.x ], [ item.x + item.width, root.width ] [ 0, item.x ], [ item.x + item.width, root.width ]
...@@ -80,5 +79,39 @@ Rectangle { ...@@ -80,5 +79,39 @@ Rectangle {
spy.wait(100) spy.wait(100)
}) })
} }
// ---------------------------------------------------------------
function test_clickInsideMouseArea_data () {
return [
{ x: item.x, y: item.y },
{ x: item.x + item.width - 1, y: item.y },
{ x: item.x, y: item.y + item.height - 1},
{ x: item.x + item.width - 1, y: item.y + item.height - 1 },
{ } // item center.
]
}
function test_clickInsideMouseArea (data) {
mouseClick(root, data.x, data.y)
wait(100)
compare(spy.count, 0, '`pressed` signal was emitted')
}
// ---------------------------------------------------------------
function test_clickOutsideMouseArea_data () {
return [
{ x: item.x - 1, y: item.y - 1},
{ x: item.x + item.width, y: item.y },
{ x: item.x, y: item.y + item.height },
{ x: item.x + item.width, y: item.y + item.height }
]
}
function test_clickOutsideMouseArea (data) {
mouseClick(root, data.x, data.y)
spy.wait(100)
}
} }
} }
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