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

Create SpeciesBUiTest.cs #915

Merged
merged 1 commit into from
Nov 12, 2024
Merged
Changes from all commits
Commits
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
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();
}
}
Loading