Skip to content

Commit

Permalink
Skip ZIndex from being serialized.
Browse files Browse the repository at this point in the history
  • Loading branch information
shshetty-microsoft committed Jun 13, 2024
1 parent c803350 commit e2df2ae
Show file tree
Hide file tree
Showing 4 changed files with 59 additions and 1 deletion.
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();

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

Expand Down

0 comments on commit e2df2ae

Please sign in to comment.