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

Skip ZIndex from being serialized. #669

Merged
merged 1 commit into from
Jun 13, 2024
Merged
Show file tree
Hide file tree
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
38 changes: 38 additions & 0 deletions src/Persistence.Tests/Yaml/ValidSerializerTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -181,12 +181,14 @@ public void Serialize_Should_FlattenGalleryTemplate(string expectedPath, bool is
properties: new()
{
{ "TemplateFill", "RGBA(0, 0, 0, 0)" },
{ "ZIndex", "1" },
}
),
ControlFactory.Create("button12", template: "button",
properties: new()
{
{ "Fill", "RGBA(0, 0, 0, 0)" },
{ "ZIndex", "1" },
}
)
}
Expand All @@ -201,6 +203,42 @@ public void Serialize_Should_FlattenGalleryTemplate(string expectedPath, bool is
sut.Should().Be(expectedYaml);
}

[TestMethod]
[DataRow(@"_TestData/ValidYaml{0}/ZIndexOrdering/with-addpropertiestoparents-control.pa.yaml", true)]
[DataRow(@"_TestData/ValidYaml{0}/ZIndexOrdering/with-addpropertiestoparents-control.pa.yaml", false)]
public void Serialize_Should_FlattenGalleryTemplateWithoutZIndex(string expectedPath, bool isControlIdentifiers)
{
var graph = ControlFactory.Create("Gallery1", template: "gallery",
properties: new()
{
{ "Items", "Accounts" },
},
children: new List<Control>()
{
ControlFactory.Create("GalleryTemplate1", template: "galleryTemplate",
properties: new()
{
{ "TemplateFill", "RGBA(0, 0, 0, 0)" },
{ "ZIndex", "1" },
}
),
ControlFactory.Create("Button1", template: "button",
properties: new()
{
{ "Fill", "RGBA(0, 0, 0, 0)" },
{ "ZIndex", "1" },
}
)
}
);

var serializer = CreateSerializer(isControlIdentifiers);

var sut = serializer.SerializeControl(graph).NormalizeNewlines();
var expectedYaml = File.ReadAllText(GetTestFilePath(expectedPath, isControlIdentifiers)).NormalizeNewlines();
sut.Should().Be(expectedYaml);
}

[TestMethod]
[DataRow(@"_TestData/ValidYaml{0}/BuiltInControl/with-variant.pa.yaml", "SuperButton", null, true)]
[DataRow(@"_TestData/ValidYaml{0}/BuiltInControl/with-variant.pa.yaml", "SuperButton", null, false)]
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
Gallery1:
Control: Gallery
Properties:
Items: =Accounts
TemplateFill: =RGBA(0, 0, 0, 0)
Children:
- Button1:
Control: Button
Properties:
Fill: =RGBA(0, 0, 0, 0)
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
Control: Gallery
Name: Gallery1
Properties:
Items: =Accounts
TemplateFill: =RGBA(0, 0, 0, 0)
Children:
- Control: Button
Name: Button1
Properties:
Fill: =RGBA(0, 0, 0, 0)
2 changes: 1 addition & 1 deletion src/Persistence/Yaml/ControlFormatter.cs
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ public static T BeforeSerialize<T>(this T control) where T : Control
_ = control ?? throw new ArgumentNullException(nameof(control));

var childrenToRemove = (control.Children ?? Enumerable.Empty<Control>()).Where(c => c.Template.AddPropertiesToParent).ToList();
var propertiesToMerge = childrenToRemove.SelectMany(c => c.Properties).ToList();
var propertiesToMerge = childrenToRemove.SelectMany(c => c.Properties.Where(p => p.Key != PropertyNames.ZIndex)).ToList();
tehcrashxor marked this conversation as resolved.
Show resolved Hide resolved

var isGroupContainer = control.Template.Name == BuiltInTemplates.GroupContainer.Name;

Expand Down
Loading