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

An9/wi00692027/ncn-Introduced Enabled property to handle the dragNewLinkBehaviour #19

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/Blazor.Diagrams.Core/Behaviors/DragNewLinkBehavior.cs
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ private void OnPointerDown(Model? model, MouseEventArgs e)

if (model is PortModel port)
{
if (port.Locked)
if (port.Locked || !port.Enabled)
return;

_targetPositionAnchor = new PositionAnchor(CalculateTargetPosition(e.ClientX, e.ClientY));
Expand Down
1 change: 1 addition & 0 deletions src/Blazor.Diagrams.Core/Models/Base/Model.cs
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ protected Model(string id)

public string Id { get; }
public bool Locked { get; set; }
public bool Enabled { get; set; } = true;
public bool Visible
{
get => _visible;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -441,4 +441,27 @@ public void Behavior_ShouldTriggerLinkTargetAttached_WhenLinkSnappedToPortAndMou
// Assert
targetAttachedTriggers.Should().Be(1);
}

[Fact]
public void Behavior_ShouldNotCreateLinkWithSinglePortAnchorSource_WhenMouseDownOnPort()
{
// Arrange
var diagram = new TestDiagram();
diagram.SetContainer(new Rectangle(0, 0, 1000, 400));
var node = new NodeModel(position: new Point(100, 50));
var port = node.AddPort(new PortModel(node)
{
Initialized = true,
Position = new Point(110, 60),
Size = new Size(10, 20),
Enabled = false
});

// Act
diagram.TriggerPointerDown(port,
new PointerEventArgs(100, 100, 0, 0, false, false, false, 0, 0, 0, 0, 0, 0, string.Empty, true));

// Assert
diagram.Links.Count.Should().Be(0);
}
}
Loading