From 0cfcb4c348e2ca30ea8f43d83ab0cfdb9c91ebe6 Mon Sep 17 00:00:00 2001 From: Spencer Lyon Date: Thu, 1 Feb 2018 11:38:39 -0500 Subject: [PATCH] TEST: add tests that use Blink frontend to test display methods and savefig routines --- src/PlotlyJS.jl | 2 +- src/displays/electron.jl | 2 +- test/REQUIRE | 1 + test/blink.jl | 118 +++++++++++++++++++++++++++++++++++++++ test/runtests.jl | 3 + 5 files changed, 124 insertions(+), 2 deletions(-) create mode 100644 test/blink.jl diff --git a/src/PlotlyJS.jl b/src/PlotlyJS.jl index 94e37519..d467d198 100644 --- a/src/PlotlyJS.jl +++ b/src/PlotlyJS.jl @@ -12,7 +12,7 @@ import PlotlyBase: restyle!, relayout!, update!, addtraces!, deletetraces!, movetraces!, redraw!, extendtraces!, prependtraces!, purge!, to_image, download_image, restyle, relayout, update, addtraces, deletetraces, movetraces, redraw, - extendtraces, prependtraces, prep_kwargs, sizes, savefig + extendtraces, prependtraces, prep_kwargs, sizes, savefig, _tovec using Blink using Requires diff --git a/src/displays/electron.jl b/src/displays/electron.jl index 400809c6..cfec47a6 100644 --- a/src/displays/electron.jl +++ b/src/displays/electron.jl @@ -293,7 +293,7 @@ function redraw!(p::ElectronDisplay) end function purge!(p::ElectronDisplay) - @js_ p begin reset_svg(); Plotly.purge(this).then(save_svg) end + @js_ p begin reset_svg(); Plotly.purge(this) end end function to_image(p::ElectronDisplay; kwargs...) diff --git a/test/REQUIRE b/test/REQUIRE index 4f9291d8..73a29362 100644 --- a/test/REQUIRE +++ b/test/REQUIRE @@ -1 +1,2 @@ TestSetExtensions 1.0 +Rsvg 0.2 diff --git a/test/blink.jl b/test/blink.jl new file mode 100644 index 00000000..a91218da --- /dev/null +++ b/test/blink.jl @@ -0,0 +1,118 @@ +using Blink + +p = plot(rand(10, 4)) +display(p) +w = PlotlyJS.get_window(p) +sleep(1.0) # make sure we give time for svg to render + +# test that plotly loads +@test isa(@js(p, Plotly), Dict) + +# test that svg is defined +@test isa(@js(p, $(PlotlyJS.svg_var(p))), String) + +# test that we get back reasonable svg +svg = @js(p, $(PlotlyJS.svg_var(p))) +@test svg[1:4] == "" + +@testset "api methods" begin + + @testset "to_image" begin + @test to_image(p)[1:21] == "data:image/png;base64" + @test to_image(p, format="svg")[1:18] == "data:image/svg+xml" + @test to_image(p, format="jpeg")[1:22] =="data:image/jpeg;base64" + @test to_image(p, format="webp")[1:22] =="data:image/webp;base64" + @test_throws Blink.JSError to_image(p, format="pdf") + @test to_image(p, imageDataOnly=true, format="svg")[1:4] == "