-
-
Notifications
You must be signed in to change notification settings - Fork 43
Expand file tree
/
Copy pathTestXmlBrowseView.cs
More file actions
223 lines (205 loc) · 12.2 KB
/
TestXmlBrowseView.cs
File metadata and controls
223 lines (205 loc) · 12.2 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
// Copyright (c) 2015 SIL International
// This software is licensed under the LGPL, version 2.1 or later
// (http://www.gnu.org/licenses/lgpl-2.1.html)
using System;
using System.Collections.Generic;
using System.Xml;
using NUnit.Framework;
using SIL.FieldWorks.Common.Controls;
using SIL.Utils;
using XCore;
namespace XMLViewsTests
{
[TestFixture]
public class TestXmlBrowseView
{
[Test]
public void DoubleClickEmptyItem()
{
using (var bv = new XmlBrowseView())
{
var xdoc = new XmlDocument();
// Largely copied from a live one. We probably don't really need all these for this test.
xdoc.LoadXml(@"<parameters id='textsChooser' clerk='interlinearTexts' filterBar='true' treeBarAvailability='NotAllowed'
defaultCursor='Arrow' altTitleId='Text-Plural' editable='false'>
<columns>
<column label='Title' width='144000'><string field='Title' ws='$ws=best vernoranal' /></column>
</columns>
</parameters>");
using (var mediator = new Mediator())
using (var propertyTable = new PropertyTable(mediator))
{
bv.Init(mediator, propertyTable, xdoc.DocumentElement);
bv.SimulateDoubleClick(new EventArgs());
}
}
}
[Test]
public void MigrateBrowseColumns()
{
var input =
"<root version=\"12\">" +
"<column layout=\"Unknown Test\"/>" +
"<column label=\"Headword\" sortmethod=\"FullSortKey\" ws=\"$ws=vernacular\" editable=\"false\" width=\"96000\"><span><properties><editable value=\"false\" /></properties><string field=\"MLHeadWord\" ws=\"vernacular\" /></span></column>" +
"<column layout=\"Weather\" rubbish=\"nonsense\"/>" +
"<column layout=\"IsAHeadwordForEntry\" label=\"Is a Headword\" visibility=\"dialog\"/>" +
"<column layout=\"IsAbstractFormForEntry\" label=\"Is Abstract Form\" visibility=\"dialog\" bulkEdit=\"integerOnSubfield\" bulkDelete=\"false\" field=\"LexEntry.LexemeForm\" subfield=\"MoForm.IsAbstract\" items=\"0:no;1:yes\" blankPossible=\"false\" sortType=\"YesNo\"/>" +
"<column layout=\"ExceptionFeatures\" label=\"'Exception' Features\" multipara=\"true\" width=\"25%\"/>" +
"<column layout=\"PictureCaptionForSense\" label=\"Picture-Caption\" multipara=\"true\" editable=\"false\" visibility=\"dialog\" />" +
"<column layout=\"AcademicDomainsForSense\" label=\"Academic Domains\" displayNameProperty=\"ShortNameTSS\" displayWs=\"analysis\" visibility=\"dialog\" />" +
"<column layout=\"StatusForSense\" label=\"Status\" field=\"LexSense.Status\" list=\"LexDb.Status\" visibility=\"dialog\"/>" +
"<column layout=\"ComplexEntryTypesBrowse\" ws=\"$ws=analysis\" label=\"Complex Form Types\" multipara=\"true\" />" +
"<column layout=\"VariantEntryTypesBrowse\" ws=\"$ws=analysis\" label=\"Variant Types\" multipara=\"true\" />" +
"<column layout=\"CustomIntegerForEntry_MyField\" label=\"$label\" visibility=\"menu\"/>" +
"<column layout=\"CustomGenDateForEntry_SomeField\" label=\"$label\" visibility=\"menu\"/>" +
"<column layout=\"CustomPossVectorForEntry_MyField\" label=\"$label\" multipara=\"true\" visibility=\"menu\"/>" +
"<column layout=\"CustomPossAtomForEntry_AField\" label=\"$label\" visibility=\"menu\"/>" +
"<column layout=\"CustomIntegerForSense_SenseField\" label=\"$label\" visibility=\"menu\"/>" +
"<column layout=\"CustomPossVectorForSense_SenseVec\" label=\"$label\" multipara=\"true\" visibility=\"menu\"/>" +
"<column layout=\"CustomPossAtomForSense_SenseAtom\" label=\"$label\" visibility=\"menu\"/>" +
"<column layout=\"CustomGenDateForAllomorph_MorphDate\" label=\"$label\" visibility=\"menu\"/>" +
"<column layout=\"CustomPossAtomForExample_ExAtom\" label=\"$label\" visibility=\"menu\"/>" +
"</root>";
using (var mediator = new Mediator())
using (var propertyTable = new PropertyTable(mediator))
{
var output = XmlBrowseViewBaseVc.GetSavedColumns(input, mediator, propertyTable, "myKey");
Assert.That(XmlUtils.GetOptionalAttributeValue(output.DocumentElement, "version"), Is.EqualTo(BrowseViewer.kBrowseViewVersion.ToString()));
var headwordNode = output.SelectSingleNode("//column[@label='Headword']");
Assert.That(headwordNode, Is.Not.Null);
Assert.That(XmlUtils.GetOptionalAttributeValue(headwordNode, "layout"), Is.EqualTo("EntryHeadwordForFindEntry"));
Assert.That(propertyTable.GetStringProperty("myKey", ""), Contains.Substring("EntryHeadwordForFindEntry"));
var weatherNode = output.SelectSingleNode("//column[@layout='Weather']");
Assert.That(weatherNode, Is.Null);
Assert.That(propertyTable.GetStringProperty("myKey", ""), Contains.Substring("EntryHeadwordForFindEntry"));
// Should not affect other nodes
var unknownNode = output.SelectSingleNode("//column[@layout='Unknown Test']");
Assert.That(unknownNode, Is.Not.Null);
var abstractFormNode = output.SelectSingleNode("//column[@layout='IsAbstractFormForEntry']");
Assert.That(abstractFormNode, Is.Not.Null);
Assert.That(XmlUtils.GetOptionalAttributeValue(abstractFormNode, "bulkEdit"), Is.EqualTo("booleanOnSubfield"));
Assert.That(XmlUtils.GetOptionalAttributeValue(abstractFormNode, "visibility"), Is.EqualTo("dialog"));
Assert.That(XmlUtils.GetOptionalAttributeValue(abstractFormNode, "bulkDelete"), Is.EqualTo("false"));
VerifyColumn(output, "ExceptionFeatures", "label", "Exception 'Features'");
VerifyColumn(output, "PictureCaptionForSense", "ws", "$ws=vernacular analysis");
VerifyColumn(output, "PictureCaptionForSense", "visibility", "dialog");
VerifyColumn(output, "AcademicDomainsForSense", "displayWs", "best analysis");
VerifyColumn(output, "StatusForSense", "list", "LangProject.Status");
VerifyColumn(output, "ComplexEntryTypesBrowse", "ghostListField", "LexDb.AllComplexEntryRefPropertyTargets");
VerifyColumn(output, "VariantEntryTypesBrowse", "ghostListField", "LexDb.AllVariantEntryRefPropertyTargets");
VerifyColumn(output, "CustomIntegerForEntry_MyField", "sortType", "integer");
VerifyColumn(output, "CustomGenDateForEntry_SomeField", "sortType", "genDate");
VerifyColumn(output, "CustomPossVectorForEntry_MyField", "bulkEdit", "complexListMultiple");
VerifyColumn(output, "CustomPossVectorForEntry_MyField", "field", "LexEntry.$fieldName");
VerifyColumn(output, "CustomPossVectorForEntry_MyField", "list", "$targetList");
VerifyColumn(output, "CustomPossVectorForEntry_MyField", "displayNameProperty", "ShortNameTSS");
VerifyColumn(output, "CustomPossAtomForEntry_AField", "bulkEdit", "atomicFlatListItem");
VerifyColumn(output, "CustomPossAtomForEntry_AField", "field", "LexEntry.$fieldName");
VerifyColumn(output, "CustomPossAtomForEntry_AField", "list", "$targetList");
VerifyColumn(output, "CustomIntegerForSense_SenseField", "sortType", "integer");
VerifyColumn(output, "CustomPossVectorForSense_SenseVec", "field", "LexSense.$fieldName");
VerifyColumn(output, "CustomPossAtomForSense_SenseAtom", "field", "LexSense.$fieldName");
VerifyColumn(output, "CustomGenDateForAllomorph_MorphDate", "sortType", "genDate");
VerifyColumn(output, "CustomPossAtomForExample_ExAtom", "field", "LexExampleSentence.$fieldName");
// version 15
var isAHeadwordNode = output.SelectSingleNode("//column[@layout='IsAHeadwordForEntry']");
Assert.That(isAHeadwordNode, Is.Null);
var publishAsHeadwordNode = output.SelectSingleNode("//column[@layout='PublishAsHeadword']");
Assert.That(publishAsHeadwordNode, Is.Not.Null);
// version 14
// Todo!
// Just version 15
input =
"<root version=\"14\">" +
"<column layout=\"Unknown Test\"/>" +
"<column layout=\"IsAHeadwordForEntry\" label=\"Is a Headword\" visibility=\"dialog\"/>" +
"</root>";
output = XmlBrowseViewBaseVc.GetSavedColumns(input, mediator, propertyTable, "myKey");
Assert.That(XmlUtils.GetOptionalAttributeValue(output.DocumentElement, "version"), Is.EqualTo(BrowseViewer.kBrowseViewVersion.ToString()));
isAHeadwordNode = output.SelectSingleNode("//column[@layout='IsAHeadwordForEntry']");
Assert.That(isAHeadwordNode, Is.Null);
publishAsHeadwordNode = output.SelectSingleNode("//column[@layout='PublishAsHeadword']");
Assert.That(publishAsHeadwordNode, Is.Not.Null);
Assert.That(propertyTable.GetStringProperty("myKey", ""), Contains.Substring("PublishAsHeadword"));
}
}
[Test]
public void MigrateBrowseColumns_Version19ToVersion20()
{
var input =
"<root version=\"19\">" +
"<column layout=\"EntryHeadwordForFindEntry\" label=\"Headword\" sortmethod=\"FullSortKey\" ws=\"$ws=vernacular\" editable=\"false\" width=\"96000\"/>" +
"<column layout=\"Unknown Test\"/>" +
"</root>";
using (var mediator = new Mediator())
using (var propertyTable = new PropertyTable(mediator))
{
var output = XmlBrowseViewBaseVc.GetSavedColumns(input, mediator, propertyTable, "myKey");
Assert.That(XmlUtils.GetOptionalAttributeValue(output.DocumentElement, "version"), Is.EqualTo(BrowseViewer.kBrowseViewVersion.ToString()));
Assert.That(XmlUtils.GetOptionalAttributeValue(output.DocumentElement, "version"), Is.EqualTo("20"));
// Columns should be preserved as-is
var headwordNode = output.SelectSingleNode("//column[@label='Headword']");
Assert.That(headwordNode, Is.Not.Null);
Assert.That(XmlUtils.GetOptionalAttributeValue(headwordNode, "layout"), Is.EqualTo("EntryHeadwordForFindEntry"));
}
}
[Test]
public void MigrateBrowseColumns_HiddenElementsPreservedThroughMigration()
{
// Version 19 with hidden elements (simulating a future scenario where hidden elements exist)
var input =
"<root version=\"19\">" +
"<column layout=\"EntryHeadwordForFindEntry\" label=\"Headword\"/>" +
"<hidden label=\"Lexeme Form\"/>" +
"</root>";
using (var mediator = new Mediator())
using (var propertyTable = new PropertyTable(mediator))
{
var output = XmlBrowseViewBaseVc.GetSavedColumns(input, mediator, propertyTable, "myKey");
Assert.That(XmlUtils.GetOptionalAttributeValue(output.DocumentElement, "version"), Is.EqualTo("20"));
// Hidden elements should be preserved
var hiddenNode = output.SelectSingleNode("//hidden[@label='Lexeme Form']");
Assert.That(hiddenNode, Is.Not.Null, "Hidden column labels should be preserved through migration");
}
}
[Test]
public void HiddenSentinel_AllColumnsVisible_AllowsAutoAddOfNewCommonColumns()
{
// Simulate a version-20 save where all columns are visible: the sentinel <hidden/>
// element (no label) signals that hidden tracking is active, so new common columns
// should be auto-added rather than skipped by the bootstrap path.
var savedXml =
"<root version=\"20\">" +
"<column layout=\"Name\" label=\"Name\" ws=\"$ws=best analysis\" field=\"Name\"/>" +
"<column layout=\"Abbreviation\" label=\"Abbreviation\" ws=\"$ws=best analysis\" field=\"Abbreviation\"/>" +
"<hidden/>" + // sentinel: hidden tracking active, but nothing hidden
"</root>";
var doc = new XmlDocument();
doc.LoadXml(savedXml);
var hiddenNodes = doc.DocumentElement.SelectNodes("//hidden");
bool hasHiddenTracking = hiddenNodes.Count > 0;
Assert.That(hasHiddenTracking, Is.True, "Sentinel <hidden/> should enable hidden tracking");
// Collect hidden labels — sentinel has no label, so hiddenLabels should be empty
var hiddenLabels = new HashSet<string>();
foreach (XmlNode hidden in hiddenNodes)
{
var label = XmlUtils.GetOptionalAttributeValue(hidden, "label", "");
if (!string.IsNullOrEmpty(label))
hiddenLabels.Add(label);
}
Assert.That(hiddenLabels, Is.Empty, "Sentinel <hidden/> should not contribute a label");
// A new common column that is not in the saved list and not hidden should be auto-added
// (i.e. hasHiddenTracking is true AND label is not in hiddenLabels)
var newColumnLabel = "NewCommonColumn";
Assert.That(hasHiddenTracking, Is.True);
Assert.That(hiddenLabels.Contains(newColumnLabel), Is.False,
"New column should not be blocked when hidden tracking is active with no hidden labels");
}
void VerifyColumn(XmlNode output, string layoutName, string attrName, string attrVal)
{
var node = output.SelectSingleNode("//column[@layout='" + layoutName + "']");
Assert.That(node, Is.Not.Null);
Assert.That(XmlUtils.GetOptionalAttributeValue(node, attrName), Is.EqualTo(attrVal));
}
}
}