From 7ef5375e4fdd4cd398e60917d20dbcf444dd7332 Mon Sep 17 00:00:00 2001 From: Rxup Date: Tue, 12 Nov 2024 05:32:17 +0300 Subject: [PATCH] Create SpeciesBUiTest.cs (#915) --- .../Tests/Backmen/Body/SpeciesBUiTest.cs | 68 +++++++++++++++++++ 1 file changed, 68 insertions(+) create mode 100644 Content.IntegrationTests/Tests/Backmen/Body/SpeciesBUiTest.cs diff --git a/Content.IntegrationTests/Tests/Backmen/Body/SpeciesBUiTest.cs b/Content.IntegrationTests/Tests/Backmen/Body/SpeciesBUiTest.cs new file mode 100644 index 00000000000..bbf5be8bc1a --- /dev/null +++ b/Content.IntegrationTests/Tests/Backmen/Body/SpeciesBUiTest.cs @@ -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 GetInterfaces(UserInterfaceComponent comp) + { + return (Dictionary) + 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(); + var factoryComp = server.ResolveDependency(); + + await server.WaitAssertion(() => + { + var bUiSys = server.System(); + + Assert.That(proto.TryIndex("BaseMobSpeciesTest", out var baseEnt), Is.True); + Assert.That(baseEnt, Is.Not.Null); + Assert.That(baseEnt.TryGetComponent(out var bUiBase, factoryComp), Is.True); + Assert.That(bUiBase, Is.Not.Null); + var baseKeys = GetInterfaces(bUiBase).Keys.ToArray(); + + foreach (var specie in proto.EnumeratePrototypes()) + { + var ent = proto.Index(specie.Prototype); + Assert.That(ent.TryGetComponent(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(); + } +}