]> git.smokeofanarchy.ru Git - space-station-14.git/commitdiff
Add BUI ctor tests (#31463)
authormetalgearsloth <31366439+metalgearsloth@users.noreply.github.com>
Mon, 26 Aug 2024 07:39:48 +0000 (17:39 +1000)
committerGitHub <noreply@github.com>
Mon, 26 Aug 2024 07:39:48 +0000 (17:39 +1000)
5 lines of eaten iocmanager.injectdependencies led to this.

Content.Client/UserInterface/Controls/ProgressTextureRect.cs
Content.IntegrationTests/Tests/UserInterface/UiControlTest.cs [new file with mode: 0644]

index 2b8d93a5d4773610e1aea8596fc19ac9f04ae24e..8454ae0892b9b67b8c6ffa06950df3494e3762de 100644 (file)
@@ -9,7 +9,12 @@ namespace Content.Client.UserInterface.Controls
     {
         public float Progress;
 
-        private readonly ProgressColorSystem _progressColor = IoCManager.Resolve<IEntityManager>().System<ProgressColorSystem>();
+        private readonly ProgressColorSystem _progressColor;
+
+        public ProgressTextureRect()
+        {
+            _progressColor = IoCManager.Resolve<IEntityManager>().System<ProgressColorSystem>();
+        }
 
         protected override void Draw(DrawingHandleScreen handle)
         {
diff --git a/Content.IntegrationTests/Tests/UserInterface/UiControlTest.cs b/Content.IntegrationTests/Tests/UserInterface/UiControlTest.cs
new file mode 100644 (file)
index 0000000..c8378bb
--- /dev/null
@@ -0,0 +1,58 @@
+using System.Linq;
+using Content.Client.Chat.UI;
+using Content.Client.LateJoin;
+using Robust.Client.UserInterface.CustomControls;
+using Robust.Shared.ContentPack;
+using Robust.Shared.IoC;
+using Robust.Shared.Reflection;
+
+namespace Content.IntegrationTests.Tests.UserInterface;
+
+[TestFixture]
+public sealed class UiControlTest
+{
+    // You should not be adding to this.
+    private Type[] _ignored = new Type[]
+    {
+        typeof(EmotesMenu),
+        typeof(LateJoinGui),
+    };
+
+    /// <summary>
+    /// Tests that all windows can be instantiated successfully.
+    /// </summary>
+    [Test]
+    public async Task TestWindows()
+    {
+        var pair = await PoolManager.GetServerClient(new PoolSettings()
+        {
+            Connected = true,
+        });
+        var activator = pair.Client.ResolveDependency<IDynamicTypeFactory>();
+        var refManager = pair.Client.ResolveDependency<IReflectionManager>();
+        var loader = pair.Client.ResolveDependency<IModLoader>();
+
+        await pair.Client.WaitAssertion(() =>
+        {
+            foreach (var type in refManager.GetAllChildren(typeof(BaseWindow)))
+            {
+                if (type.IsAbstract || _ignored.Contains(type))
+                    continue;
+
+                if (!loader.IsContentType(type))
+                    continue;
+
+                // If it has no empty ctor then skip it instead of figuring out what args it needs.
+                var ctor = type.GetConstructor(Type.EmptyTypes);
+
+                if (ctor == null)
+                    continue;
+
+                // Don't inject because the control themselves have to do it.
+                activator.CreateInstance(type, oneOff: true, inject: false);
+            }
+        });
+
+        await pair.CleanReturnAsync();
+    }
+}