Skip to content
This repository was archived by the owner on Sep 25, 2024. It is now read-only.

Commit d32b505

Browse files
author
Eric Maupin
committed
[Core] Don't leave phantom categories from grouped types
1 parent 6585cc3 commit d32b505

File tree

2 files changed

+34
-5
lines changed

2 files changed

+34
-5
lines changed

Xamarin.PropertyEditing.Tests/PanelViewModelTests.cs

Lines changed: 29 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -209,7 +209,7 @@ public async Task PropertyListCategoryFiltered ()
209209
[Test]
210210
public async Task PropertyListCategoryGroupedWithNullCategory ()
211211
{
212-
// Purposefully a null catgory
212+
// Purposefully a null category
213213
var normalProp = new Mock<IPropertyInfo> ();
214214
normalProp.SetupGet (p => p.Type).Returns (typeof(string));
215215
normalProp.SetupGet (p => p.Name).Returns ("name");
@@ -414,6 +414,34 @@ public void AutoExpandChosenGroups ()
414414
Assert.That (vm.GetIsExpanded (normalProp.Object.Category), Is.True);
415415
}
416416

417+
[Test]
418+
public void GroupedTypesDoNotLeavePhantomCategory ()
419+
{
420+
var target = new object ();
421+
422+
var property = new Mock<IPropertyInfo> ();
423+
property.SetupGet (p => p.Type).Returns (typeof (string));
424+
property.SetupGet (p => p.Category).Returns ((string)null);
425+
property.SetupGet (p => p.Name).Returns ("name");
426+
427+
var provider = new Mock<IEditorProvider> ();
428+
provider.Setup (ep => ep.GetObjectEditorAsync (target))
429+
.ReturnsAsync (new MockObjectEditor (property.Object) { Target = target });
430+
431+
var platform = new TargetPlatform (provider.Object) {
432+
GroupedTypes = new Dictionary<Type, string> {
433+
{ typeof(string), "strings" }
434+
}
435+
};
436+
437+
var vm = CreateVm (platform);
438+
vm.ArrangeMode = PropertyArrangeMode.Category;
439+
vm.AutoExpand = true;
440+
vm.SelectedObjects.Add (target);
441+
442+
Assert.That (vm.ArrangedEditors.Count, Is.EqualTo (1));
443+
}
444+
417445
internal override PanelViewModel CreateVm (TargetPlatform platform)
418446
{
419447
return new PanelViewModel (platform);

Xamarin.PropertyEditing/ViewModels/PanelViewModel.cs

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -246,10 +246,11 @@ protected override void OnAddEditors (IEnumerable<EditorViewModel> editors)
246246
}
247247
}
248248

249-
string key = grouping.Key ?? String.Empty;
250-
if (remainingItems != null) // TODO: pretty sure this was out of order before, add test
251-
this.arranged.Add (key, new PanelGroupViewModel (key, grouping.Where (evm => remainingItems.Contains (evm))));
252-
else
249+
string key = grouping.Key;
250+
if (remainingItems != null) {// TODO: pretty sure this was out of order before, add test
251+
if (remainingItems.Count > 0)
252+
this.arranged.Add (key, new PanelGroupViewModel (key, grouping.Where (evm => remainingItems.Contains (evm))));
253+
} else
253254
this.arranged.Add (key, new PanelGroupViewModel (key, grouping, separateUncommon: !isFlat));
254255

255256
AutoExpandGroup (key);

0 commit comments

Comments
 (0)