Skip to content

Commit

Permalink
Merge branch 'visualization/grid-pivot' of https://github.com/RevealB…
Browse files Browse the repository at this point in the history
…i/Reveal.Sdk.Dom into visualization/grid-pivot
  • Loading branch information
Tan Phat VO authored and Tan Phat VO committed Dec 24, 2024
2 parents 8ac02c5 + a632960 commit 2a16ebf
Show file tree
Hide file tree
Showing 7 changed files with 577 additions and 0 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,155 @@
using Reveal.Sdk.Dom.Visualizations;
using System.Collections.Generic;
using System.Linq;
using Xunit;

namespace Reveal.Sdk.Dom.Tests.Visualizations.Extensions
{
public class IAxisExtensionsFixture
{
[Fact]
public void SetXAxis_UpdateXAxis_WithFieldName()
{
// Arrange
var visualization = new MockIAxis();
var fieldName = "TestFieldName";
var expectedXAxes = new List<MeasureColumn>() { new MeasureColumn() { DataField = new NumberDataField(fieldName) } };

// Act
visualization.SetXAxis(fieldName);

// Assert
Assert.Equivalent(expectedXAxes, visualization.XAxes);
}

[Fact]
public void SetXAxis_UpdateXAxis_WithNumberDataField()
{
// Arrange
var visualization = new MockIAxis();
var fieldName = "TestFieldName";
var field = new NumberDataField(fieldName);
var expectedXAxes = new List<MeasureColumn>() { new MeasureColumn() { DataField = field } };

// Act
visualization.SetXAxis(field);

// Assert
Assert.Equivalent(expectedXAxes, visualization.XAxes);
}

[Fact]
public void SetXAxes_UpdateXAxis_WithListFieldNames()
{
// Arrange
var visualization = new MockIAxis();
var fieldNames = new List<string>()
{
"FirstFieldName",
"SecondFieldName"
};
var expectedXAxes = fieldNames.Select(fieldName => new MeasureColumn() { DataField = new NumberDataField(fieldName) });

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

// Assert
Assert.Equivalent(expectedXAxes, visualization.XAxes);
}

[Fact]
public void SetXAxes_UpdateXAxis_WithListNumberDataFields()
{
// Arrange
var visualization = new MockIAxis();
var fields = new List<NumberDataField>()
{
new NumberDataField("FirstFieldName"),
new NumberDataField("SecondFieldName")
};
var expectedXAxes = fields.Select(x => new MeasureColumn() { DataField = x });

// Act
visualization.SetXAxes(fields.ToArray());

// Assert
Assert.Equivalent(expectedXAxes, visualization.XAxes);
}

[Fact]
public void SetYAxis_UpdateYAxis_WithFieldName()
{
// Arrange
var visualization = new MockIAxis();
var fieldName = "TestFieldName";
var expectedYAxes = new List<MeasureColumn>() { new MeasureColumn() { DataField = new NumberDataField(fieldName) } };

// Act
visualization.SetYAxis(fieldName);

// Assert
Assert.Equivalent(expectedYAxes, visualization.YAxes);
}

[Fact]
public void SetYAxis_UpdateYAxis_WithNumberDataField()
{
// Arrange
var visualization = new MockIAxis();
var fieldName = "TestFieldName";
var field = new NumberDataField(fieldName);
var expectedYAxes = new List<MeasureColumn>() { new MeasureColumn() { DataField = field } };

// Act
visualization.SetYAxis(field);

// Assert
Assert.Equivalent(expectedYAxes, visualization.YAxes);
}

[Fact]
public void SetYAxes_UpdateYAxis_WithListFieldNames()
{
// Arrange
var visualization = new MockIAxis();
var fieldNames = new List<string>()
{
"FirstFieldName",
"SecondFieldName"
};
var expectedYAxes = fieldNames.Select(fieldName => new MeasureColumn() { DataField = new NumberDataField(fieldName) });

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

// Assert
Assert.Equivalent(expectedYAxes, visualization.YAxes);
}

[Fact]
public void SetYAxes_UpdateYAxis_WithListNumberDataFields()
{
// Arrange
var visualization = new MockIAxis();
var fields = new List<NumberDataField>()
{
new NumberDataField("FirstFieldName"),
new NumberDataField("SecondFieldName")
};
var expectedYAxes = fields.Select(x => new MeasureColumn() { DataField = x });

// Act
visualization.SetYAxes(fields.ToArray());

// Assert
Assert.Equivalent(expectedYAxes, visualization.YAxes);
}

private class MockIAxis : IAxis
{
public List<MeasureColumn> XAxes { get; } = new List<MeasureColumn>() { new MeasureColumn() { DataField = new NumberDataField("InitialX") } };

public List<MeasureColumn> YAxes { get; } = new List<MeasureColumn>() { new MeasureColumn() { DataField = new NumberDataField("InitialY") } };
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,99 @@
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 ICategoriesExtensionsFixture
{
[Fact]
public void SetCategory_UpdateCategories_WithFieldName()
{
// Arrange
var visualization = new MockICategories();
var fieldName = "TestField";
var expectedCategories = new List<DimensionColumn> {
new DimensionColumn()
{
DataField = new TextDataField(fieldName),
}
};

// Act
visualization.SetCategory(fieldName);

// Assert
Assert.Equivalent(expectedCategories, visualization.Categories);
}

[Fact]
public void SetCategory_UpdateCategories_WithDimensionDataField()
{
// Arrange
var visualization = new MockICategories();
var fieldName = "TestField";
var mockDimensionDataField = new Mock<DimensionDataField>(fieldName);
var field = mockDimensionDataField.Object;
var expectedCategories = new List<DimensionColumn> {
new DimensionColumn()
{
DataField = field,
}
};

// Act
visualization.SetCategory(field);

// Assert
Assert.Equivalent(expectedCategories, visualization.Categories);
}

[Fact]
public void SetCategories_UpdateCategories_WithListFieldNames()
{
// Arrange
var visualization = new MockICategories();
var fieldNames = new List<string> { "FirstFieldName", "SecondFieldName" };
var expectedCategories = fieldNames.Select(x => new DimensionColumn { DataField = new TextDataField(x) });

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

// Assert
Assert.Equivalent(expectedCategories, visualization.Categories);
}

[Fact]
public void SetCategories_UpdateCategories_WithListDimensionDataFields()
{
// Arrange
var visualization = new MockICategories();

var fields = new List<DimensionDataField>();
var expectedCategories = new List<DimensionColumn>();

var mockDimensionDataField1 = new Mock<DimensionDataField>("FirstFieldName");
var f1 = mockDimensionDataField1.Object;
fields.Add(f1);
expectedCategories.Add(new DimensionColumn() { DataField = f1 });

var mockDimensionDataField2 = new Mock<DimensionDataField>("SecondFieldName");
var f2 = mockDimensionDataField2.Object;
fields.Add(f2);
expectedCategories.Add(new DimensionColumn() { DataField = f2 });

// Act
visualization.SetCategories(fields.ToArray());

// Assert
Assert.Equivalent(expectedCategories, visualization.Categories);
}

private class MockICategories : ICategories
{
public List<DimensionColumn> Categories { get; } = new List<DimensionColumn>();
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
using Moq;
using Reveal.Sdk.Dom.Visualizations;
using Xunit;

namespace Reveal.Sdk.Dom.Tests.Visualizations.Extensions
{
public class ICategoryExtensionsFixture
{
[Fact]
public void SetCategory_UpdateCategory_WithFieldName()
{
// Arrange
var visualization = new MockICategory();
var fieldName = "TestField";
var expectedCategory = new DimensionColumn()
{
DataField = new TextDataField(fieldName)
};

// Act
visualization.SetCategory(fieldName);

// Assert
Assert.Equivalent(expectedCategory, visualization.Category);
}

[Fact]
public void SetCategory_UpdateCategory_WithDimensionDataField()
{
// Arrange
var visualization = new MockICategory();
var fieldName = "TestField";
var mockDimensionDataField = new Mock<DimensionDataField>(fieldName);
var field = mockDimensionDataField.Object;
var expectedCategory = new DimensionColumn()
{
DataField = field
};

// Act
visualization.SetCategory(field);

// Assert
Assert.Equivalent(expectedCategory, visualization.Category);
}

private class MockICategory : ICategory
{
public DimensionColumn Category { get; set; }
}
}
}
Loading

0 comments on commit 2a16ebf

Please sign in to comment.