Allow InteractionTests to load other maps (#41226)

* load maps and marker

* cleanup

* sneaky doc

* sneaky doc2

---------

Co-authored-by: ArtisticRoomba <145879011+ArtisticRoomba@users.noreply.github.com>
This commit is contained in:
slarticodefast
2025-11-01 05:00:17 +01:00
committed by GitHub
parent 696debc606
commit 85e91a7551
6 changed files with 116 additions and 6 deletions

View File

@@ -24,6 +24,7 @@ using Robust.Shared.Map;
using Robust.Shared.Player;
using Robust.Shared.Prototypes;
using Robust.Shared.Timing;
using Robust.Shared.Utility;
using Robust.UnitTesting;
namespace Content.IntegrationTests.Tests.Interaction;
@@ -39,10 +40,20 @@ namespace Content.IntegrationTests.Tests.Interaction;
[FixtureLifeCycle(LifeCycle.InstancePerTestCase)]
public abstract partial class InteractionTest
{
/// <summary>
/// The prototype that will be spawned for the player entity at <see cref="PlayerCoords"/>.
/// This is not a full humanoid and only has one hand by default.
/// </summary>
protected virtual string PlayerPrototype => "InteractionTestMob";
/// <summary>
/// The map path to load for the integration test.
/// If null an empty map with a single 1x1 plating grid will be generated.
/// </summary>
protected virtual ResPath? TestMapPath => null;
protected TestPair Pair = default!;
protected TestMapData MapData => Pair.TestMap!;
protected TestMapData MapData = default!;
protected RobustIntegrationTest.ServerIntegrationInstance Server => Pair.Server;
protected RobustIntegrationTest.ClientIntegrationInstance Client => Pair.Client;
@@ -199,7 +210,10 @@ public abstract partial class InteractionTest
CUiSys = CEntMan.System<SharedUserInterfaceSystem>();
// Setup map.
await Pair.CreateTestMap();
if (TestMapPath == null)
MapData = await Pair.CreateTestMap();
else
MapData = await Pair.LoadTestMap(TestMapPath.Value);
PlayerCoords = SEntMan.GetNetCoordinates(Transform.WithEntityId(MapData.GridCoords.Offset(new Vector2(0.5f, 0.5f)), MapData.MapUid));
TargetCoords = SEntMan.GetNetCoordinates(Transform.WithEntityId(MapData.GridCoords.Offset(new Vector2(1.5f, 0.5f)), MapData.MapUid));

View File

@@ -0,0 +1,31 @@
using System.Linq;
using Robust.Shared.GameObjects;
using Robust.Shared.Map.Components;
using Robust.Shared.Utility;
namespace Content.IntegrationTests.Tests.Interaction;
/// <summary>
/// Makes sure that interaction test helper methods are working as intended.
/// </summary>
public sealed class InteractionTestTests : InteractionTest
{
protected override ResPath? TestMapPath => new("Maps/Test/empty.yml");
/// <summary>
/// Tests that map loading is working correctly.
/// </summary>
[Test]
public void MapLoadingTest()
{
// Make sure that there is only one grid.
var grids = SEntMan.AllEntities<MapGridComponent>().ToList();
Assert.That(grids, Has.Count.EqualTo(1), "Test map did not have exactly one grid.");
Assert.That(grids, Does.Contain(MapData.Grid), "MapData did not contain the loaded grid.");
// Make sure we loaded the right map.
// This name is defined in empty.yml
Assert.That(SEntMan.GetComponent<MetaDataComponent>(MapData.MapUid).EntityName, Is.EqualTo("Empty Debug Map"));
}
}