Skip to content

Commit 989612b

Browse files
committed
Add config combine tests
1 parent 30ab8f8 commit 989612b

File tree

4 files changed

+49
-5
lines changed

4 files changed

+49
-5
lines changed

tests/Plotly.NET.Tests/ConfigObjects/Config.fs

Lines changed: 45 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ open Plotly.NET.LayoutObjects
66
open Plotly.NET.ConfigObjects
77
open DynamicObj
88

9-
open TestUtils.LayoutObjects
9+
open TestUtils.Objects
1010

1111
let config =
1212
Config.init(
@@ -94,4 +94,48 @@ let ``Config json tests`` =
9494
testCase "globalTransforms" (fun _ -> config |> jsonFieldIsSetWith "globalTransforms" "\"function(x) => {return x}\"")
9595
testCase "locale" (fun _ -> config |> jsonFieldIsSetWith "locale" "\"de-DE\"")
9696
testCase "locales" (fun _ -> config |> jsonFieldIsSetWith "locales" """{"yes":"no"}""")
97+
]
98+
99+
100+
let combined =
101+
Config.combine
102+
(Config.init(
103+
ModeBarButtonsToRemove = [StyleParam.ModeBarButton.AutoScale2d],
104+
ModeBarButtonsToAdd = [StyleParam.ModeBarButton.DrawCircle],
105+
ModeBarButtons = [[StyleParam.ModeBarButton.DrawClosedPath; StyleParam.ModeBarButton.DrawOpenPath]]
106+
))
107+
(Config.init(
108+
ModeBarButtonsToRemove = [StyleParam.ModeBarButton.DrawCircle],
109+
ModeBarButtonsToAdd = [StyleParam.ModeBarButton.AutoScale2d],
110+
ModeBarButtons = [[StyleParam.ModeBarButton.OrbitRotation]]
111+
))
112+
113+
let expectedCombined =
114+
Config.init(
115+
ModeBarButtonsToRemove = [StyleParam.ModeBarButton.AutoScale2d; StyleParam.ModeBarButton.DrawCircle],
116+
ModeBarButtonsToAdd = [StyleParam.ModeBarButton.DrawCircle; StyleParam.ModeBarButton.AutoScale2d],
117+
ModeBarButtons = [[StyleParam.ModeBarButton.DrawClosedPath; StyleParam.ModeBarButton.DrawOpenPath];[StyleParam.ModeBarButton.OrbitRotation]]
118+
)
119+
120+
[<Tests>]
121+
let ``Config API tests`` =
122+
testList "ConfigObjects.Config API" [
123+
testCase "combine ModeBarButtonsToRemove" (fun _ ->
124+
Expect.sequenceEqual
125+
(combined.TryGetTypedValue<seq<string>>("modeBarButtonsToRemove")).Value
126+
(expectedCombined.TryGetTypedValue<seq<string>>("modeBarButtonsToRemove")).Value
127+
"Config.combine did not return the correct object"
128+
)
129+
testCase "combine ModeBarButtonsToAdd" (fun _ ->
130+
Expect.sequenceEqual
131+
(combined.TryGetTypedValue<seq<string>>("modeBarButtonsToAdd")).Value
132+
(expectedCombined.TryGetTypedValue<seq<string>>("modeBarButtonsToAdd")).Value
133+
"Config.combine did not return the correct object"
134+
)
135+
testCase "combine ModeBarButtons" (fun _ ->
136+
Expect.sequenceEqual
137+
(Seq.concat (combined.TryGetTypedValue<seq<seq<string>>>("modeBarButtons")).Value)
138+
(Seq.concat (expectedCombined.TryGetTypedValue<seq<seq<string>>>("modeBarButtons")).Value)
139+
"Config.combine did not return the correct object"
140+
)
97141
]

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ open Plotly.NET.LayoutObjects
66
open Plotly.NET.TraceObjects
77
open Plotly.NET.GenericChart
88

9-
open TestUtils.LayoutObjects
9+
open TestUtils.Objects
1010

1111
let fullAxis =
1212
LinearAxis.init(

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ open Expecto
44
open Plotly.NET
55
open Plotly.NET.LayoutObjects
66

7-
open TestUtils.LayoutObjects
7+
open TestUtils.Objects
88

99
let slider =
1010
Slider.init(

tests/Plotly.NET.Tests/TestUtils.fs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -39,8 +39,8 @@ module HtmlCodegen =
3939
let emptyLayout chart =
4040
"var layout = {};" |> chartGeneratedContains chart
4141

42-
module LayoutObjects =
43-
42+
module Objects =
43+
4444
let jsonFieldIsSetWith fieldName expected (object:#DynamicObj) =
4545
Expect.equal
4646
((object :> DynamicObj)?($"{fieldName}") |> JsonConvert.SerializeObject)

0 commit comments

Comments
 (0)