-
-
Notifications
You must be signed in to change notification settings - Fork 74
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #208 from travigd/td/fix-webio-integration
Fix WebIO integration, make Window's sync by default.
- Loading branch information
Showing
3 changed files
with
97 additions
and
17 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,59 @@ | ||
using Test | ||
using Blink | ||
using WebIO | ||
|
||
""" | ||
Execute function f() with a timeout of `timeout` seconds. Returns the | ||
result of f() or `nothing` in the case of a timeout. | ||
""" | ||
function with_timeout(f::Function, timeout) | ||
c = Channel{Any}(1) | ||
@async begin | ||
put!(c, f()) | ||
end | ||
@async begin | ||
sleep(timeout) | ||
put!(c, nothing) | ||
end | ||
take!(c) | ||
end | ||
|
||
@testset "WebIO integration" begin | ||
@testset "mount test" begin | ||
w = Window(Dict(:show => false)) | ||
mounted = Channel(false) | ||
setmounted = () -> push!(mounted, true) | ||
scope = Scope() | ||
onmount(scope, js""" | ||
function () { | ||
$setmounted() | ||
} | ||
""") | ||
body!(w, scope) | ||
did_mount = with_timeout(() -> take!(mounted), 5) | ||
@test did_mount | ||
end | ||
|
||
@testset "button click" begin | ||
w = Window(Dict(:show => false)) | ||
scope = Scope() | ||
obs = Observable(scope, "obs", false) | ||
obschannel = Channel(1) | ||
on((x) -> push!(obschannel, x), obs) | ||
scope(dom"button#mybutton"( | ||
events=Dict( | ||
"click" => @js function() | ||
$obs[] = true | ||
end | ||
) | ||
)) | ||
body!(w, scope) | ||
|
||
# Sleep to allow WebIO scope to mount in Electron | ||
sleep(0.25) | ||
|
||
@js w document.querySelector("#mybutton").click() | ||
did_click = with_timeout(() -> take!(obschannel), 5) | ||
@test did_click | ||
end | ||
end |