UiControlTest.cs 1.7 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758
  1. using System.Linq;
  2. using Content.Client.Chat.UI;
  3. using Content.Client.LateJoin;
  4. using Robust.Client.UserInterface.CustomControls;
  5. using Robust.Shared.ContentPack;
  6. using Robust.Shared.IoC;
  7. using Robust.Shared.Reflection;
  8. namespace Content.IntegrationTests.Tests.UserInterface;
  9. [TestFixture]
  10. public sealed class UiControlTest
  11. {
  12. // You should not be adding to this.
  13. private Type[] _ignored = new Type[]
  14. {
  15. typeof(EmotesMenu),
  16. typeof(LateJoinGui),
  17. };
  18. /// <summary>
  19. /// Tests that all windows can be instantiated successfully.
  20. /// </summary>
  21. [Test]
  22. public async Task TestWindows()
  23. {
  24. var pair = await PoolManager.GetServerClient(new PoolSettings()
  25. {
  26. Connected = true,
  27. });
  28. var activator = pair.Client.ResolveDependency<IDynamicTypeFactory>();
  29. var refManager = pair.Client.ResolveDependency<IReflectionManager>();
  30. var loader = pair.Client.ResolveDependency<IModLoader>();
  31. await pair.Client.WaitAssertion(() =>
  32. {
  33. foreach (var type in refManager.GetAllChildren(typeof(BaseWindow)))
  34. {
  35. if (type.IsAbstract || _ignored.Contains(type))
  36. continue;
  37. if (!loader.IsContentType(type))
  38. continue;
  39. // If it has no empty ctor then skip it instead of figuring out what args it needs.
  40. var ctor = type.GetConstructor(Type.EmptyTypes);
  41. if (ctor == null)
  42. continue;
  43. // Don't inject because the control themselves have to do it.
  44. activator.CreateInstance(type, oneOff: true, inject: false);
  45. }
  46. });
  47. await pair.CleanReturnAsync();
  48. }
  49. }