mirror of
https://gitlab.linphone.org/BC/public/linphone-desktop.git
synced 2026-02-07 15:08:24 +00:00
feat(utils.spec.qml): add tests on clearTimeout, isString
This commit is contained in:
parent
cb131ed71f
commit
5d65384b97
2 changed files with 76 additions and 3 deletions
|
|
@ -50,8 +50,6 @@ function openWindow (window, parent, options) {
|
|||
object.show()
|
||||
}
|
||||
|
||||
// -------------------------------------------------------------------
|
||||
|
||||
// Display a simple ConfirmDialog component.
|
||||
// Wrap the openWindow function.
|
||||
function openConfirmDialog (parent, options) {
|
||||
|
|
@ -71,6 +69,15 @@ function openConfirmDialog (parent, options) {
|
|||
|
||||
// -------------------------------------------------------------------
|
||||
|
||||
function _computeOptimizedCb (func, context) {
|
||||
return (context != null)
|
||||
? (function () {
|
||||
return func.apply(context, arguments)
|
||||
}) : func
|
||||
}
|
||||
|
||||
// -------------------------------------------------------------------
|
||||
|
||||
function snakeToCamel (s) {
|
||||
return s.replace(/(\_\w)/g, function (matches) {
|
||||
return matches[1].toUpperCase()
|
||||
|
|
@ -97,7 +104,21 @@ function setTimeout (delay, cb) {
|
|||
}
|
||||
|
||||
function clearTimeout (timer) {
|
||||
timer.destroy() // Unnecessary call: `timer.stop()`
|
||||
timer.stop() // NECESSARY.
|
||||
timer.destroy()
|
||||
}
|
||||
|
||||
// -------------------------------------------------------------------
|
||||
|
||||
function times (n, cb, context) {
|
||||
var arr = Array(Math.max(0, n))
|
||||
cb = _computeOptimizedCb(cb, context, 1)
|
||||
|
||||
for (var i = 0; i < n; i++) {
|
||||
arr[i] = cb(i)
|
||||
}
|
||||
|
||||
return arr
|
||||
}
|
||||
|
||||
// -------------------------------------------------------------------
|
||||
|
|
|
|||
|
|
@ -25,6 +25,8 @@ TestCase {
|
|||
compare(Utils.snakeToCamel(data.input), data.output)
|
||||
}
|
||||
|
||||
// -----------------------------------------------------------------
|
||||
|
||||
function test_setTimeoutWithoutParent () {
|
||||
try {
|
||||
Utils.setTimeout(0, function () {
|
||||
|
|
@ -58,4 +60,54 @@ TestCase {
|
|||
fail('`setTimeout` failed because callback it was not called in due course')
|
||||
}
|
||||
}
|
||||
|
||||
// -----------------------------------------------------------------
|
||||
|
||||
function test_clearTimeout_data () {
|
||||
return [
|
||||
{ time: 0 },
|
||||
{ time: 100 }
|
||||
]
|
||||
}
|
||||
|
||||
function test_clearTimeout (data) {
|
||||
var failed = false
|
||||
var timeout = Utils.setTimeout.call(testCase, data.time, function () {
|
||||
failed = true
|
||||
})
|
||||
|
||||
// Simulate time
|
||||
Utils.times(500000, function (i) {
|
||||
// Nothing.
|
||||
})
|
||||
|
||||
if (failed) {
|
||||
fail('`setTimeout` callback was called')
|
||||
}
|
||||
|
||||
Utils.clearTimeout(timeout)
|
||||
wait(100)
|
||||
|
||||
if (failed) {
|
||||
fail('`setTimeout` callback was called')
|
||||
}
|
||||
}
|
||||
|
||||
// -----------------------------------------------------------------
|
||||
|
||||
function test_isString_data () {
|
||||
return [
|
||||
{ input: 'foo', output: true },
|
||||
{ input: Object('bar'), output: true },
|
||||
{ input: [ 0 ], output: false },
|
||||
{ input: /baz/, output: false },
|
||||
{ input: new Error, output: false },
|
||||
{ input: true, output: false },
|
||||
{ input: 42, output: false }
|
||||
]
|
||||
}
|
||||
|
||||
function test_isString (data) {
|
||||
compare(Utils.isString(data.input), data.output)
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue