Skip to content

Commit

Permalink
Merge branch 'main' into visualization/grid-pivot
Browse files Browse the repository at this point in the history
  • Loading branch information
recca5p authored Dec 24, 2024
2 parents b4651bc + 7ca4dd1 commit dd9f40f
Show file tree
Hide file tree
Showing 5 changed files with 365 additions and 0 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,104 @@
using Moq;
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.Extensions
{
public class ILabelsExtensions
{
[Fact]
public void SetLabel_UpdateLabels_WithFieldName()
{
// Arrange
var mockLabel = new Mock<ILabels>();
mockLabel.Setup(x => x.Labels).Returns(new List<DimensionColumn> { new DimensionColumn() { DataField = new TextDataField("InitialField") } });
var visualization = mockLabel.Object;

var fieldName = "TestName";
var expectedLabels = new List<DimensionColumn> { new DimensionColumn() { DataField = new TextDataField(fieldName) } };

// Act
visualization.SetLabel(fieldName);

// Assert
Assert.Equivalent(expectedLabels, visualization.Labels);
}

[Fact]
public void SetLabel_UpdateLabels_WithDimensionDataField()
{
// Arrange
var mockLabel = new Mock<ILabels>();
mockLabel.Setup(x => x.Labels).Returns(new List<DimensionColumn> { new DimensionColumn() { DataField = new TextDataField("InitialField") } });
var visualization = mockLabel.Object;

var mockDimensionDataField = new Mock<DimensionDataField>("TestField");
var dimensionDataField = mockDimensionDataField.Object;
var expectedLabels = new List<DimensionColumn> { new DimensionColumn() { DataField = dimensionDataField } };

// Act
visualization.SetLabel(dimensionDataField);

// Assert
Assert.Equivalent(expectedLabels, visualization.Labels);
}

[Fact]
public void SetLabels_UpdateLabels_WithListFieldNames()
{
// Arrange
var mockLabel = new Mock<ILabels>();
mockLabel.Setup(x => x.Labels).Returns(new List<DimensionColumn> { new DimensionColumn() { DataField = new TextDataField("InitialField") } });
var visualization = mockLabel.Object;

var listFieldNames = new List<string>
{
"FirstField",
"SecondField"
};
var expectedLabels = listFieldNames.Select(fieldName => new DimensionColumn()
{
DataField = new TextDataField(fieldName)
}).ToList();

// Act
visualization.SetLabels(listFieldNames.ToArray());

// Assert
Assert.Equivalent(expectedLabels, visualization.Labels);
}

[Fact]
public void SetLabels_UpdateLabels_WithListDimensionDateFields()
{
// Arrange
var mockLabel = new Mock<ILabels>();
mockLabel.Setup(x => x.Labels).Returns(new List<DimensionColumn> { new DimensionColumn() { DataField = new TextDataField("InitialField") } });
var visualization = mockLabel.Object;

var listFields = new List<DimensionDataField>();
var expectedLabels = new List<DimensionColumn>();

var mockDimensionDataField1 = new Mock<DimensionDataField>("FirstField");
var firstField = mockDimensionDataField1.Object;
listFields.Add(firstField);
expectedLabels.Add(new DimensionColumn(firstField));

var mockDimensionDataField2 = new Mock<DimensionDataField>("SecondField");
var secondField = mockDimensionDataField2.Object;
listFields.Add(secondField);
expectedLabels.Add(new DimensionColumn(secondField));

// Act
visualization.SetLabels(listFields.ToArray());

// Assert
Assert.Equivalent(expectedLabels, visualization.Labels);
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
using Moq;
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.Extensions
{
public class IMapExtensionsFixture
{
[Fact]
public void SetMap_UpdateMap_WithMapName()
{
// Arrange
var map = new MockMap();
var expectedMapName = "TestMap";

// Act
map.SetMap(expectedMapName);

// Assert
Assert.Equal(expectedMapName, map.Map);
}

private class MockMap : IMap
{
public string Map { get; set; }
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,94 @@
using Moq;
using Reveal.Sdk.Dom.Visualizations;
using System.Collections.Generic;
using System.Linq;
using Xunit;

namespace Reveal.Sdk.Dom.Tests.Visualizations.Extensions
{
public class IRowsExtensionsFixture
{
[Fact]
public void SetRow_UpdateRows_WithFieldName()
{
// Arrange
var mockRow = new Mock<IRows>();
mockRow.Setup(s => s.Rows).Returns(new List<DimensionColumn>() { new DimensionColumn() { DataField = new TextDataField("InitialField") } });
var visualization = mockRow.Object;

var fieldName = "TestField";
var expectedRows = new List<DimensionColumn> { new DimensionColumn() { DataField = new TextDataField(fieldName) } };

// Act
visualization.SetRow(fieldName);

// Assert
Assert.Equivalent(expectedRows, visualization.Rows);
}

[Fact]
public void SetRow_UpdateRows_WithDimensionDataField()
{
// Arrange
var mockRow = new Mock<IRows>();
mockRow.Setup(s => s.Rows).Returns(new List<DimensionColumn>() { new DimensionColumn() { DataField = new TextDataField("InitialField") } });
var visualization = mockRow.Object;

var mockDimensionDataField = new Mock<DimensionDataField>("TestField");
var field = mockDimensionDataField.Object;
var expectedRows = new List<DimensionColumn> { new DimensionColumn() { DataField = field } };

// Act
visualization.SetRow(field);

// Assert
Assert.Equivalent(expectedRows, visualization.Rows);
}

[Fact]
public void SetRows_UpdateRows_WithFieldNames()
{
// Arrange
var mockRow = new Mock<IRows>();
mockRow.Setup(s => s.Rows).Returns(new List<DimensionColumn>() { new DimensionColumn() { DataField = new TextDataField("InitialField") } });
var visualization = mockRow.Object;

var fieldNames = new List<string>{ "FirstField", "SecondField" };
var expectedVSRows = fieldNames.Select(fieldName => new DimensionColumn() { DataField= new TextDataField(fieldName) });

// Act
visualization.SetRows(fieldNames.ToArray());

// Assert
Assert.Equivalent(expectedVSRows, visualization.Rows);
}

[Fact]
public void SetRows_UpdateRows_WithListDimensionDataFields()
{
// Arrange
var mockRow = new Mock<IRows>();
mockRow.Setup(s => s.Rows).Returns(new List<DimensionColumn>() { new DimensionColumn() { DataField = new TextDataField("InitialField") } });
var visualization = mockRow.Object;

var listFields = new List<DimensionDataField>();
var expectedRows = new List<DimensionColumn>();

var firstMockDimensionDataField = new Mock<DimensionDataField>("FirstFieldName");
var firstField = firstMockDimensionDataField.Object;
expectedRows.Add(new DimensionColumn() { DataField = firstField });
listFields.Add(firstField);

var secondMockDimensionDataField = new Mock<DimensionDataField>("SecondFieldName");
var secondField = secondMockDimensionDataField.Object;
expectedRows.Add(new DimensionColumn() { DataField = secondField });
listFields.Add(secondField);

// Act
visualization.SetRows(listFields.ToArray());

// Assert
Assert.Equivalent(expectedRows, visualization.Rows);
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
using Moq;
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.Extensions
{
public class ITabularColumnsExtensionsFixture
{
[Fact]
public void SetColumns_UpdateColumns_WithListFieldNames()
{
// Arrange
var mockTabularColumn = new Mock<ITabularColumns>();
mockTabularColumn.SetupGet(s => s.Columns).Returns(new List<TabularColumn> { new TabularColumn("InitialColumn") });
var visualization = mockTabularColumn.Object;

var fieldNames = new List<string> { "FirstField", "SecondField" };
var expectedColumns = fieldNames.Select(fieldName => new TabularColumn(fieldName)).ToList();

// Act
visualization.SetColumns(fieldNames.ToArray());

// Assert
Assert.Equivalent(expectedColumns, visualization.Columns);
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,102 @@
using Moq;
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.Extensions
{
public class ITargetExtensionsFixture
{
[Fact]
public void SetTarget_UpdateTargets_WithFieldName()
{
// Arrange
var mockTarget = new Mock<ITargets>();
var targets = new List<MeasureColumn>() { new MeasureColumn() { DataField = new NumberDataField("InitialField") } };
mockTarget.Setup(s => s.Targets).Returns(targets);
var targetObj = mockTarget.Object;

var fieldName = "TestField";
var numberField = new NumberDataField(fieldName);
var expectedTargetList = new List<MeasureColumn>() { new MeasureColumn() { DataField = numberField } };

// Act
targetObj.SetTarget(fieldName);

// Assert
Assert.Equivalent(expectedTargetList, targetObj.Targets);
}

[Fact]
public void SetTarget_UpdateTargets_WithNumberDataField()
{
// Arrange
var mockTarget = new Mock<ITargets>();
var targets = new List<MeasureColumn>() { new MeasureColumn() { DataField = new NumberDataField("InitialField") } };
mockTarget.Setup(s => s.Targets).Returns(targets);
var targetObj = mockTarget.Object;

var fieldName = "TestField";
var numberField = new NumberDataField(fieldName);
var expectedTargetList = new List<MeasureColumn>() { new MeasureColumn() { DataField = numberField } };

// Act
targetObj.SetTarget(numberField);

// Assert
Assert.Equivalent(expectedTargetList, targetObj.Targets);
}

[Fact]
public void SetTargets_UpdateTargets_WithListFieldNames()
{
// Arrange
var mockTarget = new Mock<ITargets>();
var targets = new List<MeasureColumn>() { new MeasureColumn() { DataField = new NumberDataField("InitialField") } };
mockTarget.Setup(s => s.Targets).Returns(targets);
var targetObj = mockTarget.Object;

var fieldNames = new List<string>() { "FirstField", "SecondField" };
var expectedTargetList = fieldNames.Select(fieldName => new MeasureColumn()
{
DataField = new NumberDataField(fieldName)
});

// Act
targetObj.SetTargets(fieldNames.ToArray());

// Assert
Assert.Equivalent(expectedTargetList, targetObj.Targets);
}

[Fact]
public void SetTargets_UpdateTargets_WithListNumberDataField()
{
// Arrange
var mockTarget = new Mock<ITargets>();
var targets = new List<MeasureColumn>() { new MeasureColumn() { DataField = new NumberDataField("InitialField") } };
mockTarget.Setup(s => s.Targets).Returns(targets);
var targetObj = mockTarget.Object;

var numberFields = new List<NumberDataField>()
{
new NumberDataField("FirstField"),
new NumberDataField("SecondField"),
};
var expectedTargetList = numberFields.Select(field => new MeasureColumn()
{
DataField = field
});

// Act
targetObj.SetTargets(numberFields.ToArray());

// Assert
Assert.Equivalent(expectedTargetList, targetObj.Targets);
}
}
}

0 comments on commit dd9f40f

Please sign in to comment.