From 3a8bf11fd0fc44fc64154372bf13938a1718aefe Mon Sep 17 00:00:00 2001 From: Ronan Abhamon Date: Fri, 21 Oct 2016 16:42:34 +0200 Subject: [PATCH] feat(InvertedMouseArea.spec.qml): add fixed tests (outside/inside clicks) --- .../modules/Common/InvertedMouseArea.spec.qml | 51 +++++++++++++++---- 1 file changed, 42 insertions(+), 9 deletions(-) diff --git a/tests/ui/modules/Common/InvertedMouseArea.spec.qml b/tests/ui/modules/Common/InvertedMouseArea.spec.qml index 29f98d1f0..7f9b5025e 100644 --- a/tests/ui/modules/Common/InvertedMouseArea.spec.qml +++ b/tests/ui/modules/Common/InvertedMouseArea.spec.qml @@ -32,18 +32,17 @@ Rectangle { id: spy signalName: 'pressed' + target: invertedMouseArea } TestCase { when: windowShown - function test_randomInsideMouseArea () { - var failFun = function () { - fail('`pressed` signal was emitted.') - } - - invertedMouseArea.pressed.connect(failFun) + function init () { + spy.clear() + } + function test_randomClickInsideMouseArea () { Utils.times(100, function () { var x = Math.floor(Utils.genRandomNumber(item.x, item.x + width)) var y = Math.floor(Utils.genRandomNumber(item.y, item.y + height)) @@ -52,12 +51,12 @@ Rectangle { }) 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 () { var x = Math.floor(Utils.genRandomNumberBetweenIntervals([ [ 0, item.x ], [ item.x + item.width, root.width ] @@ -80,5 +79,39 @@ Rectangle { 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) + } } }