]> git.smokeofanarchy.ru Git - space-station-14.git/commitdiff
Add interaction test for retractable arm blade (#38452)
authorTayrtahn <tayrtahn@gmail.com>
Sat, 21 Jun 2025 01:31:32 +0000 (21:31 -0400)
committerGitHub <noreply@github.com>
Sat, 21 Jun 2025 01:31:32 +0000 (21:31 -0400)
* Add interaction test for retractable arm blade

* Update for HandsSystem refactor

* Revert "Update for HandsSystem refactor"

This reverts commit e01bb9a7e318dd916240d57b30f48af9594bff1f.

* Combine WaitAssertion blocks

Content.IntegrationTests/Tests/Actions/RetractableItemActionTest.cs [new file with mode: 0644]

diff --git a/Content.IntegrationTests/Tests/Actions/RetractableItemActionTest.cs b/Content.IntegrationTests/Tests/Actions/RetractableItemActionTest.cs
new file mode 100644 (file)
index 0000000..76c1a03
--- /dev/null
@@ -0,0 +1,65 @@
+#nullable enable
+using Content.IntegrationTests.Tests.Interaction;
+using Content.Shared.Actions;
+using Content.Shared.Hands.EntitySystems;
+using Content.Shared.RetractableItemAction;
+using Robust.Shared.Prototypes;
+
+namespace Content.IntegrationTests.Tests.Actions;
+
+public sealed class RetractableItemActionTest : InteractionTest
+{
+    private static readonly EntProtoId ArmBladeActionProtoId = "ActionRetractableItemArmBlade";
+
+    /// <summary>
+    /// Gives the player the arm blade action, then activates it and makes sure they are given the blade.
+    /// Afterwards, uses the action again to retract the blade and makes sure their hand is empty.
+    /// </summary>
+    [Test]
+    public async Task ArmBladeActivateDeactivateTest()
+    {
+        var actionsSystem = Server.System<SharedActionsSystem>();
+        var handsSystem = Server.System<SharedHandsSystem>();
+        var playerUid = SEntMan.GetEntity(Player);
+
+        await Server.WaitAssertion(() =>
+        {
+            // Make sure the player's hand starts empty
+            var heldItem = Hands.ActiveHandEntity;
+            Assert.That(heldItem, Is.Null, $"Player is holding an item ({SEntMan.ToPrettyString(heldItem)}) at start of test.");
+
+            // Inspect the action prototype to find the item it spawns
+            var armBladeActionProto = ProtoMan.Index(ArmBladeActionProtoId);
+
+            // Find the component
+            Assert.That(armBladeActionProto.TryGetComponent<RetractableItemActionComponent>(out var actionComp, SEntMan.ComponentFactory));
+            // Get the item protoId from the component
+            var spawnedProtoId = actionComp!.SpawnedPrototype;
+
+            // Add the action to the player
+            var actionUid = actionsSystem.AddAction(playerUid, ArmBladeActionProtoId);
+            // Make sure the player has the action now
+            Assert.That(actionUid, Is.Not.Null, "Failed to add action to player.");
+            var actionEnt = actionsSystem.GetAction(actionUid);
+
+            // Make sure the player's hand is still empty
+            heldItem = Hands.ActiveHandEntity;
+            Assert.That(heldItem, Is.Null, $"Player is holding an item ({SEntMan.ToPrettyString(heldItem)}) after adding action.");
+
+            // Activate the arm blade
+            actionsSystem.PerformAction(ToServer(Player), actionEnt!.Value);
+
+            // Make sure the player is now holding the expected item
+            heldItem = Hands.ActiveHandEntity;
+            Assert.That(heldItem, Is.Not.Null, $"Expected player to be holding {spawnedProtoId} but was holding nothing.");
+            AssertPrototype(spawnedProtoId, SEntMan.GetNetEntity(heldItem));
+
+            // Use the action again to retract the arm blade
+            actionsSystem.PerformAction(ToServer(Player), actionEnt.Value);
+
+            // Make sure the player's hand is empty again
+            heldItem = Hands.ActiveHandEntity;
+            Assert.That(heldItem, Is.Null, $"Player is still holding an item ({SEntMan.ToPrettyString(heldItem)}) after second use.");
+        });
+    }
+}