Skip to content

Commit 01c8d37

Browse files
committed
Fix homograph tests
Change-Id: Ida53b89fe3adb1048a5c18502cf0e725f1c6249d
1 parent 34090c5 commit 01c8d37

2 files changed

Lines changed: 27 additions & 3 deletions

File tree

Src/xWorks/xWorksTests/ConfiguredXHTMLGeneratorTests.cs

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -483,6 +483,12 @@ public void GenerateContentForEntry_HomographNumbersGeneratesCorrectResult()
483483
XHTMLStringBuilder.Append(result);
484484
XHTMLStringBuilder.AppendLine("</TESTWRAPPER>");
485485

486+
// Normally the propertyvalue for a headword with homograph number is IMultiStringAccessor.
487+
// However, in the test setup the propertyvalue for homograph number is an int
488+
// and therefore hits the int case of GenerateContentForValue in ConfiguredLcmGenerator,
489+
// and is directed to "GenerateContentForSimpleString", which applies the first analysis WS.
490+
// This creates an extra "/span[@lang='en' and text()=...]" at the end of the lexentry.
491+
// We don't care if a WS is assigned, so we ignore this possible extra span and check only for the correct homograph number.
486492
var entryWithHomograph = "/TESTWRAPPER/div[@class='lexentry']/span[@class='homographnumber' and text()=1] | /TESTWRAPPER/div[@class='lexentry']/span[@class='homographnumber']/*[text()=1]";
487493
AssertThatXmlIn.String(XHTMLStringBuilder.ToString()).HasSpecifiedNumberOfMatchesForXpath(entryWithHomograph, 1);
488494
entryWithHomograph = "/TESTWRAPPER/div[@class='lexentry']/span[@class='homographnumber' and text()=2] | /TESTWRAPPER/div[@class='lexentry']/span[@class='homographnumber']/*[text()=2]";

Src/xWorks/xWorksTests/LcmJsonGeneratorTests.cs

Lines changed: 21 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1103,13 +1103,31 @@ public void SavePublishedJsonWithStyles_DisplayXhtmlPopulated()
11031103
DefaultDecorator, 1,
11041104
new DictionaryConfigurationModel { Parts = new List<ConfigurableDictionaryNode> { mainEntryNode } },
11051105
m_propertyTable, "test.json", null, out int[] _);
1106-
var expectedResults = @"{""xhtmlTemplate"":""lexentry"",""guid"":""g" + testEntry.Guid + @""",""letterHead"": ""c"",""sortIndex"": 0,
1106+
1107+
// An explicitly stated writing system is not necessary for the homograph number to be correct.
1108+
// Normally the propertyvalue for a headword with homograph number is IMultiStringAccessor.
1109+
// However, in the test setup the propertyvalue for homograph number is an int
1110+
// and therefore hits the int case of GenerateContentForValue in ConfiguredLcmGenerator,
1111+
// and is directed to "GenerateContentForSimpleString", which applies the first analysis WS.
1112+
// The homograph portion of this test is only concerned with checking value of the homograph number; we don't care if a WS is assigned.
1113+
var expectedResultsWithoutWs = @"{""xhtmlTemplate"":""lexentry"",""guid"":""g" + testEntry.Guid + @""",""letterHead"": ""c"",""sortIndex"": 0,
11071114
""homographnumber"":""0"",""citationform"":[{""lang"":""fr"",""value"":""Citation""}],
11081115
""displayXhtml"":""<div class=\""lexentry\"" nodeId=\""" + mainEntryNode.GetNodeId() +
11091116
@"\"" id=\""g" + testEntry.Guid + @"\""><span class=\""homographnumber\"" nodeId=\""" + homographNum.GetNodeId() +
11101117
@"\"">0</span><span class=\""citationform\""><span nodeId=\""" + citationForm.GetNodeId() + @"\"" lang=\""fr\"">Citation</span></span></div>""}";
1111-
var expected = (JObject)JsonConvert.DeserializeObject(expectedResults, new JsonSerializerSettings { Formatting = Formatting.None });
1112-
VerifyJson(results[0][0].ToString(Formatting.None), expected);
1118+
var expectedResultsWithWs = @"{""xhtmlTemplate"":""lexentry"",""guid"":""g" + testEntry.Guid + @""",""letterHead"": ""c"",""sortIndex"": 0,
1119+
""homographnumber"":""0"",""citationform"":[{""lang"":""fr"",""value"":""Citation""}],
1120+
""displayXhtml"":""<div class=\""lexentry\"" nodeId=\""" + mainEntryNode.GetNodeId() +
1121+
@"\"" id=\""g" + testEntry.Guid + @"\""><span class=\""homographnumber\"" nodeId=\""" + homographNum.GetNodeId() +
1122+
@"\""><span lang=\""en\"">0</span></span><span class=\""citationform\""><span nodeId=\""" + citationForm.GetNodeId() + @"\"" lang=\""fr\"">Citation</span></span></div>""}";
1123+
1124+
var expectedWithoutWs = (JObject)JsonConvert.DeserializeObject(expectedResultsWithoutWs, new JsonSerializerSettings { Formatting = Formatting.None });
1125+
var expectedWithWs = (JObject)JsonConvert.DeserializeObject(expectedResultsWithWs, new JsonSerializerSettings { Formatting = Formatting.None });
1126+
1127+
dynamic jsonResult = JsonConvert.DeserializeObject(results[0][0].ToString(Formatting.None), new JsonSerializerSettings { Formatting = Formatting.None });
1128+
string actualReformatted = JsonConvert.SerializeObject(jsonResult, Formatting.Indented);
1129+
Assert.That(actualReformatted, Is.AnyOf(JsonConvert.SerializeObject(expectedWithoutWs, Formatting.Indented),
1130+
JsonConvert.SerializeObject(expectedWithWs, Formatting.Indented)));
11131131
}
11141132

11151133
[Test]

0 commit comments

Comments
 (0)