Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix crash when removing node from group that contains note. #12551

Merged
merged 1 commit into from
Jan 19, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion src/DynamoCoreWpf/ViewModels/Core/DynamoViewModel.cs
Original file line number Diff line number Diff line change
Expand Up @@ -1286,7 +1286,7 @@ internal void UngroupModel(object parameters)
if (modelb is NodeModel node)
{
var pinnedNotes = CurrentSpaceViewModel.Notes
.Where(x => x.PinnedNode.NodeModel == node)
.Where(x => x.PinnedNode?.NodeModel == node)
.Select(x => x.Model.GUID);

if (pinnedNotes.Any())
Expand Down
51 changes: 51 additions & 0 deletions test/DynamoCoreWpfTests/AnnotationViewModelTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -164,6 +164,57 @@ public void CanUngroupNodeFromAGroup()
Assert.AreEqual(true, ViewModel.CanUngroupModel(null));
}


[Test]
[Category("DynamoUI")]
public void CanUngroupNodeFromAGroupIfGroupContainsNote()
{
//Create a Node
var addNode = new DSFunction(ViewModel.Model.LibraryServices.GetFunctionDescriptor("+"));
ViewModel.Model.CurrentWorkspace.AddAndRegisterNode(addNode, false);

//verify the node was created
Assert.AreEqual(1, ViewModel.Model.CurrentWorkspace.Nodes.Count());

//Select the node for group
DynamoSelection.Instance.Selection.Add(addNode);

//Create a Group around that node
ViewModel.AddAnnotationCommand.Execute(null);
var annotation = ViewModel.Model.CurrentWorkspace.Annotations.FirstOrDefault();

//Check if the group is created
Assert.IsNotNull(annotation);

//Clear the selection
DynamoSelection.Instance.ClearSelection();

//create a note.
ViewModel.AddNoteCommand.Execute(null);
var note = ViewModel.Model.CurrentWorkspace.Notes.FirstOrDefault();
Assert.IsNotNull(note);

//Select the note
DynamoSelection.Instance.Selection.Add(note);
DynamoSelection.Instance.Selection.Add(annotation);

ViewModel.AddModelsToGroupModelCommand.Execute(null);

//Clear the selection
DynamoSelection.Instance.ClearSelection();
//Select the node
DynamoSelection.Instance.Selection.Add(addNode);

Assert.AreEqual(2, annotation.Nodes.Count());
//remove it
Assert.DoesNotThrow(() =>
{
ViewModel.UngroupModelCommand.Execute(null);

});
Assert.AreEqual(1, annotation.Nodes.Count());
}

[Test]
[Category("DynamoUI")]
public void CanUngroupNodeWhichIsNotInAGroup()
Expand Down