Skip to content

Commit

Permalink
Merge branch 'master' into users/joemay/fix-build-and-inner-dev-loop
Browse files Browse the repository at this point in the history
  • Loading branch information
mizrael authored Jun 22, 2024
2 parents cdc2835 + 68b9502 commit 67bffd0
Show file tree
Hide file tree
Showing 7 changed files with 52 additions and 2 deletions.
21 changes: 21 additions & 0 deletions src/Persistence.Tests/Yaml/DeserializerValidTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -515,4 +515,25 @@ public void Deserialize_ShouldParse_Lists_of_Controls(string path, bool isContro
list.First().Should().BeOfType(expectedType);
list.First().Name.Should().Be(expectedName);
}

[TestMethod]
[DataRow(@"_TestData/ValidYaml{0}/BuiltInControl/with-style.pa.yaml", true, "this is my style")]
[DataRow(@"_TestData/ValidYaml{0}/BuiltInControl/with-style.pa.yaml", false, "this is my style")]
public void Deserialize_ShouldParse_StyleName(
string path,
bool isControlIdentifiers,
string expectedStyleName)
{
// Arrange
var deserializer = CreateDeserializer(isControlIdentifiers);
using var yamlStream = File.OpenRead(GetTestFilePath(path, isControlIdentifiers));
using var yamlReader = new StreamReader(yamlStream);

// Act
var control = deserializer.Deserialize<BuiltInControl>(yamlReader);

// Assert
control.ShouldNotBeNull();
control.StyleName.Should().Be(expectedStyleName);
}
}
15 changes: 15 additions & 0 deletions src/Persistence.Tests/Yaml/ValidSerializerTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -385,4 +385,19 @@ public void Serialize_ShouldCreateValidYamlForComponentInstance(string expectedP
var expectedYaml = File.ReadAllText(GetTestFilePath(expectedPath, isControlIdentifiers)).NormalizeNewlines();
serializedGraph.Should().Be(expectedYaml);
}

[TestMethod]
[DataRow(@"_TestData/ValidYaml{0}/BuiltInControl/with-style.pa.yaml", true)]
[DataRow(@"_TestData/ValidYaml{0}/BuiltInControl/with-style.pa.yaml", false)]
public void Serialize_ShouldWriteStyle(string expectedPath, bool isControlIdentifiers)
{
var graph = ControlFactory.Create("myControl1", template: "Button");
graph.StyleName = "this is my style";

var serializer = CreateSerializer(isControlIdentifiers);

var sut = serializer.SerializeControl(graph).NormalizeNewlines();
var expectedYaml = File.ReadAllText(GetTestFilePath(expectedPath, isControlIdentifiers)).NormalizeNewlines();
sut.Should().Be(expectedYaml);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
myControl1:
Control: Button
StyleName: this is my style
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
Control: Button
Name: myControl1
StyleName: this is my style
2 changes: 2 additions & 0 deletions src/Persistence/Models/Control.cs
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,8 @@ public int ZIndex
}
}

[YamlMember(Order = 60)]
public string StyleName { get; set; } = string.Empty;

internal virtual void AfterCreate(Dictionary<string, object?> controlDefinition)
{
Expand Down
9 changes: 7 additions & 2 deletions src/Persistence/Templates/ControlFactory.cs
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,7 @@ public Control Create(string name, string template,
{
string? variant = null;
string? layout = null;
string? styleName = null;
ControlPropertiesCollection? properties = null;
IList<Control>? children = null;

Expand All @@ -61,6 +62,7 @@ public Control Create(string name, string template,
controlDefinition.TryGetValue(nameof(Control.Properties), out properties);
controlDefinition.TryGetValue(nameof(Control.Children), out children);
controlDefinition.TryGetValue(nameof(Control.Layout), out layout);
controlDefinition.TryGetValue(nameof(Control.StyleName), out styleName);
}

if (TryCreateComponent(name, template, componentDefinitionName, componentLibraryUniqueName, variant, properties, children, controlDefinition, out var control))
Expand All @@ -70,22 +72,25 @@ public Control Create(string name, string template,
{
if (TryCreateFirstClassControl(name, controlTemplate.Name, variant ?? string.Empty, properties, children, controlDefinition, out control))
{
control.StyleName = styleName ?? string.Empty;
return control;
}

return new BuiltInControl(name, variant ?? string.Empty, controlTemplate)
{
Properties = properties ?? new(),
Children = children,
Layout = layout ?? string.Empty
Layout = layout ?? string.Empty,
StyleName = styleName ?? string.Empty,
};
}

return new CustomControl(name, variant ?? string.Empty, new ControlTemplate(template))
{
Properties = properties ?? new(),
Children = children,
Layout = layout ?? string.Empty
Layout = layout ?? string.Empty,
StyleName = styleName ?? string.Empty,
};
}

Expand Down
1 change: 1 addition & 0 deletions src/Persistence/Yaml/ControlConverter.cs
Original file line number Diff line number Diff line change
Expand Up @@ -203,6 +203,7 @@ public virtual void OnWriteAfterName(IEmitter emitter, Control control)
{
emitter.Emit(nameof(Control.Variant), control.Variant);
emitter.Emit(nameof(Control.Layout), control.Layout);
emitter.Emit(nameof(Control.StyleName), control.StyleName);

if (control.Properties != null && control.Properties.Count > 0)
{
Expand Down

0 comments on commit 67bffd0

Please sign in to comment.