Skip to content

Commit

Permalink
Fix LT-21970: S/R failure with reordering data entry fields
Browse files Browse the repository at this point in the history
  • Loading branch information
jtmaxwell3 committed Dec 4, 2024
1 parent df6220a commit 95652e9
Show file tree
Hide file tree
Showing 2 changed files with 71 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -29,8 +29,10 @@ internal static string Validate(string pathToFile)
return ValidateLayoutTypeElement(childElement);
case "layout":
return ValidateLayoutElement(childElement);
case "part":
return ValidatePartElement(childElement);
default:
return "Layout file contains unrecognized child element.";
return "Layout file contains unrecognized child element: " + childElement.Name.LocalName + ".";
}
}
}
Expand Down Expand Up @@ -108,7 +110,7 @@ private static string ValidateLayoutElement(XElement layout)
case "generate":
return ValidateGenerateElement(childElement);
default:
return "Layout element contains unrecognized child element.";
return "Layout element contains unrecognized child element" + childElement.Name.LocalName + ".";
}
}
return null;
Expand All @@ -118,6 +120,14 @@ private static string ValidatePartElement(XElement part)
{
if (part.Attribute("ref") == null)
return "Required 'ref' attribute is missing.";
foreach (var childElement in part.Elements())
{
if (childElement.Name.LocalName == "indent")
foreach (var grandChildElement in childElement.Elements())
{
ValidatePartElement(grandChildElement);
}
}

return null;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
using NUnit.Framework;
using SIL.IO;
using SIL.Progress;
using System.Text.RegularExpressions;

namespace LibFLExBridgeChorusPluginTests.Handling.ConfigLayout
{
Expand Down Expand Up @@ -109,6 +110,24 @@ public void ShouldNotBeAbleToValidateFile()
Assert.IsNotNull(FileHandler.ValidateFile(_ourFile.Path, new NullProgress()));
}

[Test]
public void ShouldBeAbleToValidateFileWithPartAndIndent()
{
const string data =
@"<?xml version=""1.0"" encoding=""utf-8""?>
<LayoutInventory>
<part ref=""HeavySummary"" param=""Summary"" collapsedLayout=""SummaryCollapsed"" expansion=""expanded"" menu=""mnuDataTree-Sense"" hotlinks=""mnuDataTree-Sense-Hotlinks"" notifyVirtual=""LexSenseOutline"">
<indent>
<part ref=""Exemplar"" visibility=""ifdata"" />
<part ref=""ReversalEntries"" visibility=""ifdata"" />
</indent>
</part>
</LayoutInventory>";

File.WriteAllText(_ourFile.Path, data);
Assert.IsNull(FileHandler.ValidateFile(_ourFile.Path, new NullProgress()));
}

[Test]
public void ShouldBeAbleToValidateFile()
{
Expand Down Expand Up @@ -357,5 +376,45 @@ public void SampleMergeWithEmptyAncestor()
Assert.IsFalse(results.Contains("combinedkey"));

}

[Test]
public void SampleMergeWithPartAndIndent()
{
const string commonAncestor =
@"<?xml version=""1.0"" encoding=""utf-8""?>
<LayoutInventory>
<part ref=""HeavySummary"" param=""Summary"" collapsedLayout=""SummaryCollapsed"" expansion=""expanded"" menu=""mnuDataTree-Sense"" hotlinks=""mnuDataTree-Sense-Hotlinks"" notifyVirtual=""LexSenseOutline"">
<indent>
<part ref=""Exemplar"" visibility=""ifdata"" />
<part ref=""ReversalEntries"" visibility=""ifdata"" />
</indent>
</part>
</LayoutInventory>";
const string ourContent =
@"<?xml version=""1.0"" encoding=""utf-8""?>
<LayoutInventory>
<part ref=""HeavySummary"" param=""Summary"" collapsedLayout=""SummaryCollapsed"" expansion=""expanded"" menu=""mnuDataTree-Sense"" hotlinks=""mnuDataTree-Sense-Hotlinks"" notifyVirtual=""LexSenseOutline"">
<indent>
<part ref=""ReversalEntries"" visibility=""ifdata"" />
<part ref=""Exemplar"" visibility=""ifdata"" />
</indent>
</part>
</LayoutInventory>";

const string theirContent = commonAncestor;

var results = FieldWorksTestServices.DoMerge(
FileHandler,
_ourFile, ourContent,
_commonFile, commonAncestor,
_theirFile, theirContent,
null, null,
0, new List<Type>(),
1, new List<Type> { typeof(XmlChangedRecordReport) });
string normalizedResults = Regex.Replace(results, @"\s", "");
string normalizedOurContent = Regex.Replace(ourContent, @"\s", "");
Assert.AreEqual(normalizedResults, normalizedOurContent);
}

}
}

0 comments on commit 95652e9

Please sign in to comment.