2021-02-11 01:13:03 -08:00
|
|
|
using System.Linq;
|
2022-10-12 01:16:23 -07:00
|
|
|
using Content.Client.UserInterface.Systems.Alerts.Controls;
|
|
|
|
|
using Content.Client.UserInterface.Systems.Alerts.Widgets;
|
2020-11-09 20:22:19 -08:00
|
|
|
using Content.Shared.Alert;
|
2021-02-11 01:13:03 -08:00
|
|
|
using Robust.Client.UserInterface;
|
2022-01-05 00:19:23 -08:00
|
|
|
using Robust.Server.Player;
|
2022-10-12 01:16:23 -07:00
|
|
|
using Robust.Shared.GameObjects;
|
2020-11-09 20:22:19 -08:00
|
|
|
|
|
|
|
|
namespace Content.IntegrationTests.Tests.GameObjects.Components.Mobs
|
|
|
|
|
{
|
|
|
|
|
[TestFixture]
|
2022-01-05 00:19:23 -08:00
|
|
|
[TestOf(typeof(AlertsComponent))]
|
2022-06-19 20:22:28 -07:00
|
|
|
public sealed class AlertsComponentTests
|
2020-11-09 20:22:19 -08:00
|
|
|
{
|
|
|
|
|
[Test]
|
|
|
|
|
public async Task AlertsTest()
|
|
|
|
|
{
|
2023-08-25 02:56:51 +02:00
|
|
|
await using var pair = await PoolManager.GetServerClient(new PoolSettings
|
2023-08-06 14:30:28 +12:00
|
|
|
{
|
|
|
|
|
Connected = true,
|
|
|
|
|
DummyTicker = false
|
|
|
|
|
});
|
2023-08-25 02:56:51 +02:00
|
|
|
var server = pair.Server;
|
|
|
|
|
var client = pair.Client;
|
2020-11-09 20:22:19 -08:00
|
|
|
|
2023-05-22 18:53:51 +10:00
|
|
|
var clientUIMgr = client.ResolveDependency<IUserInterfaceManager>();
|
|
|
|
|
var clientEntManager = client.ResolveDependency<IEntityManager>();
|
|
|
|
|
|
|
|
|
|
var entManager = server.ResolveDependency<IEntityManager>();
|
2021-02-11 01:13:03 -08:00
|
|
|
var serverPlayerManager = server.ResolveDependency<IPlayerManager>();
|
2022-01-05 00:19:23 -08:00
|
|
|
var alertsSystem = server.ResolveDependency<IEntitySystemManager>().GetEntitySystem<AlertsSystem>();
|
2020-11-09 20:22:19 -08:00
|
|
|
|
2022-08-14 20:45:58 -07:00
|
|
|
EntityUid playerUid = default;
|
2020-11-09 20:22:19 -08:00
|
|
|
await server.WaitAssertion(() =>
|
|
|
|
|
{
|
2022-08-14 20:45:58 -07:00
|
|
|
playerUid = serverPlayerManager.Sessions.Single().AttachedEntity.GetValueOrDefault();
|
2023-07-05 21:54:25 -07:00
|
|
|
#pragma warning disable NUnit2045 // Interdependent assertions.
|
|
|
|
|
Assert.That(playerUid, Is.Not.EqualTo(default));
|
2022-08-14 20:45:58 -07:00
|
|
|
// Making sure it exists
|
2023-05-22 18:53:51 +10:00
|
|
|
Assert.That(entManager.HasComponent<AlertsComponent>(playerUid));
|
2023-07-05 21:54:25 -07:00
|
|
|
#pragma warning restore NUnit2045
|
2020-11-09 20:22:19 -08:00
|
|
|
|
2022-08-14 20:45:58 -07:00
|
|
|
var alerts = alertsSystem.GetActiveAlerts(playerUid);
|
2023-07-05 21:54:25 -07:00
|
|
|
Assert.That(alerts, Is.Not.Null);
|
2022-08-14 20:45:58 -07:00
|
|
|
var alertCount = alerts.Count;
|
|
|
|
|
|
2024-05-23 22:43:04 -04:00
|
|
|
alertsSystem.ShowAlert(playerUid, "Debug1");
|
|
|
|
|
alertsSystem.ShowAlert(playerUid, "Debug2");
|
2022-08-14 20:45:58 -07:00
|
|
|
|
2022-08-28 13:26:35 +10:00
|
|
|
Assert.That(alerts, Has.Count.EqualTo(alertCount + 2));
|
2020-11-09 20:22:19 -08:00
|
|
|
});
|
|
|
|
|
|
2023-08-25 04:13:11 +02:00
|
|
|
await pair.RunTicksSync(5);
|
2022-08-14 20:45:58 -07:00
|
|
|
|
|
|
|
|
AlertsUI clientAlertsUI = default;
|
2020-11-09 20:22:19 -08:00
|
|
|
await client.WaitAssertion(() =>
|
|
|
|
|
{
|
2024-02-13 22:48:39 +01:00
|
|
|
var local = client.Session;
|
2023-07-05 21:54:25 -07:00
|
|
|
Assert.That(local, Is.Not.Null);
|
2024-02-13 22:48:39 +01:00
|
|
|
var controlled = local.AttachedEntity;
|
2023-07-05 21:54:25 -07:00
|
|
|
#pragma warning disable NUnit2045 // Interdependent assertions.
|
|
|
|
|
Assert.That(controlled, Is.Not.Null);
|
2022-08-14 20:45:58 -07:00
|
|
|
// Making sure it exists
|
2023-05-22 18:53:51 +10:00
|
|
|
Assert.That(clientEntManager.HasComponent<AlertsComponent>(controlled.Value));
|
2023-07-05 21:54:25 -07:00
|
|
|
#pragma warning restore Nunit2045
|
2020-11-09 20:22:19 -08:00
|
|
|
|
|
|
|
|
// find the alertsui
|
2022-10-12 01:16:23 -07:00
|
|
|
|
|
|
|
|
clientAlertsUI = FindAlertsUI(clientUIMgr.ActiveScreen);
|
2023-07-05 21:54:25 -07:00
|
|
|
Assert.That(clientAlertsUI, Is.Not.Null);
|
2020-11-09 20:22:19 -08:00
|
|
|
|
2023-07-05 21:54:25 -07:00
|
|
|
static AlertsUI FindAlertsUI(Control control)
|
2022-10-12 01:16:23 -07:00
|
|
|
{
|
|
|
|
|
if (control is AlertsUI alertUI)
|
|
|
|
|
return alertUI;
|
|
|
|
|
foreach (var child in control.Children)
|
|
|
|
|
{
|
|
|
|
|
var found = FindAlertsUI(child);
|
|
|
|
|
if (found != null)
|
|
|
|
|
return found;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return null;
|
|
|
|
|
}
|
|
|
|
|
|
2020-11-09 20:22:19 -08:00
|
|
|
// we should be seeing 3 alerts - our health, and the 2 debug alerts, in a specific order.
|
2022-08-14 20:45:58 -07:00
|
|
|
Assert.That(clientAlertsUI.AlertContainer.ChildCount, Is.GreaterThanOrEqualTo(3));
|
|
|
|
|
var alertControls = clientAlertsUI.AlertContainer.Children.Select(c => (AlertControl) c);
|
2024-05-23 22:43:04 -04:00
|
|
|
var alertIDs = alertControls.Select(ac => ac.Alert.ID).ToArray();
|
|
|
|
|
var expectedIDs = new[] { "HumanHealth", "Debug1", "Debug2" };
|
2021-02-06 14:32:48 +01:00
|
|
|
Assert.That(alertIDs, Is.SupersetOf(expectedIDs));
|
2020-11-09 20:22:19 -08:00
|
|
|
});
|
|
|
|
|
|
|
|
|
|
await server.WaitAssertion(() =>
|
|
|
|
|
{
|
2024-05-23 22:43:04 -04:00
|
|
|
alertsSystem.ClearAlert(playerUid, "Debug1");
|
2020-11-09 20:22:19 -08:00
|
|
|
});
|
2022-06-19 20:22:28 -07:00
|
|
|
|
2023-08-25 04:13:11 +02:00
|
|
|
await pair.RunTicksSync(5);
|
2020-11-09 20:22:19 -08:00
|
|
|
|
|
|
|
|
await client.WaitAssertion(() =>
|
|
|
|
|
{
|
2021-02-06 14:32:48 +01:00
|
|
|
// we should be seeing 2 alerts now because one was cleared
|
2022-08-14 20:45:58 -07:00
|
|
|
Assert.That(clientAlertsUI.AlertContainer.ChildCount, Is.GreaterThanOrEqualTo(2));
|
|
|
|
|
var alertControls = clientAlertsUI.AlertContainer.Children.Select(c => (AlertControl) c);
|
2024-05-23 22:43:04 -04:00
|
|
|
var alertIDs = alertControls.Select(ac => ac.Alert.ID).ToArray();
|
|
|
|
|
var expectedIDs = new[] { "HumanHealth", "Debug2" };
|
2021-02-06 14:32:48 +01:00
|
|
|
Assert.That(alertIDs, Is.SupersetOf(expectedIDs));
|
2020-11-09 20:22:19 -08:00
|
|
|
});
|
2022-08-14 20:45:58 -07:00
|
|
|
|
2023-08-25 02:56:51 +02:00
|
|
|
await pair.CleanReturnAsync();
|
2020-11-09 20:22:19 -08:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|