-
Notifications
You must be signed in to change notification settings - Fork 213
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 #135 from Blazor-Diagrams/develop
Version 2.1.4
- Loading branch information
Showing
14 changed files
with
354 additions
and
11 deletions.
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
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
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
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
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
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
94 changes: 94 additions & 0 deletions
94
tests/Blazor.Diagrams.Core.Tests/Behaviors/EventsBehaviorTests.cs
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,94 @@ | ||
using Blazor.Diagrams.Core.Behaviors; | ||
using FluentAssertions; | ||
using Microsoft.AspNetCore.Components.Web; | ||
using System.Threading.Tasks; | ||
using Xunit; | ||
|
||
namespace Blazor.Diagrams.Core.Tests.Behaviors | ||
{ | ||
public class EventsBehaviorTests | ||
{ | ||
[Fact] | ||
public void Behavior_ShouldNotTriggerMouseClick_WhenItsRemoved() | ||
{ | ||
// Arrange | ||
var diagram = new Diagram(); | ||
diagram.UnregisterBehavior<EventsBehavior>(); | ||
var eventTriggered = false; | ||
|
||
// Act | ||
diagram.MouseClick += (m, e) => eventTriggered = true; | ||
diagram.OnMouseDown(null, new MouseEventArgs()); | ||
diagram.OnMouseUp(null, new MouseEventArgs()); | ||
|
||
// Assert | ||
eventTriggered.Should().BeFalse(); | ||
} | ||
|
||
[Fact] | ||
public void Behavior_ShouldTriggerMouseClick_WhenMouseDownThenUpWithoutMove() | ||
{ | ||
// Arrange | ||
var diagram = new Diagram(); | ||
var eventTriggered = false; | ||
|
||
// Act | ||
diagram.MouseClick += (m, e) => eventTriggered = true; | ||
diagram.OnMouseDown(null, new MouseEventArgs()); | ||
diagram.OnMouseUp(null, new MouseEventArgs()); | ||
|
||
// Assert | ||
eventTriggered.Should().BeTrue(); | ||
} | ||
|
||
[Fact] | ||
public void Behavior_ShouldNotTriggerMouseClick_WhenMouseMoves() | ||
{ | ||
// Arrange | ||
var diagram = new Diagram(); | ||
var eventTriggered = false; | ||
|
||
// Act | ||
diagram.MouseClick += (m, e) => eventTriggered = true; | ||
diagram.OnMouseDown(null, new MouseEventArgs()); | ||
diagram.OnMouseMove(null, new MouseEventArgs()); | ||
diagram.OnMouseUp(null, new MouseEventArgs()); | ||
|
||
// Assert | ||
eventTriggered.Should().BeFalse(); | ||
} | ||
|
||
[Fact] | ||
public void Behavior_ShouldTriggerMouseDoubleClick_WhenTwoMouseClicksHappenWithinTime() | ||
{ | ||
// Arrange | ||
var diagram = new Diagram(); | ||
var eventTriggered = false; | ||
|
||
// Act | ||
diagram.MouseDoubleClick += (m, e) => eventTriggered = true; | ||
diagram.OnMouseClick(null, new MouseEventArgs()); | ||
diagram.OnMouseClick(null, new MouseEventArgs()); | ||
|
||
// Assert | ||
eventTriggered.Should().BeTrue(); | ||
} | ||
|
||
[Fact] | ||
public async Task Behavior_ShouldNotTriggerMouseDoubleClick_WhenTimeExceeds500() | ||
{ | ||
// Arrange | ||
var diagram = new Diagram(); | ||
var eventTriggered = false; | ||
|
||
// Act | ||
diagram.MouseDoubleClick += (m, e) => eventTriggered = true; | ||
diagram.OnMouseClick(null, new MouseEventArgs()); | ||
await Task.Delay(520); | ||
diagram.OnMouseClick(null, new MouseEventArgs()); | ||
|
||
// Assert | ||
eventTriggered.Should().BeFalse(); | ||
} | ||
} | ||
} |
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,95 @@ | ||
using Blazor.Diagrams.Core.Geometry; | ||
using Blazor.Diagrams.Core.Models; | ||
using FluentAssertions; | ||
using Xunit; | ||
|
||
namespace Blazor.Diagrams.Core.Tests | ||
{ | ||
public class DiagramTests | ||
{ | ||
[Fact] | ||
public void GetScreenPoint_ShouldReturnCorrectPoint() | ||
{ | ||
// Arrange | ||
var diagram = new Diagram(); | ||
|
||
// Act | ||
diagram.SetZoom(1.234); | ||
diagram.UpdatePan(50, 50); | ||
diagram.SetContainer(new Rectangle(30, 65, 1000, 793)); | ||
var pt = diagram.GetScreenPoint(100, 200); | ||
|
||
// Assert | ||
pt.X.Should().Be(203.4); // 2*X + panX + left | ||
pt.Y.Should().Be(361.8); // 2*Y + panY + top | ||
} | ||
|
||
[Fact] | ||
public void ZoomToFit_ShouldUseSelectedNodesIfAny() | ||
{ | ||
// Arrange | ||
var diagram = new Diagram(); | ||
diagram.SetContainer(new Rectangle(new Point(0, 0), new Size(1080, 768))); | ||
diagram.Nodes.Add(new NodeModel(new Point(50, 50)) | ||
{ | ||
Size = new Size(100, 80) | ||
}); | ||
diagram.SelectModel(diagram.Nodes[0], true); | ||
|
||
// Act | ||
diagram.ZoomToFit(10); | ||
|
||
// Assert | ||
diagram.Zoom.Should().BeApproximately(7.68, 0.001); | ||
diagram.Pan.X.Should().Be(-40); | ||
diagram.Pan.Y.Should().Be(-40); | ||
} | ||
|
||
[Fact] | ||
public void ZoomToFit_ShouldUseNodesWhenNoneSelected() | ||
{ | ||
// Arrange | ||
var diagram = new Diagram(); | ||
diagram.SetContainer(new Rectangle(new Point(0, 0), new Size(1080, 768))); | ||
diagram.Nodes.Add(new NodeModel(new Point(50, 50)) | ||
{ | ||
Size = new Size(100, 80) | ||
}); | ||
|
||
// Act | ||
diagram.ZoomToFit(10); | ||
|
||
// Assert | ||
diagram.Zoom.Should().BeApproximately(7.68, 0.001); | ||
diagram.Pan.X.Should().Be(-40); | ||
diagram.Pan.Y.Should().Be(-40); | ||
} | ||
|
||
[Fact] | ||
public void ZoomToFit_ShouldTriggerAppropriateEvents() | ||
{ | ||
// Arrange | ||
var diagram = new Diagram(); | ||
diagram.SetContainer(new Rectangle(new Point(0, 0), new Size(1080, 768))); | ||
diagram.Nodes.Add(new NodeModel(new Point(50, 50)) | ||
{ | ||
Size = new Size(100, 80) | ||
}); | ||
|
||
var refreshes = 0; | ||
var zoomChanges = 0; | ||
var panChanges = 0; | ||
|
||
// Act | ||
diagram.Changed += () => refreshes++; | ||
diagram.ZoomChanged += () => zoomChanges++; | ||
diagram.PanChanged += () => panChanges++; | ||
diagram.ZoomToFit(10); | ||
|
||
// Assert | ||
refreshes.Should().Be(1); | ||
zoomChanges.Should().Be(1); | ||
panChanges.Should().Be(1); | ||
} | ||
} | ||
} |
Oops, something went wrong.