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
+ ]
0 commit comments