Skip to content

Commit 1802bfb

Browse files
committed
add tests
1 parent fb13b94 commit 1802bfb

File tree

2 files changed

+32
-1
lines changed

2 files changed

+32
-1
lines changed

src/PlotlyLight.jl

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,6 @@ Base.@kwdef mutable struct Settings
3838
style::Dict{String,String} = Dict("display" => "block", "border" => "none", "min-height" => "350px", "min-width" => "350px")
3939
end
4040
settings::Settings = Settings()
41-
set!(; kw...) = foreach(x -> setfield!(settings, x...), kw)
4241

4342
#-----------------------------------------------------------------------------# utils
4443
fix_matrix(x::Config) = Config(k => fix_matrix(v) for (k,v) in pairs(x))

test/runtests.jl

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ using PlotlyLight
22
using PlotlyLight: settings
33
using Cobweb
44
using Cobweb: h
5+
using JSON3: JSON3
56
using Test
67
using Aqua
78

@@ -30,20 +31,51 @@ html(x) = repr("text/html", x)
3031
p4(;x=1:10, y=1:10)
3132
@test length(p4.data) == 3
3233
@test p4.data[2] == p4.data[3]
34+
35+
p5 = p(p2(p3(p4)))
36+
@test length(p5.data) == 6
3337
end
3438

3539
@testset "plot" begin
3640
@test_warn "`scatter` does not have attribute `X`" plot.scatter(X=1:10);
3741
@test_nowarn plot.scatter(x=1:10);
42+
@test contains(JSON3.write(plot(y=1:10)), "scatter")
3843
end
3944

4045
@testset "settings" begin
4146
@test PlotlyLight.settings.layout == Config()
4247
@test PlotlyLight.settings.config == Config(; responsive=true)
4348
end
4449

50+
@testset "saving" begin
51+
dir = mktempdir()
52+
path1 = joinpath(dir, "test.html")
53+
path2 = joinpath(dir, "test2.html")
54+
p = Plot(Config(x = 1:10))
55+
PlotlyLight.save(p, path1)
56+
PlotlyLight.save(path2, p)
57+
@test isfile(path1)
58+
@test isfile(path2)
59+
end
60+
4561
@testset "other" begin
4662
@test propertynames(Plot()) isa Vector{Symbol}
63+
@test all(x in propertynames(Plot()) for x in propertynames(plot))
64+
@test PlotlyLight.fix_matrix([1 2; 3 4]) == [[1, 2], [3, 4]]
65+
@test propertynames(JSON3.read(JSON3.write(Plot()))) == [:data, :layout, :config]
66+
end
67+
68+
@testset "show/display" begin
69+
s = sprint((io, x) -> show(io, MIME("juliavscode/html"), x), Plot())
70+
end
71+
72+
@testset "preset" begin
73+
for f in PlotlyLight.preset.template
74+
f()
75+
end
76+
for f in PlotlyLight.preset.source
77+
f()
78+
end
4779
end
4880

4981
#-----------------------------------------------------------------------------# Aqua

0 commit comments

Comments
 (0)