-
-
Notifications
You must be signed in to change notification settings - Fork 12
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix: properly restore connections when changing parameter or return t…
…ypes of functions/modules fixes #20
- Loading branch information
Showing
3 changed files
with
96 additions
and
9 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
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,79 @@ | ||
using System; | ||
using System.Linq; | ||
using System.Threading.Tasks; | ||
using Godot; | ||
using GodotTestDriver.Drivers; | ||
using GodotXUnitApi; | ||
using OpenScadGraphEditor.Nodes; | ||
using Xunit; | ||
|
||
namespace OpenScadGraphEditor.Tests | ||
{ | ||
public class ParameterRefactoringTests : MainWindowTest | ||
{ | ||
[GodotFact(Frame = GodotFactFrame.Process)] | ||
public async Task ChangingParameterTypesKeepsConnections() | ||
{ | ||
// when i create a module | ||
var moduleName = "mod" + Guid.NewGuid().ToString().Replace("-", ""); | ||
await MainWindow.AddModuleButton.ClickCenter(); | ||
await MainWindow.InvokableRefactorDialog.NameEdit.Type(moduleName); | ||
await MainWindow.InvokableRefactorDialog.AddParameterButton.ClickCenter(); | ||
await MainWindow.InvokableRefactorDialog.OkButton.ClickCenter(); | ||
|
||
var entryPoint = MainWindow.GraphEditor.Nodes.Last(); | ||
|
||
// and i add a plus node to the module | ||
await MainWindow.AddNode("++"); | ||
var plusNodeModule = MainWindow.GraphEditor.Nodes.Last(); | ||
|
||
// and i connect the first output of the entry point to the first input of the plus node | ||
await entryPoint.DragConnection(Port.Output(0), plusNodeModule, Port.Input(0)); | ||
|
||
// and i switch to the main graph | ||
await MainWindow.TabContainer.SelectTabWithTitle("<main>"); | ||
|
||
// and i create a module instance | ||
await MainWindow.AddNode(moduleName); | ||
var invocation = MainWindow.GraphEditor.Nodes.Last(); | ||
|
||
// and i move this a bit to the right | ||
await invocation.DragByOwnSize(2, 0); | ||
|
||
// and i create an add node | ||
await MainWindow.AddNode("++"); | ||
var plusNodeMain = MainWindow.GraphEditor.Nodes.Last(); | ||
// and i drag this a bit to the left | ||
await plusNodeMain.DragByOwnSize(-2, 0); | ||
|
||
// and i connect the output of the plus node to the input of the invocation | ||
await plusNodeMain.DragConnection(Port.Output(0), invocation, Port.Input(0)); | ||
|
||
// and i right-click the module invocation | ||
await invocation.ClickAtSelectionSpot(ButtonList.Right); | ||
// and i select the "Refactor <module>" entry in the popup menu | ||
await MainWindow.PopupMenu.SelectItemWithText("Refactor " + moduleName); | ||
|
||
// and i change the type of the parameter to "number" | ||
await MainWindow.InvokableRefactorDialog.ParameterLines.First().Type.SelectItemWithText("number"); | ||
// and i press the "OK" button | ||
await MainWindow.InvokableRefactorDialog.OkButton.ClickCenter(); | ||
|
||
// then | ||
// the input type of the invocation is now "number" | ||
Assert.Equal((int)PortType.Number, invocation.GetPortType(Port.Input(0))); | ||
|
||
// and the plus node in the main graph is still connected to the invocation | ||
Assert.True(MainWindow.GraphEditor.HasConnection(plusNodeMain, Port.Output(0), invocation, Port.Input(0))); | ||
|
||
// and when i go back to the module | ||
await MainWindow.TabContainer.SelectTabWithTitle(moduleName); | ||
|
||
// then the plus node in the module is still connected to the entry point | ||
Assert.True(MainWindow.GraphEditor.HasConnection(entryPoint, Port.Output(0), plusNodeModule, Port.Input(0))); | ||
// and the port type of the entry point is now "number" | ||
Assert.Equal((int)PortType.Number, entryPoint.GetPortType(Port.Output(0))); | ||
|
||
} | ||
} | ||
} |