Skip to content

Commit

Permalink
Create SpeciesBUiTest.cs (#915)
Browse files Browse the repository at this point in the history
  • Loading branch information
Rxup authored Nov 12, 2024
1 parent d4b8def commit 7ef5375
Showing 1 changed file with 68 additions and 0 deletions.
68 changes: 68 additions & 0 deletions Content.IntegrationTests/Tests/Backmen/Body/SpeciesBUiTest.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,68 @@
using System.Collections.Generic;
using System.Linq;
using System.Reflection;
using Content.Shared.Backmen.Surgery;
using Content.Shared.Humanoid;
using Content.Shared.Humanoid.Prototypes;
using Content.Shared.Store;
using Robust.Shared.GameObjects;
using Robust.Shared.Prototypes;

namespace Content.IntegrationTests.Tests.Backmen.Body;

[TestFixture]
public sealed class SpeciesBUiTest
{
[TestPrototypes]
private const string Prototypes = @"
- type: entity
name: BaseMobSpeciesTest
id: BaseMobSpeciesTest
parent: BaseMobSpecies
";

private Dictionary<Enum, InterfaceData> GetInterfaces(UserInterfaceComponent comp)
{
return (Dictionary<Enum, InterfaceData>)
typeof(UserInterfaceComponent).GetField("Interfaces", BindingFlags.NonPublic | BindingFlags.Instance)!
.GetValue(comp);
}

[Test]
public async Task AllSpeciesHaveBaseBUiTest()
{
await using var pair = await PoolManager.GetServerClient(new PoolSettings
{
Dirty = true,
Connected = false
});

var server = pair.Server;
var proto = server.ResolveDependency<IPrototypeManager>();
var factoryComp = server.ResolveDependency<IComponentFactory>();

await server.WaitAssertion(() =>
{
var bUiSys = server.System<SharedUserInterfaceSystem>();

Assert.That(proto.TryIndex("BaseMobSpeciesTest", out var baseEnt), Is.True);
Assert.That(baseEnt, Is.Not.Null);
Assert.That(baseEnt.TryGetComponent<UserInterfaceComponent>(out var bUiBase, factoryComp), Is.True);
Assert.That(bUiBase, Is.Not.Null);
var baseKeys = GetInterfaces(bUiBase).Keys.ToArray();

foreach (var specie in proto.EnumeratePrototypes<SpeciesPrototype>())
{
var ent = proto.Index(specie.Prototype);
Assert.That(ent.TryGetComponent<UserInterfaceComponent>(out var bUi, factoryComp), Is.True);
Assert.That(bUi, Is.Not.Null);
var states = GetInterfaces(bUiBase);
foreach (var key in baseKeys)
{
Assert.That(states.ContainsKey(key), Is.True, $"Species {specie.ID} has not UserInterface of type enum.{key.GetType().Name}");
}
}
});
await pair.CleanReturnAsync();
}
}

0 comments on commit 7ef5375

Please sign in to comment.