Skip to content

Commit

Permalink
Merge pull request #367 from RevealBi/visualization-settings/pie-chart
Browse files Browse the repository at this point in the history
Write unit tests for RoundChartVisualization Settings (PieChartVisualizationSettingsFixture)
  • Loading branch information
hainv-ohio authored Jan 17, 2025
2 parents e3348c1 + cef4f62 commit 4f99072
Showing 1 changed file with 56 additions and 0 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
using Newtonsoft.Json;
using Newtonsoft.Json.Linq;
using Reveal.Sdk.Dom.Core.Constants;
using Reveal.Sdk.Dom.Visualizations;
using Reveal.Sdk.Dom.Visualizations.Settings;
using Xunit;

namespace Reveal.Sdk.Dom.Tests.Visualizations.Settings;

public class PieChartVisualizationSettingsFixture
{
[Fact]
public void Constructor_FieldsHaveDefaultValues_WhenInstanceIsCreated()
{
// Act
var settings = new PieChartVisualizationSettings();

// Assert
Assert.Equal(RdashChartType.Pie, settings.ChartType);
}

[Fact]
public void ToJsonString_GeneratesCorrectJson_WhenSerialized()
{
// Arrange
var expectedJson =
"""
{
"_type" : "ChartVisualizationSettingsType",
"ShowZeroValuesInLegend" : false,
"ShowLegends" : true,
"LabelDisplayMode" : "Percentage",
"OthersSliceThreshold" : 3.0,
"ChartType" : "Pie",
"VisualizationType" : "CHART"
}
""";

var settings = new PieChartVisualizationSettings
{
ShowLegend = true,
StartColorIndex = null,
OthersSliceThreshold = 3.0,
StartPosition = null,
ShowZeroValuesInLegend = false
};

// Act
var actualJson = settings.ToJsonString();
var expectedJObject = JObject.Parse(expectedJson);
var actualJObject = JObject.Parse(actualJson);

// Assert
Assert.Equal(expectedJObject, actualJObject);
}
}

0 comments on commit 4f99072

Please sign in to comment.