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

feat: fire input action events, synchronize methods #1

Merged
merged 23 commits into from
Jan 22, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
23 commits
Select commit Hold shift + click to select a range
b2dcb6f
test: add tests for global input state
wlsnmrk Jan 9, 2024
f162565
test: add tests for action input events
wlsnmrk Jan 22, 2024
0765dfb
fix: fire action input events
wlsnmrk Jan 22, 2024
f8b56a7
test: add tests for immediate input state
wlsnmrk Jan 9, 2024
44ef8bb
refactor: synchronize keyboard-input simulation
wlsnmrk Jan 9, 2024
aebf9ad
refactor: synchronize mouse-input simulation
wlsnmrk Jan 9, 2024
b243970
refactor: synchronize Control driver methods
wlsnmrk Jan 10, 2024
b426dc9
refactor: synchronize BaseButton driver methods
wlsnmrk Jan 10, 2024
dae4664
test: verify Camera2D stability after move
wlsnmrk Jan 10, 2024
7b420f6
refactor: synchronize ItemList driver methods
wlsnmrk Jan 10, 2024
1f8c618
refactor: synchronize LineEdit driver methods
wlsnmrk Jan 10, 2024
bf330df
refactor: synchronize OptionButton driver methods
wlsnmrk Jan 10, 2024
fc5330e
refactor: synchronize PopupMenu driver methods
wlsnmrk Jan 10, 2024
0d1b06f
refactor: synchronize TextEdit driver methods
wlsnmrk Jan 10, 2024
77905a9
refactor: synchronize Window driver methods
wlsnmrk Jan 10, 2024
8199dbd
docs: update description of WindowDriver::Close()
wlsnmrk Jan 10, 2024
8cf9589
refactor: synchronize TabContainer driver methods
wlsnmrk Jan 10, 2024
e77912e
docs: fix keyboard-input simulation return values
wlsnmrk Jan 10, 2024
7ab5576
refactor: make Fixture scene loading synchronous
wlsnmrk Jan 10, 2024
91a6ba9
refactor: wait less after adding node in Fixture
wlsnmrk Jan 10, 2024
59bd20c
feat: synchronous Camera2D motion-start method
wlsnmrk Jan 13, 2024
aca85b3
docs: updated README examples for synchrony
wlsnmrk Jan 10, 2024
6a952c1
docs: fix return values for input, drivers
wlsnmrk Jan 22, 2024
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
99 changes: 99 additions & 0 deletions GodotTestDriver.Tests/ActionsControlExtensionsTest.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,99 @@
namespace Chickensoft.GodotTestDriver.Tests;

using Chickensoft.GoDotTest;
using Godot;
using GodotTestDriver.Input;
using JetBrains.Annotations;
using Shouldly;

[UsedImplicitly]
public partial class ActionsControlExtensionsTest : DriverTest
{
private partial class ActionInputEventTestNode : Node
{
public bool HasInputEventFired { get; set; }
public bool WasInputPressed { get; set; }
public StringName InputEventName { get; set; } = string.Empty;

public override void _Input(InputEvent @event)
{
if (@event.IsAction(InputEventName))
{
HasInputEventFired = true;
WasInputPressed = @event.IsActionPressed(InputEventName);
}
}
}

private const string TestAction = "test_action";

public ActionsControlExtensionsTest(Node testScene) : base(testScene)
{
}

[Test]
public void StartActionSetsGlobalActionPressed()
{
Input.IsActionPressed(TestAction).ShouldBeFalse();
RootNode.StartAction(TestAction);
Input.IsActionPressed(TestAction).ShouldBeTrue();
RootNode.EndAction(TestAction);
}

[Test]
public void EndActionUnsetsGlobalActionPressed()
{
RootNode.StartAction(TestAction);
RootNode.EndAction(TestAction);
Input.IsActionPressed(TestAction).ShouldBeFalse();
}

[Test]
public void StartActionSetsGlobalActionJustPressed()
{
RootNode.StartAction(TestAction);
Input.IsActionJustPressed(TestAction).ShouldBeTrue();
RootNode.EndAction(TestAction);
}

[Test]
public void EndActionSetsGlobalActionJustReleased()
{
RootNode.StartAction(TestAction);
RootNode.EndAction(TestAction);
Input.IsActionJustReleased(TestAction).ShouldBeTrue();
}

[Test]
public void StartActionSendsInputEvent()
{
var inputTestNode = new ActionInputEventTestNode
{
InputEventName = TestAction
};
RootNode.AddChild(inputTestNode);
inputTestNode.HasInputEventFired.ShouldBeFalse();
inputTestNode.StartAction(TestAction);
inputTestNode.HasInputEventFired.ShouldBeTrue();
inputTestNode.WasInputPressed.ShouldBeTrue();
inputTestNode.EndAction(TestAction);
RootNode.RemoveChild(inputTestNode); // Remove immediately since we won't wait a frame for the free
inputTestNode.QueueFree();
}

[Test]
public void EndActionSendsInputEvent()
{
var inputTestNode = new ActionInputEventTestNode
{
InputEventName = TestAction
};
RootNode.AddChild(inputTestNode);
inputTestNode.HasInputEventFired.ShouldBeFalse();
inputTestNode.EndAction(TestAction);
inputTestNode.HasInputEventFired.ShouldBeTrue();
inputTestNode.WasInputPressed.ShouldBeFalse();
RootNode.RemoveChild(inputTestNode); // Remove immediately since we won't wait a frame for the free
inputTestNode.QueueFree();
}
}
3 changes: 3 additions & 0 deletions GodotTestDriver.Tests/ActionsControlExtensionsTest.tscn
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
[gd_scene format=3 uid="uid://busk27caw7oi8"]

[node name="ActionsControlExtensionsTest" type="Node"]
13 changes: 6 additions & 7 deletions GodotTestDriver.Tests/ButtonDriverTest.cs
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
namespace Chickensoft.GodotTestDriver.Tests;

using System;
using System.Threading.Tasks;
using Chickensoft.GoDotTest;
using Godot;
using GodotTestDriver.Drivers;
Expand All @@ -23,34 +22,34 @@ public ButtonDriverTest(Node testScene) : base(testScene)
}

[Test]
public async Task ClickingWorks()
public void ClickingWorks()
{
// WHEN
// i click the button
await _button.ClickCenter();
_button.ClickCenter();
// the label text changes.
_label.Text.ShouldBe("did work");
// and the panel disappears
_panel.IsVisible.ShouldBeFalse();
}

[Test]
public async Task ClickingDisabledButtonThrowsException()
public void ClickingDisabledButtonThrowsException()
{
// SETUP
_button.PresentRoot.Disabled = true;
// WHEN
// i click the button then an exception is thrown
await Should.ThrowAsync<InvalidOperationException>(async () => await _button.ClickCenter());
Should.Throw<InvalidOperationException>(() => _button.ClickCenter());
}

[Test]
public async Task ClickingHiddenButtonThrowsException()
public void ClickingHiddenButtonThrowsException()
{
// SETUP
_button.PresentRoot.Visible = false;
// WHEN
// i click the button then an exception is thrown
await Should.ThrowAsync<InvalidOperationException>(async () => await _button.ClickCenter());
Should.Throw<InvalidOperationException>(() => _button.ClickCenter());
}
}
8 changes: 5 additions & 3 deletions GodotTestDriver.Tests/Camera2DDriverTest.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@

namespace Chickensoft.GodotTestDriver.Tests;

using System.Threading.Tasks;
Expand Down Expand Up @@ -37,10 +36,13 @@ public async Task Camera2DCanMove()
{
// WHEN
// I move camera to off-center sprite
await _camera2D.MoveIntoView(_offCenterSprite.GlobalPosition, 2);
var moveTask = _camera2D.MoveIntoView(_offCenterSprite.GlobalPosition, 2);

// THEN
// the off center sprite is not visible
// the camera has successfully moved to the new position
(await moveTask).ShouldBeTrue();

// and off center sprite is visible
_offCenterSprite.IsFullyInView.ShouldBeTrue();
}
}
7 changes: 3 additions & 4 deletions GodotTestDriver.Tests/CheckBoxDriverTest.cs
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
namespace Chickensoft.GodotTestDriver.Tests;

using System.Threading.Tasks;
using Chickensoft.GoDotTest;
using Godot;
using GodotTestDriver.Drivers;
Expand All @@ -18,19 +17,19 @@ public CheckBoxDriverTest(Node testScene) : base(testScene)
}

[Test]
public async Task ClickingChecksAndUnchecks()
public void ClickingChecksAndUnchecks()
{
// WHEN
// i click the checkbox
await _checkBox.ClickCenter();
_checkBox.ClickCenter();

// THEN
// the checkbox is checked
_checkBox.IsChecked.ShouldBeTrue();

// WHEN
// i click the checkbox again
await _checkBox.ClickCenter();
_checkBox.ClickCenter();

// THEN
// the checkbox is unchecked
Expand Down
21 changes: 10 additions & 11 deletions GodotTestDriver.Tests/GraphEditDriverTest.cs
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
namespace Chickensoft.GodotTestDriver.Tests;
namespace Chickensoft.GodotTestDriver.Tests;

using System.Linq;
using System.Threading.Tasks;
using Chickensoft.GoDotTest;
using Godot;
using GodotTestDriver.Drivers;
Expand Down Expand Up @@ -51,15 +50,15 @@ public void InspectionWorks()
}

[Test]
public async Task DraggingNodesWorks()
public void DraggingNodesWorks()
{
// SETUP
var firstNode = _graphEdit.Nodes.First();

var firstNodeOffset = firstNode.Offset;
// WHEN
// i drag the first node
await firstNode.DragByOwnSize(2, 0);
firstNode.DragByOwnSize(2, 0);

// THEN
// the offset has changed by 2x it's width
Expand All @@ -71,50 +70,50 @@ public async Task DraggingNodesWorks()
}

[Test]
public async Task DraggingConnectionsWorks()
public void DraggingConnectionsWorks()
{
// SETUP
var firstNode = _graphEdit.Nodes.First();
var secondNode = _graphEdit.Nodes.Last();

// WHEN
// i drag a connection from the first node to the second node
await firstNode.DragConnection(Port.Output(0), secondNode, Port.Input(0));
firstNode.DragConnection(Port.Output(0), secondNode, Port.Input(0));

// THEN
// the connection works
_graphEdit.HasConnection(firstNode, Port.Output(0), secondNode, Port.Input(0)).ShouldBeTrue();
}

[Test]
public async Task DraggingConnectionsInReverseWorks()
public void DraggingConnectionsInReverseWorks()
{
// SETUP
var firstNode = _graphEdit.Nodes.First();
var secondNode = _graphEdit.Nodes.Last();

// WHEN
// i drag a connection from the second node to the first node
await secondNode.DragConnection(Port.Input(0), firstNode, Port.Output(0));
secondNode.DragConnection(Port.Input(0), firstNode, Port.Output(0));

// THEN
// the connection works
_graphEdit.HasConnection(firstNode, Port.Output(0), secondNode, Port.Input(0)).ShouldBeTrue();
}

[Test]
public async Task DisconnectingWorks()
public void DisconnectingWorks()
{
// SETUP
var firstNode = _graphEdit.Nodes.First();
var secondNode = _graphEdit.Nodes.Last();

// make a connection
await firstNode.DragConnection(Port.Output(0), secondNode, Port.Input(0));
firstNode.DragConnection(Port.Output(0), secondNode, Port.Input(0));

// WHEN
// i disconnect the connection, by dragging it from the second node to the first node
await secondNode.DragConnection(Port.Input(0), firstNode, Port.Output(0));
secondNode.DragConnection(Port.Input(0), firstNode, Port.Output(0));

// THEN
// the connection is gone
Expand Down
Loading