]> git.smokeofanarchy.ru Git - space-station-14.git/commitdiff
Add admin ui tests (#40914)
authorLeon Friedrich <60421075+ElectroJr@users.noreply.github.com>
Wed, 15 Oct 2025 12:14:48 +0000 (01:14 +1300)
committerGitHub <noreply@github.com>
Wed, 15 Oct 2025 12:14:48 +0000 (12:14 +0000)
* Add admin ui tests

* fix notes test

* Apply suggestions from code review

---------

Co-authored-by: slarticodefast <161409025+slarticodefast@users.noreply.github.com>
Content.Client/Administration/UI/Bwoink/BwoinkControl.xaml
Content.Client/Administration/UI/Notes/AdminNotesControl.xaml
Content.Client/Administration/UI/Notes/NoteEdit.xaml
Content.Client/Administration/UI/Notes/NoteEdit.xaml.cs
Content.Client/AssemblyInfo.cs
Content.IntegrationTests/Tests/Administration/Logs/LogWindowTest.cs [new file with mode: 0644]
Content.IntegrationTests/Tests/Administration/Notes/NotesControlTest.cs [new file with mode: 0644]
Content.IntegrationTests/Tests/Interaction/InteractionTest.cs
Content.Server/Administration/Commands/OpenAdminLogsCommand.cs

index 2c27fdd2ce3a67075e0a93af0ddeba71fa81ecf5..fdaa838201e1267b97f352b529986452571092a9 100644 (file)
@@ -18,7 +18,7 @@
                 <Button Visible="True" Name="PopOut" Access="Public" Text="{Loc 'admin-logs-pop-out'}" StyleClasses="OpenBoth" HorizontalAlignment="Left" />
                 <Control HorizontalExpand="True" />
                 <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" />
                 <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" />
index 326e4bf3a31b0ffc429a5b5e3aaac46eddc605a8..09d36af1b0cc7b2337e5aee534fd0ef602cf441a 100644 (file)
@@ -5,7 +5,7 @@
                 <BoxContainer Orientation="Vertical" Name="Notes" Access="Public" VerticalExpand="True"/>
             </ScrollContainer>
             <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>
     </PanelContainer>
 </Control>
index 72b2c55ce8da7bfcc1b48b2c2c5a8c9a241c62ad..793d84113d163e81bb9908b7c15fb6cba7ce0e23 100644 (file)
@@ -3,7 +3,7 @@
                       Title="Loading..."
                       MinSize="400 200">
     <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">
             <Label Name="ExpiryLabel" Text="{Loc admin-note-editor-expiry-label}" Visible="False" />
             <HistoryLineEdit Name="ExpiryLineEdit" PlaceHolder="{Loc admin-note-editor-expiry-placeholder}"
@@ -17,7 +17,7 @@
                       ToolTip="{Loc admin-note-editor-secret-tooltip}" />
             <CheckBox Name="PermanentCheckBox" Pressed="True" Text="{Loc admin-note-editor-expiry-checkbox}"
                       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>
 </controls:FancyWindow>
index c8e3afeb22c03228577b9a8e26f41d41d4c98d95..0c27d9d646aa06ca14d261af4f6cd8d8675d02d1 100644 (file)
@@ -133,7 +133,7 @@ public sealed partial class NoteEdit : FancyWindow
     private bool IsSecret { get; set; }
     private NoteType NoteType { get; set; }
 
-    private NoteSeverity? NoteSeverity
+    public NoteSeverity? NoteSeverity
     {
         get => _noteSeverity;
         set
index 54b2cd50ace24a556285a484a5d9ee9dcf98f605..513ab37ab23640399fe1d8cae3a04e979d8e3f08 100644 (file)
@@ -1,3 +1,4 @@
 using System.Runtime.CompilerServices;
 
 [assembly: InternalsVisibleTo("Content.Tests")]
+[assembly: InternalsVisibleTo("Content.IntegrationTests")]
diff --git a/Content.IntegrationTests/Tests/Administration/Logs/LogWindowTest.cs b/Content.IntegrationTests/Tests/Administration/Logs/LogWindowTest.cs
new file mode 100644 (file)
index 0000000..80236c7
--- /dev/null
@@ -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}"));
+    }
+}
diff --git a/Content.IntegrationTests/Tests/Administration/Notes/NotesControlTest.cs b/Content.IntegrationTests/Tests/Administration/Notes/NotesControlTest.cs
new file mode 100644 (file)
index 0000000..c8dd637
--- /dev/null
@@ -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));
+    }
+}
index eff0ed3a0c2e367ae0174ea423ec1d81f94b454c..4a33fdc03b66b10a011d4008d60c52936827a8d4 100644 (file)
@@ -156,10 +156,13 @@ public abstract partial class InteractionTest
   - type: CombatMode
 ";
 
+    protected static PoolSettings Default => new() { Connected = true, Dirty = true };
+    protected virtual PoolSettings Settings => Default;
+
     [SetUp]
     public virtual async Task Setup()
     {
-        Pair = await PoolManager.GetServerClient(new PoolSettings { Connected = true, Dirty = true });
+        Pair = await PoolManager.GetServerClient(Settings);
 
         // server dependencies
         SEntMan = Server.ResolveDependency<IEntityManager>();
index 1beaaa928e35f18848b37d534aad39bd8ff40ad7..df437fcc2d44dc50b7623e6c69a965304c0b78b8 100644 (file)
@@ -10,7 +10,8 @@ public sealed class OpenAdminLogsCommand : LocalizedEntityCommands
 {
     [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)
     {