Skip to content

Commit

Permalink
Added failing test for AvaloniaUI#3328.
Browse files Browse the repository at this point in the history
  • Loading branch information
grokys committed Dec 11, 2019
1 parent a70da65 commit 14ed1fd
Showing 1 changed file with 34 additions and 0 deletions.
34 changes: 34 additions & 0 deletions tests/Avalonia.Controls.UnitTests/TreeViewTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -971,6 +971,40 @@ public void Auto_Expanding_In_Style_Should_Not_Break_Range_Selection()
}
}

[Fact]
public void Removing_TreeView_From_Root_Should_Preserve_TreeViewItems()
{
// Issue #3328
var tree = CreateTestTreeData();
var target = new TreeView
{
Template = CreateTreeViewTemplate(),
Items = tree,
};

var root = new TestRoot();
root.Child = target;

CreateNodeDataTemplate(target);
ApplyTemplates(target);
ExpandAll(target);

Assert.Equal(5, target.ItemContainerGenerator.Index.Containers.Count());

root.Child = null;

Assert.Equal(5, target.ItemContainerGenerator.Index.Containers.Count());
Assert.Equal(1, target.Presenter.Panel.Children.Count);

var rootNode = Assert.IsType<TreeViewItem>(target.Presenter.Panel.Children[0]);
Assert.Equal(3, rootNode.ItemContainerGenerator.Containers.Count());
Assert.Equal(3, rootNode.Presenter.Panel.Children.Count);

var child2Node = Assert.IsType<TreeViewItem>(rootNode.Presenter.Panel.Children[1]);
Assert.Equal(1, child2Node.ItemContainerGenerator.Containers.Count());
Assert.Equal(1, child2Node.Presenter.Panel.Children.Count);
}

private void ApplyTemplates(TreeView tree)
{
tree.ApplyTemplate();
Expand Down

0 comments on commit 14ed1fd

Please sign in to comment.