|
1 | 1 | include("../../utilities/prelude.jl")
|
2 | 2 |
|
3 |
| -test_example(joinpath(@__DIR__, "../../examples/integrations/ojs_define.qmd")) do json |
| 3 | +test_example( |
| 4 | + joinpath(@__DIR__, "../../examples/integrations/ojs_define/no_imports.qmd"), |
| 5 | +) do json |
4 | 6 | cells = json["cells"]
|
5 |
| - |
6 | 7 | cell = cells[2]
|
7 |
| - @test contains(cell["outputs"][1]["data"]["text/plain"], "ojs_define") |
| 8 | + @test length(cell["outputs"]) == 1 |
| 9 | + @test contains(cell["outputs"][1]["text"], "Please import either JSON.jl or JSON3.jl") |
| 10 | +end |
| 11 | + |
| 12 | +for file in ("json", "json3", "both") |
| 13 | + test_example( |
| 14 | + joinpath(@__DIR__, "../../examples/integrations/ojs_define/$(file)_imported.qmd"), |
| 15 | + ) do json |
| 16 | + cells = json["cells"] |
| 17 | + |
| 18 | + function extract_json(str) |
| 19 | + str = replace(str, "<script type='ojs-define'>" => "") |
| 20 | + str = replace(str, "</script>" => "") |
| 21 | + return JSON3.read(str, Dict{String,Any}) |
| 22 | + end |
| 23 | + |
| 24 | + cell = cells[4] |
| 25 | + data = cell["outputs"][1]["data"] |
| 26 | + @test haskey(data, "text/html") |
| 27 | + @test contains(data["text/html"], "<script type='ojs-define'>") |
| 28 | + obj = extract_json(data["text/html"]) |
| 29 | + @test obj["contents"][1] == Dict("name" => "key", "value" => "value") |
8 | 30 |
|
9 |
| - cell = cells[8] |
10 |
| - @test !isempty(cell["outputs"][1]["data"]["text/plain"]) |
11 |
| - @test !isempty(cell["outputs"][1]["data"]["text/html"]) |
| 31 | + for (nth, name) in (8 => "table", 12 => "df") |
| 32 | + cell = cells[nth] |
| 33 | + data = cell["outputs"][1]["data"] |
| 34 | + @test haskey(data, "text/html") |
| 35 | + @test contains(data["text/html"], "<script type='ojs-define'>") |
| 36 | + obj = extract_json(data["text/html"]) |
| 37 | + @test obj["contents"][1]["name"] == name |
| 38 | + @test obj["contents"][1]["value"][1] == Dict("a" => 1) |
| 39 | + @test obj["contents"][1]["value"][2] == Dict("a" => 2) |
| 40 | + @test obj["contents"][1]["value"][3] == Dict("a" => 3) |
| 41 | + end |
| 42 | + end |
12 | 43 | end
|
0 commit comments