forked from Blazor-Diagrams/Blazor.Diagrams
-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #26 from WiseTechGlobal/pan_changed_backup
WI00713829 - Ports dont update when resizing nodes in Blazor Diagrams
- Loading branch information
Showing
5 changed files
with
145 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
2 changes: 1 addition & 1 deletion
2
tests/Blazor.Diagrams.Core.Tests/Blazor.Diagrams.Core.Tests.csproj
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,53 @@ | ||
using Blazor.Diagrams.Core.Geometry; | ||
using Blazor.Diagrams.Core.Models; | ||
using Moq; | ||
using Xunit; | ||
|
||
namespace Blazor.Diagrams.Core.Tests.Models | ||
{ | ||
public class NodeModelTest | ||
{ | ||
[Fact] | ||
public void UpdatePortOnSetPosition() | ||
{ | ||
var node = new NodeModel(position: new Point(100, 100)); | ||
node.Size = new Size(100, 100); | ||
|
||
var port = new PortModel(node, PortAlignment.BottomLeft, new Point(50, 50)); | ||
node.AddPort(port); | ||
|
||
var newX = 200; | ||
var newY = 300; | ||
|
||
//Act | ||
node.SetPosition(newX, newY); | ||
|
||
//Assert | ||
Assert.Equal(150, port.Position.X); | ||
Assert.Equal(250, port.Position.Y); | ||
} | ||
|
||
[Fact] | ||
public void SetPortPositionOnNodeSizeChangedIsCalledOnSetSize() | ||
{ | ||
// Arrange | ||
var oldWidth = 100.0; | ||
var oldHeight = 100.0; | ||
var newWidth = 500.0; | ||
var newHeight = 700.0; | ||
var deltaX = newWidth - oldWidth; | ||
var deltaY = newHeight - oldHeight; | ||
|
||
var node = new NodeModel(new Point(100, 100)) { Size = new Size(oldWidth, oldHeight) }; | ||
var portMock = new Mock<PortModel>(node, PortAlignment.BottomLeft, null, null); | ||
|
||
node.AddPort(portMock.Object); | ||
|
||
// Act | ||
node.SetSize(newWidth, newHeight); | ||
|
||
// Assert | ||
portMock.Verify(m => m.SetPortPositionOnNodeSizeChanged(deltaX, deltaY), Times.Once); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
using Blazor.Diagrams.Core.Geometry; | ||
using Blazor.Diagrams.Core.Models; | ||
using Xunit; | ||
|
||
namespace Blazor.Diagrams.Core.Tests.Models | ||
{ | ||
public class PortModelTest | ||
{ | ||
[Theory] | ||
[InlineData(PortAlignment.Top, 50, 0)] | ||
[InlineData(PortAlignment.TopLeft, 0, 0)] | ||
[InlineData(PortAlignment.TopRight, 100, 0)] | ||
[InlineData(PortAlignment.Bottom, 50, 100)] | ||
[InlineData(PortAlignment.BottomLeft, 0, 100)] | ||
[InlineData(PortAlignment.BottomRight, 100, 100)] | ||
[InlineData(PortAlignment.Left, 0, 50)] | ||
[InlineData(PortAlignment.Right, 100, 50)] | ||
public void SetPortPositionOnNodeSizeChangedCalculatesCorrectPosition(PortAlignment alignment, double expectedXPosition, double expectedYPosition) | ||
{ | ||
// Arrange | ||
var node = new NodeModel(); | ||
var port = new PortModel(node, alignment, new Point(0, 0)); | ||
node.Size = new Size(100, 100); | ||
|
||
// Act | ||
port.SetPortPositionOnNodeSizeChanged(100, 100); | ||
|
||
// Assert | ||
Assert.Equal(expectedXPosition, port.Position.X); | ||
Assert.Equal(expectedYPosition, port.Position.Y); | ||
} | ||
} | ||
} |