Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Unit test/primitive test field #271

Merged
merged 3 commits into from
Jan 10, 2025
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -0,0 +1,68 @@
using Newtonsoft.Json.Linq;
using Reveal.Sdk.Dom.Visualizations;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using Xunit;

namespace Reveal.Sdk.Dom.Tests.Visualizations.Primitives
{
public class TextFieldFixture
{
[Fact]
public void Constructor_SetDefaultValues_WhenConstructed()
{
// Act
var field = new TextField();

// Assert
Assert.Equal(DataType.String, ((IFieldDataType)field).DataType);
Assert.Equal(string.Empty, field.FieldName);
}

[Fact]
public void Constructor_SetFieldName_WhenConstructed()
{
// Arrange
var fieldName = "FieldName";

// Act
var field = new TextField(fieldName);

// Assert
Assert.Equal(DataType.String, ((IFieldDataType)field).DataType);
Assert.Equal(fieldName, field.FieldName);
}

[Fact]
public void ToJsonString_CreateCorrectJsonString_WithoutCondition()
{
// Arrange
var expectedJson = """
{
"FieldName": "FieldName",
"FieldLabel": "FieldName",
"UserCaption": "FieldName",
"IsCalculated": false,
"Properties": {},
"Sorting": "None",
"FieldType": "String"
}
""";
var fieldName = "FieldName";

// Act
var field = new TextField(fieldName);

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

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