diff --git a/src/Persistence.Tests/Yaml/ValidSerializerTests.cs b/src/Persistence.Tests/Yaml/ValidSerializerTests.cs index 20a39cee..7ec26c3d 100644 --- a/src/Persistence.Tests/Yaml/ValidSerializerTests.cs +++ b/src/Persistence.Tests/Yaml/ValidSerializerTests.cs @@ -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" }, } ) } @@ -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() + { + 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)] diff --git a/src/Persistence.Tests/_TestData/ValidYaml-CI/ZIndexOrdering/with-addpropertiestoparents-control.pa.yaml b/src/Persistence.Tests/_TestData/ValidYaml-CI/ZIndexOrdering/with-addpropertiestoparents-control.pa.yaml new file mode 100644 index 00000000..d3a7fd4e --- /dev/null +++ b/src/Persistence.Tests/_TestData/ValidYaml-CI/ZIndexOrdering/with-addpropertiestoparents-control.pa.yaml @@ -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) diff --git a/src/Persistence.Tests/_TestData/ValidYaml/ZIndexOrdering/with-addpropertiestoparents-control.pa.yaml b/src/Persistence.Tests/_TestData/ValidYaml/ZIndexOrdering/with-addpropertiestoparents-control.pa.yaml new file mode 100644 index 00000000..002dc103 --- /dev/null +++ b/src/Persistence.Tests/_TestData/ValidYaml/ZIndexOrdering/with-addpropertiestoparents-control.pa.yaml @@ -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) diff --git a/src/Persistence/Yaml/ControlFormatter.cs b/src/Persistence/Yaml/ControlFormatter.cs index 053e2fbc..8e45fe4b 100644 --- a/src/Persistence/Yaml/ControlFormatter.cs +++ b/src/Persistence/Yaml/ControlFormatter.cs @@ -20,7 +20,7 @@ public static T BeforeSerialize(this T control) where T : Control _ = control ?? throw new ArgumentNullException(nameof(control)); var childrenToRemove = (control.Children ?? Enumerable.Empty()).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;