acdream/tests/AcDream.App.Tests/UI/Layout/OptionsPanelControllerTests.cs
Erik bc43fb1d1d fix(ui,runtime): OP4 review fixes — live re-seed, enable-gating, Combat panel re-point, universal timestamps
Both OP4 reviews converged on one headline bug (Character-tab rows never
re-read live server truth after their pre-login constructor-word seed) plus
overlapping MUST-FIXes. All ten converged/consolidated findings land here:

MUST-FIX:
- BoolOptionRow.SaveCurrentValue now re-reads its live binding (retail's
  GetValue()-into-SaveCurrentValue) on every OnShown — panel open, tab
  switch in, initial activation — instead of trusting the pre-login
  constructor word it was built with. Reset/tab-switch can now only
  restore values that were actually live at the last show. LockUI's
  host.Root.UiLocked one-shot mount seed now also converges on every
  PlayerDescription via the existing OnCharacterOptionsChanged hook.
- Apply/Reset are wired to OptionPage.OnOptionChanged in production
  (Ghosted when nothing changed, Normal when dirty, run once at bind so
  both start disabled per retail's PostInit); Defaults stays ungated.
- The Combat panel's three LEDs (Repeat Attacks/Auto Target/Keep in View)
  now read/write the same RuntimeCharacterOptionsState seam the Character
  tab uses instead of a disconnected client-local GameplaySettings copy —
  closes the "two writable copies" divergence. The three now-orphaned
  GameplaySettings fields and RuntimeSettingsController's mirror
  properties/SetCombatGameplay are deleted outright; the headless host's
  hardcoded AutoRepeatAttack/AutoTarget now read the live option bit.
- RuntimeSettingsController.SetUiLocked's convergence guard now compares
  against the last value actually applied to the runtime target instead
  of the persisted GameplaySettings.LockUI snapshot, which could already
  match a server-derived request without ever having been pushed.

SHOULD-FIX:
- DisplayTimeStamps now prefixes every chat producer (ChatLog.Append is
  the one seam all of them funnel through), not just AddText's own
  callers — heard speech, emotes, Turbine channels, and combat text were
  previously missed. The prefix format escapes its colons and forces
  InvariantCulture instead of the culture-dependent TimeSeparator
  placeholder.
- sky.frag now honors uFogParams.w (fog mode) like the mesh/terrain
  shaders, so Disable Distance Fog stops the sky dome's horizon band from
  blending toward fog color too.
- Corrected the "byte-verified" overclaim on the timestamp format string
  doc comment (BN-sourced, wire doc U6) and the AP-194 anchor-column
  class-name typo; the RunAsDefaultMovement doc comments now cite retail's
  actual acclient.h enumerator name.
- Added: DispatcherMovementInputSource's option x modifier truth table
  (incl. || AutoRunActive with the option off), the per-page Apply/Reset
  enable-gate tests, a real checkbox.OnClick/ToggleBehavior-driven click
  test, and hash-pins for the six header string keys.
- Gate script step 8 corrected for the logout-flush false-failure
  (closing the panel before relogging is load-bearing); a new step
  documents the enable-gate sequence and the Combat-panel/Character-tab
  cross-check.

Register: AP-196 (the Group-C default-source change + GameplaySettings
retirement) and AP-197 (the ignored per-character timestamp format
override) filed in this commit.

Full Release suite: 13,044 passed / 4 skipped / 0 failed (was 13,008/4/0;
net +36 tests from new coverage and legitimate assertion updates from the
GameplaySettings retirement).

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

405 lines
16 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_ButNeverFlushesIt()
{
// Mechanism review S1 (2026-08-11 fix round): gmGameplayOptionsUI is
// NOT an OptionPage in retail (acclient.h:55857) — its own OptionPage
// instance is constructed with AfterApply deliberately left null
// (OptionsPanelController's constructor), regardless of what the
// controller's OWN AfterApply callback is, so the initial default-
// tab activation (OnShown -> Apply) never publishes a flush.
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
Assert.Equal(0, gameplayFlushCount);
}
[Fact]
public void TabSwitch_RevertsLeavingGameplayPage_AndAppliesEnteringCharacterPage()
{
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 (Gameplay never flushes anyway)
controller.TabPanel.SwitchTo(0x10000211u); // Character page slot
Assert.Equal(0x10000211u, controller.TabPanel.ActivePageElementId);
// OnHidden (Gameplay, Reset — no flush regardless) and OnShown
// (Character, a REAL AfterApply-wired page — Apply flushes).
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()
{
// Switches off the Gameplay default onto Character FIRST — Gameplay
// never flushes (S1), so testing "OnShown applies the currently
// active page" needs a REAL AfterApply-wired page active, exactly
// like a returning user re-opening the window on a non-default tab.
ImportedLayout layout = FixtureLoader.LoadOptionsPanelHost();
var calls = new List<string>();
int flushCount = 0;
OptionsPanelController controller = OptionsPanelController.Bind(
layout, MakeCallbacks(calls) with { AfterApply = () => flushCount++ })!;
controller.ActivateTabs();
controller.TabPanel.SwitchTo(0x10000211u); // Character page slot
flushCount = 0;
controller.OnShown();
Assert.Equal(1, flushCount);
}
[Fact]
public void GameplayPage_OnShownAndOnHidden_NeverFlush_EvenWhenControllerAfterApplyIsWired()
{
// Direct pin of S1's fix: cycling Gameplay's own OnShown/OnHidden
// (the page-model hooks OnActivePageChanged drives) never publishes
// a flush, independent of TabSwitch/ActivateTabs framing.
ImportedLayout layout = FixtureLoader.LoadOptionsPanelHost();
var calls = new List<string>();
int flushCount = 0;
OptionsPanelController controller = OptionsPanelController.Bind(
layout, MakeCallbacks(calls) with { AfterApply = () => flushCount++ })!;
controller.GameplayPage.OnShown();
controller.GameplayPage.OnHidden();
Assert.Equal(0, flushCount);
}
// ── MUST-FIX 2 (OP4 review-fix round, 2026-08-11): Apply/Reset gating ──────
private static (UiButton Apply, UiButton Reset, UiButton Defaults) GetCharacterPageButtons(
OptionsPanelController controller)
{
UiElement pageRoot = UiElement.FindDescendant(controller.Root, 0x10000211u)!; // Character page slot
var apply = Assert.IsType<UiButton>(UiElement.FindDescendant(pageRoot, 0x100001FCu));
var reset = Assert.IsType<UiButton>(UiElement.FindDescendant(pageRoot, 0x100001FDu));
var defaults = Assert.IsType<UiButton>(UiElement.FindDescendant(pageRoot, 0x100001FEu));
return (apply, reset, defaults);
}
[Fact]
public void CharacterPage_ApplyAndReset_StartDisabled_OnFreshBind()
{
// Retail's PostInit calls InitOptions() then OnOptionChanged(0), so
// the pair starts Ghosted before any row has ever been touched.
ImportedLayout layout = FixtureLoader.LoadOptionsPanelHost();
var calls = new List<string>();
OptionsPanelController controller =
OptionsPanelController.Bind(layout, MakeCallbacks(calls))!;
(UiButton apply, UiButton reset, _) = GetCharacterPageButtons(controller);
Assert.False(apply.Enabled);
Assert.False(reset.Enabled);
}
[Fact]
public void CharacterPage_OneLedClick_EnablesApplyAndReset()
{
ImportedLayout layout = FixtureLoader.LoadOptionsPanelHost();
var calls = new List<string>();
OptionsPanelController controller =
OptionsPanelController.Bind(layout, MakeCallbacks(calls))!;
var row = new BoolOptionRow(initial: false, defaultValue: false);
controller.CharacterPage.Register(row);
(UiButton apply, UiButton reset, _) = GetCharacterPageButtons(controller);
row.SetCurrentValue(true);
Assert.True(apply.Enabled);
Assert.True(reset.Enabled);
}
[Fact]
public void CharacterPage_Apply_DisablesApplyAndResetAgain()
{
ImportedLayout layout = FixtureLoader.LoadOptionsPanelHost();
var calls = new List<string>();
OptionsPanelController controller =
OptionsPanelController.Bind(layout, MakeCallbacks(calls))!;
var row = new BoolOptionRow(initial: false, defaultValue: false);
controller.CharacterPage.Register(row);
(UiButton apply, UiButton reset, _) = GetCharacterPageButtons(controller);
row.SetCurrentValue(true);
controller.CharacterPage.Apply();
Assert.False(apply.Enabled);
Assert.False(reset.Enabled);
}
[Fact]
public void CharacterPage_Defaults_LeavesApplyAndResetEnabled_WhenSomethingActuallyChanged()
{
ImportedLayout layout = FixtureLoader.LoadOptionsPanelHost();
var calls = new List<string>();
OptionsPanelController controller =
OptionsPanelController.Bind(layout, MakeCallbacks(calls))!;
var row = new BoolOptionRow(initial: false, defaultValue: true);
controller.CharacterPage.Register(row);
(UiButton apply, UiButton reset, _) = GetCharacterPageButtons(controller);
controller.CharacterPage.Defaults();
Assert.True(row.Current);
Assert.True(controller.CharacterPage.Changed);
Assert.True(apply.Enabled);
Assert.True(reset.Enabled);
}
[Fact]
public void CharacterPage_Defaults_IsNeverGated()
{
// Retail's Defaults override never fetches its own child id at all
// — it must never grey itself out, before OR after a real change.
ImportedLayout layout = FixtureLoader.LoadOptionsPanelHost();
var calls = new List<string>();
OptionsPanelController controller =
OptionsPanelController.Bind(layout, MakeCallbacks(calls))!;
var row = new BoolOptionRow(initial: false, defaultValue: false);
controller.CharacterPage.Register(row);
(_, _, UiButton defaults) = GetCharacterPageButtons(controller);
Assert.True(defaults.Enabled);
row.SetCurrentValue(true);
Assert.True(defaults.Enabled);
controller.CharacterPage.Apply();
Assert.True(defaults.Enabled);
controller.CharacterPage.Defaults();
Assert.True(defaults.Enabled);
}
// ── 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));
}
}