1
0

StorageInteractionTest.cs 2.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162
  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. // UIs should still be open
  39. Assert.That(IsUiOpen(StorageComponent.StorageUiKey.Key), Is.True);
  40. Assert.That(IsUiOpen(PdaUiKey.Key), Is.True);
  41. }
  42. /// <summary>
  43. /// Retrieve the control that corresponds to the given entity in the currently open storage UI.
  44. /// </summary>
  45. private ItemGridPiece GetStorageControl(NetEntity target)
  46. {
  47. var uid = ToClient(target);
  48. var hotbar = GetWidget<HotbarGui>();
  49. var storageContainer = GetControlFromField<Control>(nameof(HotbarGui.StorageContainer), hotbar);
  50. return GetControlFromChildren<ItemGridPiece>(c => c.Entity == uid, storageContainer);
  51. }
  52. }