Skip to content

Commit 2dcbbb7

Browse files
authored
Fix LT-21970: S/R failure with reordering data entry fields (#422)
* Add handling of indented sub parts
1 parent 5e6d4dd commit 2dcbbb7

File tree

2 files changed

+73
-2
lines changed

2 files changed

+73
-2
lines changed

src/LibFLExBridge-ChorusPlugin/Handling/ConfigLayout/FieldWorksConfigurationLayoutValidator.cs

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -29,8 +29,10 @@ internal static string Validate(string pathToFile)
2929
return ValidateLayoutTypeElement(childElement);
3030
case "layout":
3131
return ValidateLayoutElement(childElement);
32+
case "part":
33+
return ValidatePartElement(childElement);
3234
default:
33-
return "Layout file contains unrecognized child element.";
35+
return "Layout file contains unrecognized child element: " + childElement.Name.LocalName + ".";
3436
}
3537
}
3638
}
@@ -108,7 +110,7 @@ private static string ValidateLayoutElement(XElement layout)
108110
case "generate":
109111
return ValidateGenerateElement(childElement);
110112
default:
111-
return "Layout element contains unrecognized child element.";
113+
return "Layout element contains unrecognized child element" + childElement.Name.LocalName + ".";
112114
}
113115
}
114116
return null;
@@ -118,6 +120,16 @@ private static string ValidatePartElement(XElement part)
118120
{
119121
if (part.Attribute("ref") == null)
120122
return "Required 'ref' attribute is missing.";
123+
foreach (var childElement in part.Elements())
124+
{
125+
if (childElement.Name.LocalName == "indent")
126+
{
127+
foreach (var grandChildElement in childElement.Elements())
128+
{
129+
ValidatePartElement(grandChildElement);
130+
}
131+
}
132+
}
121133

122134
return null;
123135
}

src/LibFLExBridge-ChorusPluginTests/Handling/ConfigLayout/FieldWorksCustomLayoutTypeHandlerTests.cs

Lines changed: 59 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313
using NUnit.Framework;
1414
using SIL.IO;
1515
using SIL.Progress;
16+
using System.Text.RegularExpressions;
1617

1718
namespace LibFLExBridgeChorusPluginTests.Handling.ConfigLayout
1819
{
@@ -109,6 +110,24 @@ public void ShouldNotBeAbleToValidateFile()
109110
Assert.IsNotNull(FileHandler.ValidateFile(_ourFile.Path, new NullProgress()));
110111
}
111112

113+
[Test]
114+
public void ShouldBeAbleToValidateFileWithPartAndIndent()
115+
{
116+
const string data =
117+
@"<?xml version=""1.0"" encoding=""utf-8""?>
118+
<LayoutInventory>
119+
<part ref=""HeavySummary"" param=""Summary"" collapsedLayout=""SummaryCollapsed"" expansion=""expanded"" menu=""mnuDataTree-Sense"" hotlinks=""mnuDataTree-Sense-Hotlinks"" notifyVirtual=""LexSenseOutline"">
120+
<indent>
121+
<part ref=""Exemplar"" visibility=""ifdata"" />
122+
<part ref=""ReversalEntries"" visibility=""ifdata"" />
123+
</indent>
124+
</part>
125+
</LayoutInventory>";
126+
127+
File.WriteAllText(_ourFile.Path, data);
128+
Assert.IsNull(FileHandler.ValidateFile(_ourFile.Path, new NullProgress()));
129+
}
130+
112131
[Test]
113132
public void ShouldBeAbleToValidateFile()
114133
{
@@ -357,5 +376,45 @@ public void SampleMergeWithEmptyAncestor()
357376
Assert.IsFalse(results.Contains("combinedkey"));
358377

359378
}
379+
380+
[Test]
381+
public void SampleMergeWithPartAndIndent()
382+
{
383+
const string commonAncestor =
384+
@"<?xml version=""1.0"" encoding=""utf-8""?>
385+
<LayoutInventory>
386+
<part ref=""HeavySummary"" param=""Summary"" collapsedLayout=""SummaryCollapsed"" expansion=""expanded"" menu=""mnuDataTree-Sense"" hotlinks=""mnuDataTree-Sense-Hotlinks"" notifyVirtual=""LexSenseOutline"">
387+
<indent>
388+
<part ref=""Exemplar"" visibility=""ifdata"" />
389+
<part ref=""ReversalEntries"" visibility=""ifdata"" />
390+
</indent>
391+
</part>
392+
</LayoutInventory>";
393+
const string ourContent =
394+
@"<?xml version=""1.0"" encoding=""utf-8""?>
395+
<LayoutInventory>
396+
<part ref=""HeavySummary"" param=""Summary"" collapsedLayout=""SummaryCollapsed"" expansion=""expanded"" menu=""mnuDataTree-Sense"" hotlinks=""mnuDataTree-Sense-Hotlinks"" notifyVirtual=""LexSenseOutline"">
397+
<indent>
398+
<part ref=""ReversalEntries"" visibility=""ifdata"" />
399+
<part ref=""Exemplar"" visibility=""ifdata"" />
400+
</indent>
401+
</part>
402+
</LayoutInventory>";
403+
404+
const string theirContent = commonAncestor;
405+
406+
var results = FieldWorksTestServices.DoMerge(
407+
FileHandler,
408+
_ourFile, ourContent,
409+
_commonFile, commonAncestor,
410+
_theirFile, theirContent,
411+
null, null,
412+
0, new List<Type>(),
413+
1, new List<Type> { typeof(XmlChangedRecordReport) });
414+
string normalizedResults = Regex.Replace(results, @"\s", "");
415+
string normalizedOurContent = Regex.Replace(ourContent, @"\s", "");
416+
Assert.AreEqual(normalizedResults, normalizedOurContent);
417+
}
418+
360419
}
361420
}

0 commit comments

Comments
 (0)