acdream/tests/AcDream.App.Tests/UI/Layout/MapHousePanelControllerTests.cs
Erik e5629d713d fix(ui): Map/House panel — marker tooltips use the wrong property
Live verification (slice 5) found town-marker tooltips never appeared:
RetailTooltipPresenter.OnTooltipShow gates unconditionally on
AuthoredTooltipRootElementId == 0 -> return, with no fallback, but the
markers only set AuthoredTooltipText/Enabled (the DAT-authored P0x49
path). gmMapUI::AddMapNote's UIElement::SetTooltip call is retail's
RUNTIME m_TTText/SetTooltip mechanism, not the authored path — the
correct seam is UiButton.TooltipText (backing GetTooltipText()'s
override), which ResolveTooltipText consults before authored text.

The popup-skin locator (AuthoredTooltipRootElementId/LayoutDid) is
still required even on the runtime-text path with no built-in
fallback, so markers now hardcode the same shared popup skin
UiItemSlot already uses (0x10000395/0x21000041) — matching that
established precedent exactly.

Verified live: hovering a town marker (Aerlinthe Island) now renders
its tooltip correctly. 21/21 Map/House controller tests still pass.

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

189 lines
8.2 KiB
C#

using System.Linq;
using AcDream.App.UI;
using AcDream.App.UI.Layout;
using AcDream.Core.Net.Messages;
using AcDream.Core.World;
namespace AcDream.App.Tests.UI.Layout;
/// <summary>
/// Controller-level tests for <see cref="MapHousePanelController"/> against
/// the committed <c>map_house_2100006E_1000018C.json</c> fixture (Batch C,
/// overnight hover/UI round) — the SAME <c>LayoutImporter.ImportInfos(dats,
/// 0x2100006Eu, 0x1000018Cu)</c> catalog import
/// <see cref="RetailUiRuntime.MountMapHousePanel"/> performs against real
/// DATs. No DAT access, no live runtime — dat-free per the established
/// <see cref="FixtureLoader"/> pattern.
/// </summary>
public sealed class MapHousePanelControllerTests
{
/// <summary>Serves BOTH the town-hotspot template (any (layoutId,
/// elementId) pair not the player/house icon ids) and the two icons
/// <see cref="MapPageController.Bind"/> re-resolves standalone
/// (<c>m_pMap</c>'s own button-swallowed children). Returns a
/// <see cref="UiButton"/> — matching the live template's own authored
/// Type 1 (<c>MapHousePanelSlotProbeTests</c>: "hotspot template
/// type=1") — so <see cref="MapPageController.BuildTownMarkers"/>'s
/// <c>marker is UiButton</c> tooltip-text branch is actually exercised
/// by these tests. A real <see cref="RowTemplateResolver"/> would set
/// <c>DatElementId</c> the same way <see cref="LayoutImporter.Build"/>
/// does, so tests that need to find these icons back by id after the
/// fact need it too.</summary>
private static UiElement? FakeHotspotTemplate(uint layoutId, uint elementId)
=> new UiButton(new ElementInfo(), static _ => (0u, 0, 0))
{
Width = 10f,
Height = 10f,
DatElementId = elementId,
};
private static MapHousePanelController.Callbacks MakeCallbacks(
List<string>? calls = null,
Func<DerethDateTime.Calendar>? currentCalendar = null,
Func<uint>? playerCellId = null,
Func<CreateObject.ServerPosition?>? housePosition = null,
Func<IReadOnlyList<string>>? houseLines = null)
{
calls ??= new List<string>();
return new MapHousePanelController.Callbacks(
Toggle: () => calls.Add("toggle"),
Map: new MapPageController.Bindings(
CurrentCalendar: currentCalendar ?? (static () => default),
PlayerCellId: playerCellId ?? (static () => 0u),
HousePosition: housePosition ?? (static () => null),
TemplateResolver: FakeHotspotTemplate),
House: new HousePageController.Bindings(
Lines: houseLines ?? (static () => Array.Empty<string>()),
OnShown: () => calls.Add("house-shown")));
}
[Fact]
public void Bind_RootBuildsAsUiTabPanel()
{
ElementInfo rootInfo = FixtureLoader.LoadMapHouseHostInfos();
ImportedLayout layout = FixtureLoader.LoadMapHouseHost();
MapHousePanelController? controller =
MapHousePanelController.Bind(rootInfo, layout, MakeCallbacks());
Assert.NotNull(controller);
Assert.IsType<UiTabPanel>(controller!.Root);
}
/// <summary>Pins the authored tab table exactly as read from the live
/// DATs (<c>MapHousePanelSlotProbeTests</c>): two entries, Map is the
/// sole default.</summary>
[Fact]
public void TabTable_MatchesLiveDatPairing_MapIsDefault()
{
ImportedLayout layout = FixtureLoader.LoadMapHouseHost();
var tabs = Assert.IsType<UiTabPanel>(layout.Root);
Assert.Equal(2, tabs.Tabs.Count);
Assert.Contains(tabs.Tabs, e =>
e.ButtonElementId == 0x100001F3u && e.PageElementId == 0x100001F6u && e.IsDefault);
Assert.Contains(tabs.Tabs, e =>
e.ButtonElementId == 0x100001F4u && e.PageElementId == 0x100001F7u && !e.IsDefault);
Assert.Single(tabs.Tabs, e => e.IsDefault);
}
[Fact]
public void Bind_Succeeds_AndActivateTabs_SelectsMapByDefault()
{
ElementInfo rootInfo = FixtureLoader.LoadMapHouseHostInfos();
ImportedLayout layout = FixtureLoader.LoadMapHouseHost();
MapHousePanelController? controller =
MapHousePanelController.Bind(rootInfo, layout, MakeCallbacks());
Assert.NotNull(controller);
controller!.ActivateTabs();
Assert.Empty(controller.TabPanel.UnresolvedEntries);
Assert.False(controller.IsShowingHouse);
}
[Fact]
public void SwitchToHouse_FiresOnShown_OnlyWhenPanelIsVisible()
{
ElementInfo rootInfo = FixtureLoader.LoadMapHouseHostInfos();
ImportedLayout layout = FixtureLoader.LoadMapHouseHost();
var calls = new List<string>();
MapHousePanelController? controller =
MapHousePanelController.Bind(rootInfo, layout, MakeCallbacks(calls));
Assert.NotNull(controller);
controller!.ActivateTabs();
// Not visible yet: switching tabs must not fire OnShown.
controller.TabPanel.SwitchTo(0x100001F7u);
Assert.DoesNotContain("house-shown", calls);
controller.OnShown();
Assert.Contains("house-shown", calls);
}
[Fact]
public void CloseButton_InvokesToggle()
{
ElementInfo rootInfo = FixtureLoader.LoadMapHouseHostInfos();
ImportedLayout layout = FixtureLoader.LoadMapHouseHost();
var calls = new List<string>();
MapHousePanelController? controller =
MapHousePanelController.Bind(rootInfo, layout, MakeCallbacks(calls));
Assert.NotNull(controller);
UiElement? close = layout.FindElement(0x100001F5u);
Assert.IsType<UiButton>(close);
((UiButton)close!).OnClick?.Invoke();
Assert.Contains("toggle", calls);
}
[Fact]
public void Bind_BuildsAll53TownHotspots_UnderTheMapWidget()
{
ElementInfo rootInfo = FixtureLoader.LoadMapHouseHostInfos();
ImportedLayout layout = FixtureLoader.LoadMapHouseHost();
MapHousePanelController? controller =
MapHousePanelController.Bind(rootInfo, layout, MakeCallbacks());
Assert.NotNull(controller);
UiElement? map = UiElement.FindDescendant(controller!.Root, MapPageController.MapWidgetId);
Assert.NotNull(map);
// m_pMap's own children are the player/house icons (re-resolved
// standalone — see MapPageController.Bind's doc on why m_pMap being
// a Button swallows its authored nested children) PLUS the 53 town
// hotspots.
var townMarkers = map!.Children
.Where(c => c.DatElementId != MapPageController.PlayerIconId
&& c.DatElementId != MapPageController.HouseIconId)
.ToList();
Assert.Equal(55, map.Children.Count);
Assert.Equal(53, townMarkers.Count);
Assert.All(townMarkers, c => Assert.Contains(
MapLocations.All, loc => loc.Width == c.Width && loc.Height == c.Height));
// Runtime tooltip text (UiButton.TooltipText, backing
// GetTooltipText()) — the retail SetTooltip/m_TTText mechanism, NOT
// the DAT-authored AuthoredTooltipText path. The popup-skin locator
// is unconditionally required even on the runtime-text path (see
// MapPageController.MarkerTooltipRootElementId's doc).
Assert.All(townMarkers, c => Assert.NotEqual(0u, c.AuthoredTooltipRootElementId));
Assert.All(townMarkers, c => Assert.NotEqual(0u, c.AuthoredTooltipLayoutDid));
Assert.All(townMarkers, c => Assert.IsType<UiButton>(c));
Assert.All(townMarkers, c => Assert.False(string.IsNullOrEmpty(((UiButton)c).TooltipText)));
Assert.Contains(townMarkers, c => ((UiButton)c).TooltipText == "Holtburg");
}
[Fact]
public void Bind_HouseListBoxStartsEmpty_MatchingRetailPostInit()
{
ElementInfo rootInfo = FixtureLoader.LoadMapHouseHostInfos();
ImportedLayout layout = FixtureLoader.LoadMapHouseHost();
MapHousePanelController? controller =
MapHousePanelController.Bind(rootInfo, layout, MakeCallbacks());
Assert.NotNull(controller);
UiElement? box = UiElement.FindDescendant(controller!.Root, HousePageController.TextBoxId);
var listBox = Assert.IsType<UiTemplateListBox>(box);
Assert.Equal(0, listBox.ContentHeight);
}
}