Skip to content

Commit ed2933f

Browse files
committed
##367: Add display options tests
1 parent 989612b commit ed2933f

File tree

4 files changed

+107
-3
lines changed

4 files changed

+107
-3
lines changed

src/Plotly.NET/ChartAPI/GenericChart.fs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -259,7 +259,7 @@ module GenericChart =
259259
displayOpts |> DisplayOptions.getDescription
260260

261261
let plotlyReference =
262-
displayOpts |> DisplayOptions.getPlotlyPlotlyReference
262+
displayOpts |> DisplayOptions.getPlotlyReference
263263

264264
div
265265
[]
@@ -301,7 +301,7 @@ module GenericChart =
301301
(displayOpts |> DisplayOptions.getDescription)
302302

303303
let plotlyReference =
304-
displayOpts |> DisplayOptions.getPlotlyPlotlyReference
304+
displayOpts |> DisplayOptions.getPlotlyReference
305305

306306
HTML.Doc(
307307
chart =

src/Plotly.NET/DisplayOptions/DisplayOptions.fs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -139,5 +139,5 @@ type DisplayOptions() =
139139
static member tryGetPlotlyReference(displayOpts: DisplayOptions) =
140140
displayOpts.TryGetTypedValue<PlotlyJSReference>("PlotlyJSReference")
141141

142-
static member getPlotlyPlotlyReference(displayOpts: DisplayOptions) =
142+
static member getPlotlyReference(displayOpts: DisplayOptions) =
143143
displayOpts |> DisplayOptions.tryGetPlotlyReference |> Option.defaultValue (PlotlyJSReference.NoReference)
Lines changed: 103 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,103 @@
1+
module Tests.DisplayOptions
2+
3+
open Expecto
4+
open Plotly.NET
5+
open Plotly.NET.LayoutObjects
6+
open Plotly.NET.ConfigObjects
7+
open DynamicObj
8+
open Giraffe.ViewEngine
9+
10+
open TestUtils.Objects
11+
12+
let headTags =
13+
[
14+
script [_src "lol.meme"] []
15+
]
16+
17+
let description =
18+
[
19+
h1 [] [str "Yes"]
20+
]
21+
22+
let plotlyRef = NoReference
23+
24+
let displayOpts =
25+
DisplayOptions.init(
26+
AdditionalHeadTags = [
27+
script [_src "lol.meme"] []
28+
],
29+
Description = [
30+
h1 [] [str "Yes"]
31+
],
32+
PlotlyJSReference = NoReference
33+
)
34+
35+
let combined =
36+
DisplayOptions.combine
37+
(DisplayOptions.init(
38+
AdditionalHeadTags = [script [_src "1"] []],
39+
Description = [h1 [] [str "1"]],
40+
PlotlyJSReference = NoReference
41+
))
42+
(DisplayOptions.init(
43+
AdditionalHeadTags = [script [_src "2"] []],
44+
Description = [h1 [] [str "2"]],
45+
PlotlyJSReference = Full
46+
))
47+
48+
let expectedCombined =
49+
DisplayOptions.init(
50+
AdditionalHeadTags = [script [_src "1"] []; script [_src "2"] []],
51+
Description = [h1 [] [str "1"]; h1 [] [str "2"]],
52+
PlotlyJSReference = Full
53+
)
54+
55+
[<Tests>]
56+
let ``DisplayOptions API tests`` =
57+
testList "DisplayOptions.DisplayOptions API" [
58+
testCase "AdditionalHeadTags tryGet" (fun _ -> Expect.equal (displayOpts |> DisplayOptions.tryGetAdditionalHeadTags) (Some headTags) "DisplayOptions.tryGetAdditionalHeadTags did not return the correct result")
59+
testCase "Description tryGet" (fun _ -> Expect.equal (displayOpts |> DisplayOptions.tryGetDescription) (Some description) "DisplayOptions.tryGetDescription did not return the correct result")
60+
testCase "PlotlyJSReference tryGet" (fun _ -> Expect.equal (displayOpts |> DisplayOptions.tryGetPlotlyReference) (Some plotlyRef) "DisplayOptions.tryGetPlotlyReference did not return the correct result")
61+
62+
testCase "AdditionalHeadTags getter" (fun _ -> Expect.equal (displayOpts |> DisplayOptions.getAdditionalHeadTags) headTags "DisplayOptions.getAdditionalHeadTags did not return the correct result")
63+
testCase "Description getter" (fun _ -> Expect.equal (displayOpts |> DisplayOptions.getDescription) description "DisplayOptions.getDescription did not return the correct result")
64+
testCase "PlotlyJSReference getter" (fun _ -> Expect.equal (displayOpts |> DisplayOptions.getPlotlyReference) plotlyRef "DisplayOptions.getPlotlyReference did not return the correct result")
65+
66+
testCase "AdditionalHeadTags setter" (fun _ ->
67+
Expect.equal
68+
(DisplayOptions.init() |> DisplayOptions.setAdditionalHeadTags headTags |> DisplayOptions.getAdditionalHeadTags)
69+
headTags
70+
"DisplayOptions.setAdditionalHeadTags did not set the correct result"
71+
)
72+
testCase "Description setter" (fun _ ->
73+
Expect.equal
74+
(DisplayOptions.init() |> DisplayOptions.setDescription description |> DisplayOptions.getDescription)
75+
description
76+
"DisplayOptions.setDescription did not set the correct result"
77+
)
78+
testCase "PlotlyJSReference setter" (fun _ ->
79+
Expect.equal
80+
(DisplayOptions.init() |> DisplayOptions.setPlotlyReference plotlyRef |> DisplayOptions.getPlotlyReference)
81+
plotlyRef
82+
"DisplayOptions.setPlotlyReference did set return the correct result"
83+
)
84+
85+
testCase "AdditionalHeadTags combine" (fun _ ->
86+
Expect.sequenceEqual
87+
(combined |> DisplayOptions.getAdditionalHeadTags)
88+
(expectedCombined |> DisplayOptions.getAdditionalHeadTags)
89+
"DisplayOptions.combine did not return the correct object"
90+
)
91+
testCase "Description combine" (fun _ ->
92+
Expect.sequenceEqual
93+
(combined |> DisplayOptions.getDescription)
94+
(expectedCombined |> DisplayOptions.getDescription)
95+
"DisplayOptions.combine did not return the correct object"
96+
)
97+
testCase "PlotlyJSReference combine" (fun _ ->
98+
Expect.equal
99+
(combined |> DisplayOptions.getPlotlyReference)
100+
Full
101+
"DisplayOptions.combine did not return the correct object"
102+
)
103+
]

tests/Plotly.NET.Tests/Plotly.NET.Tests.fsproj

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@
1818
<Compile Include="LayoutObjects\Slider.fs" />
1919
<Compile Include="LayoutObjects\LinearAxis.fs" />
2020
<Compile Include="ConfigObjects\Config.fs" />
21+
<Compile Include="DisplayOptions\DisplayOptions.fs" />
2122
<Compile Include="Traces\TraceStaticMembers.fs" />
2223
<Compile Include="Traces\TraceStyle.fs" />
2324
<Compile Include="Traces\TraceID.fs" />

0 commit comments

Comments
 (0)