Commit 64e5a70b authored by Ronan Abhamon's avatar Ronan Abhamon

feat(Utils): better style

parent d9b4dff2
...@@ -153,23 +153,6 @@ function openWindow (window, parent, options) { ...@@ -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. // Test if a point is in a item.
// //
// `source` is the item that generated the point. // `source` is the item that generated the point.
...@@ -203,6 +186,23 @@ function qmlTypeof (object, className) { ...@@ -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. // GENERIC.
// =================================================================== // ===================================================================
......
...@@ -10,6 +10,37 @@ import './utils.js' as Utils ...@@ -10,6 +10,37 @@ import './utils.js' as Utils
TestCase { TestCase {
id: 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. // Test only if a confirm dialog can be opened.
// The other tests are launched by `ConfirmDialog.spec.qml`. // The other tests are launched by `ConfirmDialog.spec.qml`.
function test_openConfirmDialog () { function test_openConfirmDialog () {
...@@ -33,6 +64,33 @@ TestCase { ...@@ -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 () { function test_setTimeoutWithoutParent () {
try { try {
Utils.setTimeout(null, 0, function () { Utils.setTimeout(null, 0, function () {
...@@ -67,61 +125,9 @@ TestCase { ...@@ -67,61 +125,9 @@ TestCase {
} }
} }
// ----------------------------------------------------------------- // =================================================================
// GENERIC.
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)
}
// -----------------------------------------------------------------
function test_genRandomNumber_data () { function test_genRandomNumber_data () {
return [ return [
......
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