diff --git a/tests/ui/scripts/Utils/utils.js b/tests/ui/scripts/Utils/utils.js index f65b7fb00..e8ca823b8 100644 --- a/tests/ui/scripts/Utils/utils.js +++ b/tests/ui/scripts/Utils/utils.js @@ -153,23 +153,6 @@ function openWindow (window, parent, options) { // ------------------------------------------------------------------- -// A copy of `Window.setTimeout` from js. -// delay is in milliseconds. -function setTimeout (parent, delay, cb) { - var timer = new (function (parent) { - return Qt.createQmlObject('import QtQuick 2.7; Timer { }', parent) - })(parent) - - timer.interval = delay - timer.repeat = false - timer.triggered.connect(cb) - timer.start() - - return timer -} - -// ------------------------------------------------------------------- - // Test if a point is in a item. // // `source` is the item that generated the point. @@ -203,6 +186,23 @@ function qmlTypeof (object, className) { ) } +// ------------------------------------------------------------------- + +// A copy of `Window.setTimeout` from js. +// delay is in milliseconds. +function setTimeout (parent, delay, cb) { + var timer = new (function (parent) { + return Qt.createQmlObject('import QtQuick 2.7; Timer { }', parent) + })(parent) + + timer.interval = delay + timer.repeat = false + timer.triggered.connect(cb) + timer.start() + + return timer +} + // =================================================================== // GENERIC. // =================================================================== diff --git a/tests/ui/scripts/Utils/utils.spec.qml b/tests/ui/scripts/Utils/utils.spec.qml index bec022310..b0f9da4b7 100644 --- a/tests/ui/scripts/Utils/utils.spec.qml +++ b/tests/ui/scripts/Utils/utils.spec.qml @@ -10,6 +10,37 @@ import './utils.js' as Utils TestCase { id: testCase + // ================================================================= + // QML helpers. + // ================================================================= + + function test_clearTimeout_data () { + return [ + { time: 0 }, + { time: 100 } + ] + } + + function test_clearTimeout (data) { + var failed = false + var timeout = Utils.setTimeout(testCase, data.time, function () { + failed = true + }) + + if (failed) { + fail('`setTimeout` callback was called before `wait`.') + } + + Utils.clearTimeout(timeout) + wait(100) + + if (failed) { + fail('`setTimeout` callback was called after `wait`.') + } + } + + // ----------------------------------------------------------------- + // Test only if a confirm dialog can be opened. // The other tests are launched by `ConfirmDialog.spec.qml`. function test_openConfirmDialog () { @@ -33,6 +64,33 @@ TestCase { // ----------------------------------------------------------------- + function test_qmlTypeof_data () { + return [ + { + component: 'import QtQuick 2.7; ListModel {}', + result: true, + type: 'QQmlListModel' + }, { + component: 'import QtQuick 2.7; ListView {}', + result: true, + type: 'QQuickListView' + }, { + component: 'import QtQuick 2.7; MouseArea {}', + result: true, + type: 'QQuickMouseArea' + } + ] + } + + function test_qmlTypeof (data) { + var object = Qt.createQmlObject(data.component, testCase) + verify(object) + + compare(Utils.qmlTypeof(object, data.type), data.result) + } + + // ----------------------------------------------------------------- + function test_setTimeoutWithoutParent () { try { Utils.setTimeout(null, 0, function () { @@ -67,61 +125,9 @@ TestCase { } } - // ----------------------------------------------------------------- - - function test_clearTimeout_data () { - return [ - { time: 0 }, - { time: 100 } - ] - } - - function test_clearTimeout (data) { - var failed = false - var timeout = Utils.setTimeout(testCase, data.time, function () { - failed = true - }) - - if (failed) { - fail('`setTimeout` callback was called before `wait`.') - } - - Utils.clearTimeout(timeout) - wait(100) - - if (failed) { - fail('`setTimeout` callback was called after `wait`.') - } - } - - // ----------------------------------------------------------------- - - function test_qmlTypeof_data () { - return [ - { - component: 'import QtQuick 2.7; ListModel {}', - result: true, - type: 'QQmlListModel' - }, { - component: 'import QtQuick 2.7; ListView {}', - result: true, - type: 'QQuickListView' - }, { - component: 'import QtQuick 2.7; MouseArea {}', - result: true, - type: 'QQuickMouseArea' - } - ] - } - - function test_qmlTypeof (data) { - var object = Qt.createQmlObject(data.component, testCase) - verify(object) - - compare(Utils.qmlTypeof(object, data.type), data.result) - } - - // ----------------------------------------------------------------- + // ================================================================= + // GENERIC. + // ================================================================= function test_genRandomNumber_data () { return [