Skip to content

Commit

Permalink
Merge pull request #264 from RevealBi/unit-test/sparkline-vs-dataspec
Browse files Browse the repository at this point in the history
Create UTs for SparklineVisualizationDataSpec class
  • Loading branch information
hainv-ohio authored Jan 7, 2025
2 parents 687db2e + 8bf9e85 commit 7f75fe9
Show file tree
Hide file tree
Showing 2 changed files with 70 additions and 0 deletions.
4 changes: 4 additions & 0 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,10 @@ jobs:
uses: actions/checkout@v3
with:
fetch-depth: 0
- name: Install Mono
run: |
sudo apt-get update
sudo apt-get install -y mono-complete
- name: Setup .NET
uses: actions/setup-dotnet@v2
with:
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@
using Newtonsoft.Json.Linq;
using Reveal.Sdk.Dom.Core.Constants;
using Reveal.Sdk.Dom.Visualizations;
using Reveal.Sdk.Dom.Visualizations.VisualizationSpecs;
using System.Collections.Generic;
using Xunit;

namespace Reveal.Sdk.Dom.Tests.Visualizations.VisualizationSpecs
{
public class SparklineVisualizationDataSpecFixture
{
[Fact]
public void Constructor_FieldsHaveDefaultValue()
{
// Act
var sparklineVSDataSpec = new SparklineVisualizationDataSpec();

// Assert
Assert.Equal(SchemaTypeNames.SparklineVisualizationDataSpecType, sparklineVSDataSpec.SchemaTypeName);
Assert.Equal(IndicatorVisualizationType.LastMonths, sparklineVSDataSpec.IndicatorType);
}

[Fact]
public void ToJsonString_CreateCorrectJsonString_WithoutCondition()
{
// Arrange
var expectedJson = """
{
"_type": "BubbleVisualizationDataSpecType",
"NumberOfPeriods": 3,
"ShowIndicator": false,
"IndicatorType": "YearToDatePreviousYear",
"Date": {
"_type": "DimensionColumnSpecType"
},
"Value": [],
"AdHocFields": 12,
"FormatVersion": 2,
"AdHocExpandedElements": [],
"Rows": []
}
""";
var sparklineVSDataSpec = new SparklineVisualizationDataSpec()
{
AdHocExpandedElements = new List<AdHocExpandedElement>(),
AdHocFields = 12,
Date = new DimensionColumn(),
FormatVersion = 2,
IndicatorType = IndicatorVisualizationType.YearToDatePreviousYear,
NumberOfPeriods =3,
Rows = new List<DimensionColumn>(),
SchemaTypeName = SchemaTypeNames.BubbleVisualizationDataSpecType,
ShowIndicator = false,
Value = new List<MeasureColumn>()
};

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

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

0 comments on commit 7f75fe9

Please sign in to comment.