Skip to content

Commit 4a37217

Browse files
committed
Add config tests, refactor json field tests to have linkable source
1 parent 5cd6c99 commit 4a37217

File tree

5 files changed

+142
-46
lines changed

5 files changed

+142
-46
lines changed
Lines changed: 97 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,97 @@
1+
module Tests.ConfigObjects.Config
2+
3+
open Expecto
4+
open Plotly.NET
5+
open Plotly.NET.LayoutObjects
6+
open Plotly.NET.ConfigObjects
7+
open DynamicObj
8+
9+
open TestUtils.LayoutObjects
10+
11+
let config =
12+
Config.init(
13+
StaticPlot = false,
14+
TypesetMath = true,
15+
PlotlyServerUrl = "myserver.me.meme",
16+
Editable = true,
17+
Edits = Edits.init(AnnotationPosition = true, ShapePosition = true),
18+
EditSelection = true,
19+
Autosizable = true,
20+
Responsive = true,
21+
FillFrame = true,
22+
FrameMargins = 1.337,
23+
ScrollZoom = StyleParam.ScrollZoom.All,
24+
DoubleClick = StyleParam.DoubleClick.Reset,
25+
DoubleClickDelay = 1337,
26+
ShowAxisDragHandles = true,
27+
ShowAxisRangeEntryBoxes = true,
28+
ShowTips = true,
29+
ShowLink = true,
30+
LinkText = "never gonna give you up",
31+
SendData = true,
32+
ShowSources = true,
33+
DisplayModeBar = true,
34+
ShowSendToCloud = true,
35+
ShowEditInChartStudio = true,
36+
ModeBarButtonsToRemove = [StyleParam.ModeBarButton.AutoScale2d],
37+
ModeBarButtonsToAdd = [StyleParam.ModeBarButton.DrawCircle],
38+
ModeBarButtons = [[StyleParam.ModeBarButton.DrawClosedPath; StyleParam.ModeBarButton.DrawOpenPath];[StyleParam.ModeBarButton.OrbitRotation]],
39+
ToImageButtonOptions = ToImageButtonOptions.init(Format = StyleParam.ImageFormat.SVG, Filename="soos.svg"),
40+
Displaylogo = true,
41+
Watermark = true,
42+
plotGlPixelRatio = 1.0,
43+
SetBackground = box "function(x) => {return x}",
44+
TopojsonURL = "myserver.me.meme",
45+
MapboxAccessToken = "4Tw20BlzLT",
46+
Logging = 2,
47+
NotifyOnLogging = 2,
48+
QueueLength = 1337,
49+
GlobalTransforms = box """function(x) => {return x}""",
50+
Locale = "de-DE",
51+
Locales = (DynamicObj() |> fun x -> x?yes <- "no"; x)
52+
)
53+
54+
55+
[<Tests>]
56+
let ``Config json tests`` =
57+
testList "ConfigObjects.Config JSON field tests" [
58+
testCase "active" (fun _ -> config |> jsonFieldIsSetWith "staticPlot" "false")
59+
testCase "typesetMath" (fun _ -> config |> jsonFieldIsSetWith "typesetMath" "true")
60+
testCase "plotlyServerUrl" (fun _ -> config |> jsonFieldIsSetWith "plotlyServerUrl" "\"myserver.me.meme\"")
61+
testCase "editable" (fun _ -> config |> jsonFieldIsSetWith "editable" "true")
62+
testCase "edits" (fun _ -> config |> jsonFieldIsSetWith "edits" """{"annotationPosition":true,"shapePosition":true}""")
63+
testCase "editSelection" (fun _ -> config |> jsonFieldIsSetWith "editSelection" "true")
64+
testCase "autosizable" (fun _ -> config |> jsonFieldIsSetWith "autosizable" "true")
65+
testCase "responsive" (fun _ -> config |> jsonFieldIsSetWith "responsive" "true")
66+
testCase "fillFrame" (fun _ -> config |> jsonFieldIsSetWith "fillFrame" "true")
67+
testCase "frameMargins" (fun _ -> config |> jsonFieldIsSetWith "frameMargins" "1.337")
68+
testCase "scrollZoom" (fun _ -> config |> jsonFieldIsSetWith "scrollZoom" "true")
69+
testCase "doubleClick" (fun _ -> config |> jsonFieldIsSetWith "doubleClick" "\"reset\"")
70+
testCase "doubleClickDelay" (fun _ -> config |> jsonFieldIsSetWith "doubleClickDelay" "1337")
71+
testCase "showAxisDragHandles" (fun _ -> config |> jsonFieldIsSetWith "showAxisDragHandles" "true")
72+
testCase "showAxisRangeEntryBoxes" (fun _ -> config |> jsonFieldIsSetWith "showAxisRangeEntryBoxes" "true")
73+
testCase "showTips" (fun _ -> config |> jsonFieldIsSetWith "showTips" "true")
74+
testCase "showLink" (fun _ -> config |> jsonFieldIsSetWith "showLink" "true")
75+
testCase "linkText" (fun _ -> config |> jsonFieldIsSetWith "linkText" "\"never gonna give you up\"")
76+
testCase "sendData" (fun _ -> config |> jsonFieldIsSetWith "sendData" "true")
77+
testCase "showSources" (fun _ -> config |> jsonFieldIsSetWith "showSources" "true")
78+
testCase "displayModeBar" (fun _ -> config |> jsonFieldIsSetWith "displayModeBar" "true")
79+
testCase "showSendToCloud" (fun _ -> config |> jsonFieldIsSetWith "showSendToCloud" "true")
80+
testCase "showEditInChartStudio" (fun _ -> config |> jsonFieldIsSetWith "showEditInChartStudio" "true")
81+
testCase "modeBarButtonsToRemove" (fun _ -> config |> jsonFieldIsSetWith "modeBarButtonsToRemove" """["autoScale2d"]""")
82+
testCase "modeBarButtonsToAdd" (fun _ -> config |> jsonFieldIsSetWith "modeBarButtonsToAdd" """["drawcircle"]""")
83+
testCase "modeBarButtons" (fun _ -> config |> jsonFieldIsSetWith "modeBarButtons" """[["drawclosedpath","drawopenpath"],["orbitRotation"]]""")
84+
testCase "toImageButtonOptions" (fun _ -> config |> jsonFieldIsSetWith "toImageButtonOptions" """{"format":"svg","filename":"soos.svg"}""")
85+
testCase "displaylogo" (fun _ -> config |> jsonFieldIsSetWith "displaylogo" "true")
86+
testCase "watermark" (fun _ -> config |> jsonFieldIsSetWith "watermark" "true")
87+
testCase "plotGlPixelRatio" (fun _ -> config |> jsonFieldIsSetWith "plotGlPixelRatio" "1.0")
88+
testCase "setBackground" (fun _ -> config |> jsonFieldIsSetWith "setBackground" "\"function(x) => {return x}\"")
89+
testCase "topojsonURL" (fun _ -> config |> jsonFieldIsSetWith "topojsonURL" "\"myserver.me.meme\"")
90+
testCase "mapboxAccessToken" (fun _ -> config |> jsonFieldIsSetWith "mapboxAccessToken" "\"4Tw20BlzLT\"")
91+
testCase "logging" (fun _ -> config |> jsonFieldIsSetWith "logging" "2")
92+
testCase "notifyOnLogging" (fun _ -> config |> jsonFieldIsSetWith "notifyOnLogging" "2")
93+
testCase "queueLength" (fun _ -> config |> jsonFieldIsSetWith "queueLength" "1337")
94+
testCase "globalTransforms" (fun _ -> config |> jsonFieldIsSetWith "globalTransforms" "\"function(x) => {return x}\"")
95+
testCase "locale" (fun _ -> config |> jsonFieldIsSetWith "locale" "\"de-DE\"")
96+
testCase "locales" (fun _ -> config |> jsonFieldIsSetWith "locales" """{"yes":"no"}""")
97+
]

tests/Plotly.NET.Tests/LayoutObjects/LinearAxis.fs

Lines changed: 16 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -91,20 +91,20 @@ let fullAxis =
9191
[<Tests>]
9292
let ``LinearAxis tests`` =
9393
testList "LayoutObjects.LinearAxis JSON field tests" [
94-
fullAxis |> createJsonFieldTest "visible" "true"
95-
fullAxis |> createJsonFieldTest "color" "\"red\""
96-
fullAxis |> createJsonFieldTest "title" "{\"text\":\"Hi\"}"
97-
fullAxis |> createJsonFieldTest "type" "\"log\""
98-
fullAxis |> createJsonFieldTest "autotypenumbers" "\"strict\""
99-
fullAxis |> createJsonFieldTest "autorange" "true"
100-
fullAxis |> createJsonFieldTest "rangemode" "\"normal\""
101-
fullAxis |> createJsonFieldTest "range" "[-1.0,1.0]"
102-
fullAxis |> createJsonFieldTest "fixedrange" "true"
103-
fullAxis |> createJsonFieldTest "scaleanchor" "\"x\""
104-
fullAxis |> createJsonFieldTest "scaleratio" "6.9"
105-
fullAxis |> createJsonFieldTest "constrain" "\"range\""
106-
fullAxis |> createJsonFieldTest "constraintoward" "\"bottom\""
107-
fullAxis |> createJsonFieldTest "matches" "\"x\""
108-
fullAxis |> createJsonFieldTest "rangebreaks" "[{\"enabled\":false}]"
109-
fullAxis |> createJsonFieldTest "tickmode" "\"auto\""
94+
testCase "visible" (fun _ -> fullAxis |> jsonFieldIsSetWith "visible" "true" )
95+
testCase "color" (fun _ -> fullAxis |> jsonFieldIsSetWith "color" "\"red\"")
96+
testCase "title" (fun _ -> fullAxis |> jsonFieldIsSetWith "title" "{\"text\":\"Hi\"}")
97+
testCase "type" (fun _ -> fullAxis |> jsonFieldIsSetWith "type" "\"log\"")
98+
testCase "autotypenumbers" (fun _ -> fullAxis |> jsonFieldIsSetWith "autotypenumbers" "\"strict\"")
99+
testCase "autorange" (fun _ -> fullAxis |> jsonFieldIsSetWith "autorange" "true")
100+
testCase "rangemode" (fun _ -> fullAxis |> jsonFieldIsSetWith "rangemode" "\"normal\"")
101+
testCase "range" (fun _ -> fullAxis |> jsonFieldIsSetWith "range" "[-1.0,1.0]")
102+
testCase "fixedrange" (fun _ -> fullAxis |> jsonFieldIsSetWith "fixedrange" "true")
103+
testCase "scaleanchor" (fun _ -> fullAxis |> jsonFieldIsSetWith "scaleanchor" "\"x\"")
104+
testCase "scaleratio" (fun _ -> fullAxis |> jsonFieldIsSetWith "scaleratio" "6.9")
105+
testCase "constrain" (fun _ -> fullAxis |> jsonFieldIsSetWith "constrain" "\"range\"")
106+
testCase "constraintoward" (fun _ -> fullAxis |> jsonFieldIsSetWith "constraintoward" "\"bottom\"")
107+
testCase "matches" (fun _ -> fullAxis |> jsonFieldIsSetWith "matches" "\"x\"")
108+
testCase "rangebreaks" (fun _ -> fullAxis |> jsonFieldIsSetWith "rangebreaks" "[{\"enabled\":false}]")
109+
testCase "tickmode" (fun _ -> fullAxis |> jsonFieldIsSetWith "tickmode" "\"auto\"")
110110
]

tests/Plotly.NET.Tests/LayoutObjects/Slider.fs

Lines changed: 23 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -57,27 +57,27 @@ let slider =
5757
[<Tests>]
5858
let ``Slider tests`` =
5959
testList "LayoutObjects.Slider JSON field tests" [
60-
slider |> createJsonFieldTest "active" "1"
61-
slider |> createJsonFieldTest "activebgcolor" "\"rgba(1, 2, 3, 1.0)\""
62-
slider |> createJsonFieldTest "bgcolor" "\"rgba(2, 3, 4, 1.0)\""
63-
slider |> createJsonFieldTest "bordercolor" "\"rgba(3, 4, 5, 1.0)\""
64-
slider |> createJsonFieldTest "borderwidth" "2"
65-
slider |> createJsonFieldTest "currentvalue" "{\"font\":{\"family\":\"Arial\",\"size\":1.0,\"color\":\"rgba(4, 5, 6, 1.0)\"},\"offset\":1,\"prefix\":\"prefix\",\"suffix\":\"suffix\",\"visible\":false,\"xanchor\":\"center\"}"
66-
slider |> createJsonFieldTest "font" "{\"family\":\"Balto\",\"size\":2.0,\"color\":\"rgba(5, 6, 7, 1.0)\"}"
67-
slider |> createJsonFieldTest "len" "0.4"
68-
slider |> createJsonFieldTest "lenmode" "\"fraction\""
69-
slider |> createJsonFieldTest "minorticklen" "6"
70-
slider |> createJsonFieldTest "name" "\"SliderName\""
71-
slider |> createJsonFieldTest "pad" "{\"b\":1,\"l\":2,\"r\":3,\"t\":4}"
72-
slider |> createJsonFieldTest "templateitemname" "\"TemplateItemName\""
73-
slider |> createJsonFieldTest "tickcolor" "\"rgba(6, 7, 8, 1.0)\""
74-
slider |> createJsonFieldTest "ticklen" "7"
75-
slider |> createJsonFieldTest "tickwidth" "8"
76-
slider |> createJsonFieldTest "transition" "{\"duration\":1,\"easing\":\"back\",\"ordering\":\"layout first\"}"
77-
slider |> createJsonFieldTest "visible" "true"
78-
slider |> createJsonFieldTest "x" "9"
79-
slider |> createJsonFieldTest "xanchor" "\"left\""
80-
slider |> createJsonFieldTest "y" "10"
81-
slider |> createJsonFieldTest "yanchor" "\"middle\""
82-
slider |> createJsonFieldTest "steps" "[{\"args\":[{\"visible\":false},{\"title\":\"stepTitle\"}],\"execute\":true,\"label\":\"stepLabel\",\"method\":\"update\",\"name\":\"stepName\",\"templateitemname\":\"stepTemplateItemName\",\"value\":\"stepValue\",\"visible\":true}]"
60+
testCase "active" (fun _ -> slider |> jsonFieldIsSetWith "active" "1" )
61+
testCase "activebgcolor" (fun _ -> slider |> jsonFieldIsSetWith "activebgcolor" "\"rgba(1, 2, 3, 1.0)\"" )
62+
testCase "bgcolor" (fun _ -> slider |> jsonFieldIsSetWith "bgcolor" "\"rgba(2, 3, 4, 1.0)\"" )
63+
testCase "bordercolor" (fun _ -> slider |> jsonFieldIsSetWith "bordercolor" "\"rgba(3, 4, 5, 1.0)\"" )
64+
testCase "borderwidth" (fun _ -> slider |> jsonFieldIsSetWith "borderwidth" "2" )
65+
testCase "currentvalue" (fun _ -> slider |> jsonFieldIsSetWith "currentvalue" "{\"font\":{\"family\":\"Arial\",\"size\":1.0,\"color\":\"rgba(4, 5, 6, 1.0)\"},\"offset\":1,\"prefix\":\"prefix\",\"suffix\":\"suffix\",\"visible\":false,\"xanchor\":\"center\"}" )
66+
testCase "font" (fun _ -> slider |> jsonFieldIsSetWith "font" "{\"family\":\"Balto\",\"size\":2.0,\"color\":\"rgba(5, 6, 7, 1.0)\"}" )
67+
testCase "len" (fun _ -> slider |> jsonFieldIsSetWith "len" "0.4" )
68+
testCase "lenmode" (fun _ -> slider |> jsonFieldIsSetWith "lenmode" "\"fraction\"" )
69+
testCase "minorticklen" (fun _ -> slider |> jsonFieldIsSetWith "minorticklen" "6" )
70+
testCase "name" (fun _ -> slider |> jsonFieldIsSetWith "name" "\"SliderName\"" )
71+
testCase "pad" (fun _ -> slider |> jsonFieldIsSetWith "pad" "{\"b\":1,\"l\":2,\"r\":3,\"t\":4}" )
72+
testCase "templateitemname" (fun _ -> slider |> jsonFieldIsSetWith "templateitemname" "\"TemplateItemName\"" )
73+
testCase "tickcolor" (fun _ -> slider |> jsonFieldIsSetWith "tickcolor" "\"rgba(6, 7, 8, 1.0)\"" )
74+
testCase "ticklen" (fun _ -> slider |> jsonFieldIsSetWith "ticklen" "7" )
75+
testCase "tickwidth" (fun _ -> slider |> jsonFieldIsSetWith "tickwidth" "8" )
76+
testCase "transition" (fun _ -> slider |> jsonFieldIsSetWith "transition" "{\"duration\":1,\"easing\":\"back\",\"ordering\":\"layout first\"}" )
77+
testCase "visible" (fun _ -> slider |> jsonFieldIsSetWith "visible" "true" )
78+
testCase "x" (fun _ -> slider |> jsonFieldIsSetWith "x" "9" )
79+
testCase "xanchor" (fun _ -> slider |> jsonFieldIsSetWith "xanchor" "\"left\"" )
80+
testCase "y" (fun _ -> slider |> jsonFieldIsSetWith "y" "10" )
81+
testCase "yanchor" (fun _ -> slider |> jsonFieldIsSetWith "yanchor" "\"middle\"" )
82+
testCase "steps" (fun _ -> slider |> jsonFieldIsSetWith "steps" "[{\"args\":[{\"visible\":false},{\"title\":\"stepTitle\"}],\"execute\":true,\"label\":\"stepLabel\",\"method\":\"update\",\"name\":\"stepName\",\"templateitemname\":\"stepTemplateItemName\",\"value\":\"stepValue\",\"visible\":true}]" )
8383
]

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

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717
<Compile Include="CommonAbstractions\Colors.fs" />
1818
<Compile Include="LayoutObjects\Slider.fs" />
1919
<Compile Include="LayoutObjects\LinearAxis.fs" />
20+
<Compile Include="ConfigObjects\Config.fs" />
2021
<Compile Include="Traces\TraceStaticMembers.fs" />
2122
<Compile Include="Traces\TraceStyle.fs" />
2223
<Compile Include="Traces\TraceID.fs" />

tests/Plotly.NET.Tests/TestUtils.fs

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -41,10 +41,8 @@ module HtmlCodegen =
4141

4242
module LayoutObjects =
4343

44-
let createJsonFieldTest fieldName expected (object:#DynamicObj) =
45-
testCase fieldName ( fun () ->
46-
Expect.stringContains
47-
((object :> DynamicObj) |> JsonConvert.SerializeObject)
48-
($"\"{fieldName}\":{expected}")
49-
($"Field `{fieldName}` not set correctly in serialized dynamic object.")
50-
)
44+
let jsonFieldIsSetWith fieldName expected (object:#DynamicObj) =
45+
Expect.equal
46+
((object :> DynamicObj)?($"{fieldName}") |> JsonConvert.SerializeObject)
47+
expected
48+
($"Field `{fieldName}` not set correctly in serialized dynamic object.")

0 commit comments

Comments
 (0)