StorageInteractionTest.cs 3.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687
  1. using Content.Client.UserInterface.Systems.Hotbar.Widgets;
  2. using Content.Client.UserInterface.Systems.Storage.Controls;
  3. using Content.IntegrationTests.Tests.Interaction;
  4. using Content.Shared.Input;
  5. using Content.Shared.PDA;
  6. using Content.Shared.Storage;
  7. using Content.Shared.Timing;
  8. using Robust.Client.UserInterface;
  9. using Robust.Shared.Containers;
  10. using Robust.Shared.GameObjects;
  11. namespace Content.IntegrationTests.Tests.Storage;
  12. public sealed class StorageInteractionTest : InteractionTest
  13. {
  14. /// <summary>
  15. /// Check that players can interact with items in storage if the storage UI is open
  16. /// </summary>
  17. [Test]
  18. public async Task UiInteractTest()
  19. {
  20. var sys = Server.System<SharedContainerSystem>();
  21. await SpawnTarget("ClothingBackpack");
  22. var backpack = ToServer(Target);
  23. // Initially no BUI is open.
  24. Assert.That(IsUiOpen(StorageComponent.StorageUiKey.Key), Is.False);
  25. Assert.That(IsUiOpen(PdaUiKey.Key), Is.False);
  26. await Server.WaitPost(() => SEntMan.RemoveComponent<UseDelayComponent>(STarget!.Value));
  27. await RunTicks(5);
  28. // Activating the backpack opens the UI
  29. await Activate();
  30. Assert.That(IsUiOpen(StorageComponent.StorageUiKey.Key), Is.True);
  31. Assert.That(IsUiOpen(PdaUiKey.Key), Is.False);
  32. // Activating it again closes the UI
  33. await Activate();
  34. Assert.That(IsUiOpen(StorageComponent.StorageUiKey.Key), Is.False);
  35. // Open it again
  36. await Activate();
  37. Assert.That(IsUiOpen(StorageComponent.StorageUiKey.Key), Is.True);
  38. // Pick up a PDA
  39. var pda = await PlaceInHands("PassengerPDA");
  40. var sPda = ToServer(pda);
  41. Assert.That(sys.IsEntityInContainer(sPda), Is.True);
  42. Assert.That(sys.TryGetContainingContainer((sPda, null), out var container));
  43. Assert.That(container!.Owner, Is.EqualTo(SPlayer));
  44. // Insert the PDA into the backpack
  45. await Interact();
  46. Assert.That(sys.TryGetContainingContainer((sPda, null), out container));
  47. Assert.That(container!.Owner, Is.EqualTo(backpack));
  48. // Use "e" / ActivateInWorld to open the PDA UI while it is still in the backpack.
  49. var ctrl = GetStorageControl(pda);
  50. await ClickControl(ctrl, ContentKeyFunctions.ActivateItemInWorld);
  51. await RunTicks(10);
  52. Assert.That(IsUiOpen(StorageComponent.StorageUiKey.Key), Is.True);
  53. Assert.That(IsUiOpen(PdaUiKey.Key), Is.True);
  54. // Click on the pda to pick it up and remove it from the backpack.
  55. await ClickControl(ctrl, ContentKeyFunctions.MoveStoredItem);
  56. await RunTicks(10);
  57. Assert.That(sys.TryGetContainingContainer((sPda, null), out container));
  58. Assert.That(container!.Owner, Is.EqualTo(SPlayer));
  59. // UIs should still be open
  60. Assert.That(IsUiOpen(StorageComponent.StorageUiKey.Key), Is.True);
  61. Assert.That(IsUiOpen(PdaUiKey.Key), Is.True);
  62. }
  63. /// <summary>
  64. /// Retrieve the control that corresponds to the given entity in the currently open storage UI.
  65. /// </summary>
  66. private ItemGridPiece GetStorageControl(NetEntity target)
  67. {
  68. var uid = ToClient(target);
  69. var hotbar = GetWidget<HotbarGui>();
  70. var storageContainer = GetControlFromField<Control>(nameof(HotbarGui.StorageContainer), hotbar);
  71. return GetControlFromChildren<ItemGridPiece>(c => c.Entity == uid, storageContainer);
  72. }
  73. }