Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
L
linphone-desktop
Project
Project
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Administrator
linphone-desktop
Commits
5d65384b
Commit
5d65384b
authored
Oct 19, 2016
by
Ronan Abhamon
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
feat(utils.spec.qml): add tests on `clearTimeout`, `isString`
parent
cb131ed7
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
76 additions
and
3 deletions
+76
-3
utils.js
tests/ui/scripts/Utils/utils.js
+24
-3
utils.spec.qml
tests/ui/scripts/Utils/utils.spec.qml
+52
-0
No files found.
tests/ui/scripts/Utils/utils.js
View file @
5d65384b
...
...
@@ -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
}
// -------------------------------------------------------------------
...
...
tests/ui/scripts/Utils/utils.spec.qml
View file @
5d65384b
...
...
@@ -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
)
}
}
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment