Skip to content

Instantly share code, notes, and snippets.

@mushfiqweb
Created October 4, 2024 16:25
Show Gist options
  • Save mushfiqweb/26208d685e8519c4365e403d43537347 to your computer and use it in GitHub Desktop.
Save mushfiqweb/26208d685e8519c4365e403d43537347 to your computer and use it in GitHub Desktop.
using Intact.DynamicRendering.Uncork.Components;
using Snapshooter.Xunit;
namespace Intact.DynamicRendering.UnitTests.Unqork.Components
{
public class PanelTests
{
[Fact]
public void CreateComponent_ShouldCreatePanelComponentCorrectly()
{
// Arrange
var intactComponent = new IntactComponent
{
ObjectName = "TestPanel",
Label = "Test Panel Label",
Hidden = false,
Required = true,
ReadOnly = false,
RequiredMessage = "Panel is required"
};
var childComponents = new List<IUnqorkComponent>
{
new TextField { Key = "ChildTextField" },
new Checkbox { Key = "ChildCheckbox" }
};
// Act
var result = Panel.CreateComponent(intactComponent, childComponents);
// Assert
Assert.NotNull(result);
Assert.IsType<Panel>(result);
Assert.Equal("panel", result.Type);
Assert.Equal("testPanelpanel", result.Key);
Assert.Equal("Test Panel Label", result.Label);
Assert.False(result.Hidden);
Assert.True(result.Validate.Required);
Assert.Null(result.ReadOnlyView);
Assert.NotNull(result.Errors);
Assert.Equal("Panel is required", result.Errors.Required);
Assert.Equal("TestPanel", result.Title);
Assert.Equal("panel-border stack sov-padding", result.CustomClass);
Assert.False(result.Modal);
Assert.False(result.OutsideDismiss);
Assert.False(result.TableView);
Assert.Equal("default", result.Theme);
Assert.Equal(2, result.Components.Count);
Assert.IsType<TextField>(result.Components[0]);
Assert.IsType<Checkbox>(result.Components[1]);
// Snapshot testing
Snapshot.Match(intactComponent, "InitialComponentPanel");
Snapshot.Match(result, "CreatedComponentPanel");
}
[Theory]
[InlineData(null)]
[InlineData(new object[] { new string[0] })]
[InlineData(new object[] { new[] { "childTextField1", "childCheckbox", "childTextField2" } })]
public void CreateComponent_ShouldHandleVariousChildComponentScenarios(string[] childKeys)
{
// Arrange
var intactComponent = new IntactComponent { ObjectName = "ChildrenPanel" };
var childComponents = childKeys?.Select(key =>
key == "childCheckbox"
? (IUnqorkComponent)new Checkbox { Key = key }
: new TextField { Key = key }
).ToList();
// Act
var result = Panel.CreateComponent(intactComponent, childComponents);
// Assert
Assert.NotNull(result);
Assert.Equal(childKeys?.Length ?? 0, result.Components.Count);
for (int i = 0; i < (childKeys?.Length ?? 0); i++)
{
Assert.Equal(childKeys[i], result.Components[i].Key);
if (childKeys[i] == "childCheckbox")
{
Assert.IsType<Checkbox>(result.Components[i]);
}
else
{
Assert.IsType<TextField>(result.Components[i]);
}
}
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment