Skip to content

Commit

Permalink
add tests
Browse files Browse the repository at this point in the history
  • Loading branch information
joshday committed Apr 24, 2024
1 parent fb13b94 commit 1802bfb
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 1 deletion.
1 change: 0 additions & 1 deletion src/PlotlyLight.jl
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,6 @@ Base.@kwdef mutable struct Settings
style::Dict{String,String} = Dict("display" => "block", "border" => "none", "min-height" => "350px", "min-width" => "350px")
end
settings::Settings = Settings()
set!(; kw...) = foreach(x -> setfield!(settings, x...), kw)

#-----------------------------------------------------------------------------# utils
fix_matrix(x::Config) = Config(k => fix_matrix(v) for (k,v) in pairs(x))
Expand Down
32 changes: 32 additions & 0 deletions test/runtests.jl
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ using PlotlyLight
using PlotlyLight: settings
using Cobweb
using Cobweb: h
using JSON3: JSON3
using Test
using Aqua

Expand Down Expand Up @@ -30,20 +31,51 @@ html(x) = repr("text/html", x)
p4(;x=1:10, y=1:10)
@test length(p4.data) == 3
@test p4.data[2] == p4.data[3]

p5 = p(p2(p3(p4)))
@test length(p5.data) == 6
end

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

@testset "settings" begin
@test PlotlyLight.settings.layout == Config()
@test PlotlyLight.settings.config == Config(; responsive=true)
end

@testset "saving" begin
dir = mktempdir()
path1 = joinpath(dir, "test.html")
path2 = joinpath(dir, "test2.html")
p = Plot(Config(x = 1:10))
PlotlyLight.save(p, path1)
PlotlyLight.save(path2, p)
@test isfile(path1)
@test isfile(path2)
end

@testset "other" begin
@test propertynames(Plot()) isa Vector{Symbol}
@test all(x in propertynames(Plot()) for x in propertynames(plot))
@test PlotlyLight.fix_matrix([1 2; 3 4]) == [[1, 2], [3, 4]]
@test propertynames(JSON3.read(JSON3.write(Plot()))) == [:data, :layout, :config]
end

@testset "show/display" begin
s = sprint((io, x) -> show(io, MIME("juliavscode/html"), x), Plot())
end

@testset "preset" begin
for f in PlotlyLight.preset.template
f()
end
for f in PlotlyLight.preset.source
f()
end
end

#-----------------------------------------------------------------------------# Aqua
Expand Down

0 comments on commit 1802bfb

Please sign in to comment.