acdream/tests/AcDream.App.Tests/UI/Layout/OptionsPanelControllerTests.cs
Erik 9d26ecc623 feat(ui): Campaign OP slice OP3 — Options panel shell, open paths, Gameplay tab
Mounts retail's Options panel (LayoutDesc 0x2100002B resolved through host
0x2100006E slot 0x1000018D, gmPanelUI key 10) via the same catalog-import
pattern CharacterController already validates, registered through
RetailPanelUiController so it shares retail's "one active gmPanelUI child"
mutual exclusion with every other sibling panel for free. F11 and the
toolbar's options button (0x1000019B, already authoring panel id 10) both
now open it; the close button fires the same ToggleOptionsPanel action.

OptionPageModel (OptionPage/BoolOptionRow) ports retail's exact
Apply/Reset/Defaults/visibility semantics from
UIOption_Checkbox/PlayerOptionPage — LED clicks apply live immediately,
Apply commits every row unconditionally + flushes the batched blob, Reset
reverts only Changed rows, Defaults restores without committing, and
tab-switch/window-hide revert uncommitted edits. Wired for all four tabs;
this slice registers real rows on none of them (Gameplay authentically has
none — a pure button list). UiTabPanel gains an ActivePageChanged event so
the page model can hook every tab transition, including the initial
default-tab activation.

The seven Gameplay-tab buttons: Exit Game reuses the existing graceful
window-close path; Exit to Character Selection gets retail's confirmation
dialog and byte-verified mid-air refusal but still behaves as Exit Game
(AD-74 — no pre-world character-select flow exists); Configure Keyboard
and In-Game Help Files are inert this slice (AD-76 for Help — the
plugin retail depends on doesn't exist); Urgent Assistance/Report Abuse
short-circuit to their own byte-verified failure text through the
interface-text seam instead of ShellExecute against a dead URL (AD-75);
Use Mouse Turning Settings runs the pure MouseTurningSettingsMacro port,
persisting five new CameraTurningSettings preferences and sending
PlayerOption.UseMouseTurning — TS-74 records that acdream has no
persistent mouse-turning camera mode for the bit to drive yet.

Full Release suite: 12,918 passed / 4 skipped / 0 failed (baseline
12,871/4/0 — only new tests added).

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
2026-08-11 02:14:40 +02:00

269 lines
9.7 KiB
C#

using AcDream.App.UI;
using AcDream.App.UI.Layout;
using AcDream.Core.Chat;
namespace AcDream.App.Tests.UI.Layout;
/// <summary>
/// Controller-level tests for <see cref="OptionsPanelController"/> against
/// the committed <c>options_panel_2100006E_1000018D.json</c> fixture
/// (Campaign OP slice OP3) — the SAME <c>LayoutImporter.ImportInfos(dats,
/// 0x2100006Eu, 0x1000018Du)</c> catalog import
/// <see cref="RetailUiRuntime.MountOptionsPanel"/> performs against real
/// DATs. No DAT access, no live runtime — dat-free per the established
/// <c>FixtureLoader</c> pattern.
/// </summary>
public sealed class OptionsPanelControllerTests
{
private static UiButton Click(ImportedLayout layout, uint elementId)
{
var button = Assert.IsType<UiButton>(layout.FindElement(elementId));
button.OnEvent(new UiEvent(0, button, UiEventType.Click));
return button;
}
private static OptionsPanelController.Callbacks MakeCallbacks(
List<string> calls,
Action<string>? displaySystemMessage = null)
=> new(
Toggle: () => calls.Add("toggle"),
RequestExitToCharacterSelection: () => calls.Add("exit-to-char-select"),
ExitGame: () => calls.Add("exit-game"),
UseMouseTurningSettings: () => calls.Add("mouse-turning"),
DisplaySystemMessage: displaySystemMessage ?? (text => calls.Add($"message:{text}")));
// ── Mount conformance ────────────────────────────────────────────────────
[Fact]
public void Bind_RootBuildsAsUiTabPanel()
{
ImportedLayout layout = FixtureLoader.LoadOptionsPanelHost();
Assert.IsType<UiTabPanel>(layout.Root);
}
[Fact]
public void Bind_Succeeds_AndExposesFourEmptyPages()
{
ImportedLayout layout = FixtureLoader.LoadOptionsPanelHost();
var calls = new List<string>();
OptionsPanelController? controller =
OptionsPanelController.Bind(layout, MakeCallbacks(calls));
Assert.NotNull(controller);
Assert.Equal(4, controller!.Pages.Count);
Assert.Empty(controller.GameplayPage.Rows);
Assert.Empty(controller.CharacterPage.Rows);
Assert.Empty(controller.ChatPage.Rows);
Assert.Empty(controller.ConfigPage.Rows);
}
[Fact]
public void ActivateTabs_SelectsGameplayAsDefault_AndAppliesItsPage()
{
ImportedLayout layout = FixtureLoader.LoadOptionsPanelHost();
var calls = new List<string>();
int gameplayFlushCount = 0;
OptionsPanelController controller = OptionsPanelController.Bind(
layout,
MakeCallbacks(calls) with { AfterApply = () => gameplayFlushCount++ })!;
controller.ActivateTabs();
Assert.True(controller.TabPanel.BehaviorActive);
Assert.Equal(0x10000212u, controller.TabPanel.ActivePageElementId); // Gameplay slot
// OnShown() fired for the initial default tab -> Apply() -> AfterApply.
Assert.Equal(1, gameplayFlushCount);
}
[Fact]
public void TabSwitch_RevertsLeavingPage_AndAppliesEnteringPage()
{
ImportedLayout layout = FixtureLoader.LoadOptionsPanelHost();
var calls = new List<string>();
var flushes = new List<string>();
OptionsPanelController controller = OptionsPanelController.Bind(
layout, MakeCallbacks(calls) with { AfterApply = () => flushes.Add("flush") })!;
controller.ActivateTabs();
flushes.Clear(); // drop the initial-activation flush
controller.TabPanel.SwitchTo(0x10000211u); // Character page slot
Assert.Equal(0x10000211u, controller.TabPanel.ActivePageElementId);
// Both OnHidden (Gameplay, Reset — no flush) and OnShown (Character, Apply — flush).
Assert.Equal(["flush"], flushes);
}
[Fact]
public void WholeWindowHide_RevertsCurrentlyActivePage()
{
ImportedLayout layout = FixtureLoader.LoadOptionsPanelHost();
var calls = new List<string>();
OptionsPanelController controller =
OptionsPanelController.Bind(layout, MakeCallbacks(calls))!;
controller.ActivateTabs();
var row = new BoolOptionRow(initial: false, defaultValue: false);
controller.GameplayPage.Register(row);
row.SetCurrentValue(true);
Assert.True(controller.GameplayPage.Changed);
controller.OnHidden(); // IRetainedPanelController hook — whole window closing
Assert.False(controller.GameplayPage.Changed);
}
[Fact]
public void WholeWindowShow_AppliesCurrentlyActivePage()
{
ImportedLayout layout = FixtureLoader.LoadOptionsPanelHost();
var calls = new List<string>();
int flushCount = 0;
OptionsPanelController controller = OptionsPanelController.Bind(
layout, MakeCallbacks(calls) with { AfterApply = () => flushCount++ })!;
controller.ActivateTabs();
flushCount = 0;
controller.OnShown();
Assert.Equal(1, flushCount);
}
// ── Close button ─────────────────────────────────────────────────────────
[Fact]
public void CloseButton_FiresToggleCallback()
{
ImportedLayout layout = FixtureLoader.LoadOptionsPanelHost();
var calls = new List<string>();
OptionsPanelController.Bind(layout, MakeCallbacks(calls));
Click(layout, 0x10000210u);
Assert.Equal(["toggle"], calls);
}
// ── The seven Gameplay-tab buttons ───────────────────────────────────────
[Fact]
public void ExitToCharacterSelectionButton_FiresRequestCallback()
{
ImportedLayout layout = FixtureLoader.LoadOptionsPanelHost();
var calls = new List<string>();
OptionsPanelController.Bind(layout, MakeCallbacks(calls));
Click(layout, 0x10000203u);
Assert.Equal(["exit-to-char-select"], calls);
}
[Fact]
public void ExitGameButton_FiresExitGameCallback()
{
ImportedLayout layout = FixtureLoader.LoadOptionsPanelHost();
var calls = new List<string>();
OptionsPanelController.Bind(layout, MakeCallbacks(calls));
Click(layout, 0x10000617u);
Assert.Equal(["exit-game"], calls);
}
[Fact]
public void UseMouseTurningSettingsButton_FiresMacroCallback()
{
ImportedLayout layout = FixtureLoader.LoadOptionsPanelHost();
var calls = new List<string>();
OptionsPanelController.Bind(layout, MakeCallbacks(calls));
Click(layout, 0x100005CCu);
Assert.Equal(["mouse-turning"], calls);
}
[Fact]
public void UrgentAssistanceButton_DisplaysItsOwnByteVerifiedFailureText()
{
ImportedLayout layout = FixtureLoader.LoadOptionsPanelHost();
var calls = new List<string>();
OptionsPanelController.Bind(layout, MakeCallbacks(calls));
Click(layout, 0x10000206u);
Assert.Equal([$"message:{OptionsPanelText.UrgentAssistanceUnavailable}"], calls);
}
[Fact]
public void ReportAbuseButton_DisplaysItsOwnByteVerifiedFailureText()
{
ImportedLayout layout = FixtureLoader.LoadOptionsPanelHost();
var calls = new List<string>();
OptionsPanelController.Bind(layout, MakeCallbacks(calls));
Click(layout, 0x10000207u);
Assert.Equal([$"message:{OptionsPanelText.ReportAbuseUnavailable}"], calls);
}
[Fact]
public void UrgentAssistanceAndReportAbuse_UseDifferentText()
{
// The two buttons share retail's identical body template but differ
// in ONE clause ("urgent assistance request" vs "abuse report").
Assert.NotEqual(
OptionsPanelText.UrgentAssistanceUnavailable,
OptionsPanelText.ReportAbuseUnavailable);
Assert.Contains(OptionsPanelText.SupportUrl, OptionsPanelText.UrgentAssistanceUnavailable);
Assert.Contains(OptionsPanelText.SupportUrl, OptionsPanelText.ReportAbuseUnavailable);
}
[Fact]
public void ConfigureKeyboardButton_IsInert_ClickDoesNothing()
{
// D4/OP8: authored, clickable, no handler this slice.
ImportedLayout layout = FixtureLoader.LoadOptionsPanelHost();
var calls = new List<string>();
OptionsPanelController.Bind(layout, MakeCallbacks(calls));
Click(layout, 0x10000204u);
Assert.Empty(calls);
}
[Fact]
public void InGameHelpFilesButton_IsInert_ClickDoesNothing()
{
// D5: retail's own KeyStone::OpenHelp fails silently without the
// missing ACHelpPlugin.dll — mirrored as an inert button.
ImportedLayout layout = FixtureLoader.LoadOptionsPanelHost();
var calls = new List<string>();
OptionsPanelController.Bind(layout, MakeCallbacks(calls));
Click(layout, 0x10000205u);
Assert.Empty(calls);
}
[Fact]
public void AllSevenGameplayButtons_ResolveInTheBuiltLayout()
{
// Guards against a future fixture regeneration silently dropping an
// id (a missing button degrades to a logged no-op, not a test
// failure, unless asserted here).
ImportedLayout layout = FixtureLoader.LoadOptionsPanelHost();
uint[] buttonIds =
{
0x10000203u, // Exit to Character Selection
0x10000204u, // Configure Keyboard
0x10000205u, // In-Game Help Files
0x10000206u, // Urgent Assistance
0x10000207u, // Report Abuse
0x100005CCu, // Use Mouse Turning Settings
0x10000617u, // Exit Game
};
foreach (uint id in buttonIds)
Assert.IsType<UiButton>(layout.FindElement(id));
}
}