Skip to content

Commit

Permalink
Update PreviewBubbleTests.cs
Browse files Browse the repository at this point in the history
  • Loading branch information
pinzart90 committed Dec 30, 2024
1 parent 58c78fa commit 7e45d93
Showing 1 changed file with 19 additions and 17 deletions.
36 changes: 19 additions & 17 deletions test/DynamoCoreWpfTests/PreviewBubbleTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ public void PreviewBubbleVisible_MouseMoveOverNode()
var nodeView = NodeViewWithGuid("7828a9dd-88e6-49f4-9ed3-72e355f89bcc");
nodeView.PreviewControl.RaiseEvent(new RoutedEventArgs(FrameworkElement.LoadedEvent));

RaiseMouseEnterOnNode(nodeView);
RaiseMouseEnterOnNode(nodeView, () => nodeView.PreviewControl.IsCondensed);

Assert.IsTrue(nodeView.PreviewControl.IsCondensed);
}
Expand All @@ -61,7 +61,7 @@ public void PreviewBubbleVisible_MouseMoveOverNode_InCustomWorkspace()
var nodeView = NodeViewWithGuid("9ce91e89-c087-49cd-9fd9-540cca086475");
nodeView.PreviewControl.RaiseEvent(new RoutedEventArgs(FrameworkElement.LoadedEvent));

RaiseMouseEnterOnNode(nodeView);
RaiseMouseEnterOnNode(nodeView, () => nodeView.PreviewControl.IsHidden);

Assert.IsTrue(nodeView.PreviewControl.IsHidden);
}
Expand All @@ -73,11 +73,11 @@ public void PreviewBubbleVisible_MouseMoveOutOfNode()
var nodeView = NodeViewWithGuid("7828a9dd-88e6-49f4-9ed3-72e355f89bcc");
nodeView.PreviewControl.RaiseEvent(new RoutedEventArgs(FrameworkElement.LoadedEvent));

RaiseMouseEnterOnNode(nodeView);
RaiseMouseEnterOnNode(nodeView, () => nodeView.PreviewControl.IsCondensed);

Assert.IsTrue(nodeView.PreviewControl.IsCondensed);

RaiseMouseLeaveNode(nodeView);
RaiseMouseLeaveNode(nodeView, () => nodeView.PreviewControl.IsHidden);

Assert.IsTrue(nodeView.PreviewControl.IsHidden);
}
Expand All @@ -90,7 +90,7 @@ public void PreviewBubbleHidden_OnFrozenNode()
nodeView.ViewModel.IsFrozen = true;
nodeView.PreviewControl.RaiseEvent(new RoutedEventArgs(FrameworkElement.LoadedEvent));

RaiseMouseEnterOnNode(nodeView);
RaiseMouseEnterOnNode(nodeView, () => nodeView.PreviewControl.IsHidden);

Assert.IsTrue(nodeView.PreviewControl.IsHidden);
}
Expand Down Expand Up @@ -264,7 +264,7 @@ public void Watch_PreviewAllowanceDisabled()

var nodeView = NodeViewWithGuid("456e57f3-d06f-4a53-9771-27188ee9cb40");

RaiseMouseEnterOnNode(nodeView);
RaiseMouseEnterOnNode(nodeView, () => nodeView.PreviewControl.IsHidden);

Assert.IsTrue(nodeView.PreviewControl.IsHidden);
}
Expand Down Expand Up @@ -512,17 +512,17 @@ public void PreviewBubble_ToggleShowPreviewBubbles()

nodeView.PreviewControl.RaiseEvent(new RoutedEventArgs(FrameworkElement.LoadedEvent));

RaiseMouseEnterOnNode(nodeView);
RaiseMouseEnterOnNode(nodeView, () => nodeView.PreviewControl.IsCondensed);
Assert.IsTrue(nodeView.PreviewControl.IsCondensed, "Compact preview bubble is not shown");

RaiseMouseLeaveNode(nodeView);
RaiseMouseLeaveNode(nodeView, () => nodeView.PreviewControl.IsHidden);
Assert.IsTrue(nodeView.PreviewControl.IsHidden, "Preview bubble is not hidden");

// turn off preview bubbles
ViewModel.PreferencesViewModel.ShowPreviewBubbles = false;
Assert.IsFalse(ViewModel.PreferencesViewModel.ShowPreviewBubbles, "Preview bubbles have not been turned off");

RaiseMouseEnterOnNode(nodeView);
RaiseMouseEnterOnNode(nodeView, () => nodeView.PreviewControl.IsHidden);

Assert.IsTrue(nodeView.PreviewControl.IsHidden, "Preview bubble is not hidden");
}
Expand Down Expand Up @@ -554,6 +554,8 @@ public void PreviewBubble_UnpinAllPreviewBubble()
RaiseMouseEnterOnNode(previewBubble.bubbleTools);
RaiseLeftMouseClick(previewBubble.pinIconBorder);

DispatcherUtil.DoEventsLoop(() => previewBubble.IsExpanded && previewBubble.StaysOpen);

// Assert the bubble is expanded and pinned
Assert.IsTrue(previewBubble.IsExpanded, "Expanded preview bubble should be shown");
Assert.IsTrue(previewBubble.StaysOpen, "Expanded preview bubble should be pinned");
Expand Down Expand Up @@ -604,16 +606,16 @@ public void PreviewBubble_ShowExpandedPreview_MultiReturnNode()
previewBubble.bubbleTools.RaiseEvent(new RoutedEventArgs(FrameworkElement.LoadedEvent));

// open preview bubble
RaiseMouseEnterOnNode(nodeView);
RaiseMouseEnterOnNode(nodeView, () => previewBubble.IsCondensed);
Assert.IsTrue(previewBubble.IsCondensed, "Compact preview bubble should be shown");
Assert.AreEqual(Visibility.Collapsed, previewBubble.bubbleTools.Visibility, "Pin icon should not be shown");

// hover preview bubble to see pin icon
RaiseMouseEnterOnNode(previewBubble);
RaiseMouseEnterOnNode(previewBubble, () => previewBubble.bubbleTools.Visibility == Visibility.Visible);
Assert.AreEqual(Visibility.Visible, previewBubble.bubbleTools.Visibility, "Pin icon should be shown");

// expand preview bubble
RaiseMouseEnterOnNode(previewBubble.bubbleTools);
RaiseMouseEnterOnNode(previewBubble.bubbleTools, () => previewBubble.IsExpanded);
Assert.IsTrue(previewBubble.IsExpanded, "Expanded preview bubble should be shown");
}

Expand All @@ -627,7 +629,7 @@ public void PreviewBubble_ShownForColorRange()
nodeView.PreviewControl.RaiseEvent(new RoutedEventArgs(FrameworkElement.LoadedEvent));

// open preview bubble
RaiseMouseEnterOnNode(nodeView);
RaiseMouseEnterOnNode(nodeView, () => nodeView.PreviewControl.IsHidden);
Assert.IsFalse(nodeView.PreviewControl.IsHidden, "Preview bubble for color range should be shown");
}

Expand Down Expand Up @@ -956,24 +958,24 @@ private bool ElementIsInContainerWithEpsilonCompare(FrameworkElement element, Fr
return epsilonEqual(relativePosition.X, 0) && (element.ActualWidth <= container.ActualWidth);
}

private void RaiseMouseEnterOnNode(IInputElement nv)
private void RaiseMouseEnterOnNode(IInputElement nv, Func<bool> check = null)
{
View.Dispatcher.Invoke(() =>
{
nv.RaiseEvent(new MouseEventArgs(Mouse.PrimaryDevice, 0) { RoutedEvent = Mouse.MouseEnterEvent });
});

DispatcherUtil.DoEvents();
DispatcherUtil.DoEventsLoop(check);
}

private void RaiseMouseLeaveNode(IInputElement nv)
private void RaiseMouseLeaveNode(IInputElement nv, Func<bool> check = null)
{
View.Dispatcher.Invoke(() =>
{
nv.RaiseEvent(new MouseEventArgs(Mouse.PrimaryDevice, 0) { RoutedEvent = Mouse.MouseLeaveEvent });
});

DispatcherUtil.DoEvents();
DispatcherUtil.DoEventsLoop(check);
}

private void RaiseLeftMouseClick(IInputElement nv)
Expand Down

0 comments on commit 7e45d93

Please sign in to comment.