Add admin ui tests (#40914)

* Add admin ui tests

* fix notes test

* Apply suggestions from code review

---------

Co-authored-by: slarticodefast <161409025+slarticodefast@users.noreply.github.com>
This commit is contained in:
Leon Friedrich
2025-10-16 01:14:48 +13:00
committed by GitHub
parent 6fbcc6d0fb
commit bd1cbabea8
9 changed files with 128 additions and 7 deletions

View File

@@ -18,7 +18,7 @@
<Button Visible="True" Name="PopOut" Access="Public" Text="{Loc 'admin-logs-pop-out'}" StyleClasses="OpenBoth" HorizontalAlignment="Left" /> <Button Visible="True" Name="PopOut" Access="Public" Text="{Loc 'admin-logs-pop-out'}" StyleClasses="OpenBoth" HorizontalAlignment="Left" />
<Control HorizontalExpand="True" /> <Control HorizontalExpand="True" />
<Button Visible="False" Name="Bans" Text="{Loc 'admin-player-actions-bans'}" StyleClasses="OpenRight" /> <Button Visible="False" Name="Bans" Text="{Loc 'admin-player-actions-bans'}" StyleClasses="OpenRight" />
<Button Visible="False" Name="Notes" Text="{Loc 'admin-player-actions-notes'}" StyleClasses="OpenBoth" /> <Button Visible="False" Access="Public" Name="Notes" Text="{Loc 'admin-player-actions-notes'}" StyleClasses="OpenBoth" />
<controls:ConfirmButton Visible="False" Name="Kick" Text="{Loc 'admin-player-actions-kick'}" ConfirmationText="{Loc 'admin-player-actions-confirm'}" StyleClasses="OpenBoth" /> <controls:ConfirmButton Visible="False" Name="Kick" Text="{Loc 'admin-player-actions-kick'}" ConfirmationText="{Loc 'admin-player-actions-confirm'}" StyleClasses="OpenBoth" />
<Button Visible="False" Name="Ban" Text="{Loc 'admin-player-actions-ban'}" StyleClasses="OpenBoth" /> <Button Visible="False" Name="Ban" Text="{Loc 'admin-player-actions-ban'}" StyleClasses="OpenBoth" />
<controls:ConfirmButton Visible="False" Name="Respawn" Text="{Loc 'admin-player-actions-respawn'}" ConfirmationText="{Loc 'admin-player-actions-confirm'}" StyleClasses="OpenBoth" /> <controls:ConfirmButton Visible="False" Name="Respawn" Text="{Loc 'admin-player-actions-respawn'}" ConfirmationText="{Loc 'admin-player-actions-confirm'}" StyleClasses="OpenBoth" />

View File

@@ -5,7 +5,7 @@
<BoxContainer Orientation="Vertical" Name="Notes" Access="Public" VerticalExpand="True"/> <BoxContainer Orientation="Vertical" Name="Notes" Access="Public" VerticalExpand="True"/>
</ScrollContainer> </ScrollContainer>
<Button Name="ShowMoreButton" Text="{Loc admin-notes-show-more}" Visible="False" HorizontalAlignment="Center" /> <Button Name="ShowMoreButton" Text="{Loc admin-notes-show-more}" Visible="False" HorizontalAlignment="Center" />
<Button Name="NewNoteButton" Text="{Loc admin-notes-new-note}" Disabled="True" /> <Button Name="NewNoteButton" Access="Public" Text="{Loc admin-notes-new-note}" Disabled="True" />
</BoxContainer> </BoxContainer>
</PanelContainer> </PanelContainer>
</Control> </Control>

View File

@@ -3,7 +3,7 @@
Title="Loading..." Title="Loading..."
MinSize="400 200"> MinSize="400 200">
<BoxContainer Orientation="Vertical" Margin="4"> <BoxContainer Orientation="Vertical" Margin="4">
<TextEdit Name="NoteTextEdit" HorizontalExpand="True" VerticalExpand="True" /> <TextEdit Name="NoteTextEdit" Access="Public" HorizontalExpand="True" VerticalExpand="True" />
<BoxContainer Orientation="Horizontal" HorizontalExpand="True"> <BoxContainer Orientation="Horizontal" HorizontalExpand="True">
<Label Name="ExpiryLabel" Text="{Loc admin-note-editor-expiry-label}" Visible="False" /> <Label Name="ExpiryLabel" Text="{Loc admin-note-editor-expiry-label}" Visible="False" />
<HistoryLineEdit Name="ExpiryLineEdit" PlaceHolder="{Loc admin-note-editor-expiry-placeholder}" <HistoryLineEdit Name="ExpiryLineEdit" PlaceHolder="{Loc admin-note-editor-expiry-placeholder}"
@@ -17,7 +17,7 @@
ToolTip="{Loc admin-note-editor-secret-tooltip}" /> ToolTip="{Loc admin-note-editor-secret-tooltip}" />
<CheckBox Name="PermanentCheckBox" Pressed="True" Text="{Loc admin-note-editor-expiry-checkbox}" <CheckBox Name="PermanentCheckBox" Pressed="True" Text="{Loc admin-note-editor-expiry-checkbox}"
ToolTip="{Loc admin-note-editor-expiry-checkbox-tooltip}" /> ToolTip="{Loc admin-note-editor-expiry-checkbox-tooltip}" />
<Button Name="SubmitButton" Text="{Loc admin-note-editor-submit}" HorizontalAlignment="Right" /> <Button Name="SubmitButton" Access="Public" Text="{Loc admin-note-editor-submit}" HorizontalAlignment="Right" />
</BoxContainer> </BoxContainer>
</BoxContainer> </BoxContainer>
</controls:FancyWindow> </controls:FancyWindow>

View File

@@ -133,7 +133,7 @@ public sealed partial class NoteEdit : FancyWindow
private bool IsSecret { get; set; } private bool IsSecret { get; set; }
private NoteType NoteType { get; set; } private NoteType NoteType { get; set; }
private NoteSeverity? NoteSeverity public NoteSeverity? NoteSeverity
{ {
get => _noteSeverity; get => _noteSeverity;
set set

View File

@@ -1,3 +1,4 @@
using System.Runtime.CompilerServices; using System.Runtime.CompilerServices;
[assembly: InternalsVisibleTo("Content.Tests")] [assembly: InternalsVisibleTo("Content.Tests")]
[assembly: InternalsVisibleTo("Content.IntegrationTests")]

View File

@@ -0,0 +1,60 @@
using System.Linq;
using Content.Client.Administration.UI;
using Content.Client.Administration.UI.CustomControls;
using Content.Client.Administration.UI.Logs;
using Content.Client.UserInterface.Controls;
using Content.Client.UserInterface.Systems.MenuBar.Widgets;
using Content.IntegrationTests.Tests.Interaction;
using Content.Server.Administration.Commands;
using Content.Server.Administration.Logs;
using Content.Shared.Database;
namespace Content.IntegrationTests.Tests.Administration.Logs;
public sealed class LogWindowTest : InteractionTest
{
protected override PoolSettings Settings => new() { Connected = true, Dirty = true, AdminLogsEnabled = true, DummyTicker = false };
[Test]
public async Task TestAdminLogsWindow()
{
// First, generate a new log
var log = Server.Resolve<IAdminLogManager>();
var guid = Guid.NewGuid();
await Server.WaitPost(() => log.Add(LogType.Unknown, $"{SPlayer} test log 1: {guid}"));
// Click the admin button in the menu bar
await ClickWidgetControl<GameTopMenuBar, MenuButton>(nameof(GameTopMenuBar.AdminButton));
var adminWindow = GetWindow<AdminMenuWindow>();
// Find and click the "open logs" button.
Assert.That(TryGetControlFromChildren<CommandButton>(x => x.Command == OpenAdminLogsCommand.Cmd, adminWindow, out var btn));
await ClickControl(btn!);
var logWindow = GetWindow<AdminLogsWindow>();
// Find the log search field and refresh buttons
var search = logWindow.Logs.LogSearch;
var refresh = logWindow.Logs.RefreshButton;
var cont = logWindow.Logs.LogsContainer;
// Search for the log we added earlier.
await Client.WaitPost(() => search.Text = guid.ToString());
await ClickControl(refresh);
await RunTicks(5);
var searchResult = cont.Children.Where(x => x.Visible && x is AdminLogLabel).Cast<AdminLogLabel>().ToArray();
Assert.That(searchResult.Length, Is.EqualTo(1));
Assert.That(searchResult[0].Log.Message, Contains.Substring($" test log 1: {guid}"));
// Add a new log
guid = Guid.NewGuid();
await Server.WaitPost(() => log.Add(LogType.Unknown, $"{SPlayer} test log 2: {guid}"));
// Update the search and refresh
await Client.WaitPost(() => search.Text = guid.ToString());
await ClickControl(refresh);
await RunTicks(5);
searchResult = cont.Children.Where(x => x.Visible && x is AdminLogLabel).Cast<AdminLogLabel>().ToArray();
Assert.That(searchResult.Length, Is.EqualTo(1));
Assert.That(searchResult[0].Log.Message, Contains.Substring($" test log 2: {guid}"));
}
}

View File

@@ -0,0 +1,56 @@
using System.Linq;
using Content.Client.Administration.UI.Bwoink;
using Content.Client.Administration.UI.CustomControls;
using Content.Client.Administration.UI.Notes;
using Content.Client.UserInterface.Controls;
using Content.Client.UserInterface.Systems.MenuBar.Widgets;
using Content.IntegrationTests.Tests.Interaction;
using Content.Shared.Database;
using Robust.Shared.Utility;
namespace Content.IntegrationTests.Tests.Administration.Notes;
/// <summary>
/// Test that the admin notes UI can be used to add a new note.
/// </summary>
public sealed class NotesControlTest : InteractionTest
{
protected override PoolSettings Settings => new() {Connected = true, Dirty = true, AdminLogsEnabled = true, DummyTicker = false};
[Test]
public async Task TestNotesControl()
{
// Click the ahelp button in the menu bar
await ClickWidgetControl<GameTopMenuBar, MenuButton>(nameof(GameTopMenuBar.AHelpButton));
var bwoink = GetWindow<BwoinkWindow>();
// Damn, if only I had an excuse to use bwoink.Bwoink.BwoinkArea
var players = bwoink.Bwoink.ChannelSelector.PlayerListContainer;
// Check that the player is in the menu, and make sure it is selected
var entry = players.Data.Cast<PlayerListData>().Single(x => x.Info.SessionId == ServerSession.UserId);
await Client.WaitPost(() => players.Select(entry));
// Open their notes
await ClickControl(bwoink.Bwoink.Notes);
var noteCtrl = GetWindow<AdminNotesWindow>().Notes;
Assert.That(noteCtrl.Notes.ChildCount, Is.EqualTo(0));
// Add a new note
await ClickControl(noteCtrl.NewNoteButton);
var addNoteWindow = GetWindow<NoteEdit>();
var msg = $"note: {Guid.NewGuid()}";
await Client.WaitPost(() => addNoteWindow.NoteTextEdit.TextRope = new Rope.Leaf(msg));
addNoteWindow.NoteSeverity = NoteSeverity.None;
// Have to click submit twice for confirmation?
await ClickControl(addNoteWindow.SubmitButton);
await ClickControl(addNoteWindow.SubmitButton);
// Check that the new note exists
await RunTicks(5);
Assert.That(noteCtrl.Notes.ChildCount, Is.EqualTo(1));
var note = (AdminNotesLine)noteCtrl.Notes.Children[0];
Assert.That(note.Note.Message, Is.EqualTo(msg));
}
}

View File

@@ -156,10 +156,13 @@ public abstract partial class InteractionTest
- type: CombatMode - type: CombatMode
"; ";
protected static PoolSettings Default => new() { Connected = true, Dirty = true };
protected virtual PoolSettings Settings => Default;
[SetUp] [SetUp]
public virtual async Task Setup() public virtual async Task Setup()
{ {
Pair = await PoolManager.GetServerClient(new PoolSettings { Connected = true, Dirty = true }); Pair = await PoolManager.GetServerClient(Settings);
// server dependencies // server dependencies
SEntMan = Server.ResolveDependency<IEntityManager>(); SEntMan = Server.ResolveDependency<IEntityManager>();

View File

@@ -10,7 +10,8 @@ public sealed class OpenAdminLogsCommand : LocalizedEntityCommands
{ {
[Dependency] private readonly EuiManager _euiManager = default!; [Dependency] private readonly EuiManager _euiManager = default!;
public override string Command => "adminlogs"; public override string Command => Cmd;
public const string Cmd = "adminlogs";
public override void Execute(IConsoleShell shell, string argStr, string[] args) public override void Execute(IConsoleShell shell, string argStr, string[] args)
{ {