Make some overall changes to utilities

This commit is contained in:
2026-10-26 22:09:36 +01:00
parent a4109f5be0
commit 881b61a66d
22 changed files with 376 additions and 790 deletions
@@ -173,6 +173,52 @@ public class CombatLayoutTests
}
}
[UnityTest]
public IEnumerator HandFocusRevealsNameAndCostAndStillAllowsRulesScrolling()
{
bool testedOversizedCard = false;
foreach (var size in Viewports)
foreach (var textSize in new[] { UITextSize.Standard, UITextSize.Large })
{
UIPreferences.TextSize = textSize;
Resize(size);
Call(_view, "RefreshHand");
for (int frame = 0; frame < 5; frame++) yield return null;
var scroll = _root.Q<ScrollView>(className: "hand-scroll");
var faces = scroll.Query<Button>(className: "hand-card").ToList();
string context = $"{size}, {textSize}";
testedOversizedCard |= faces.Any(face => face.worldBound.height > scroll.contentViewport.worldBound.height);
scroll.scrollOffset = new Vector2(scroll.horizontalScroller.highValue, scroll.verticalScroller.highValue);
// Moving focus twice before layout must not restore a stale card's position.
faces[0].Focus();
faces[faces.Count - 1].Focus();
for (int frame = 0; frame < 3; frame++) yield return null;
foreach (var face in new[] { faces[faces.Count - 1], faces[0] })
{
face.Focus();
for (int frame = 0; frame < 3; frame++) yield return null;
foreach (string className in new[] { "software-name", "software-cost" })
{
var label = face.Q<Label>(className: className);
AssertContainedHorizontally(label, scroll.contentViewport, context);
Assert.That(label.worldBound.yMin, Is.GreaterThanOrEqualTo(scroll.contentViewport.worldBound.yMin - 1),
$"{context}; {className}; face={face.worldBound}; viewport={scroll.contentViewport.worldBound}; content={scroll.contentContainer.worldBound}; offset={scroll.scrollOffset}; focus={_root.focusController.focusedElement == face}");
Assert.That(label.worldBound.yMax, Is.LessThanOrEqualTo(scroll.contentViewport.worldBound.yMax + 1), context);
}
}
Call(_view, "RefreshHand");
for (int frame = 0; frame < 3; frame++) yield return null;
Assert.That(_root.focusController.focusedElement, Is.SameAs(faces[0]), context);
scroll.scrollOffset = new Vector2(scroll.scrollOffset.x, scroll.verticalScroller.highValue);
float rulesOffset = scroll.scrollOffset.y;
for (int frame = 0; frame < 3; frame++) yield return null;
Assert.That(rulesOffset, Is.EqualTo(scroll.verticalScroller.highValue).Within(1), context);
Assert.That(scroll.scrollOffset.y, Is.EqualTo(rulesOffset).Within(1), context + ": focus must not pin scrolling");
faces[0].Blur();
}
Assert.That(testedOversizedCard, Is.True, "Exercise at least one card taller than the hand viewport.");
}
[UnityTest]
public IEnumerator FirstBattleGuideAndReplayControlFitAcrossViewports()
{
@@ -315,6 +361,8 @@ public class CombatLayoutTests
for (int i = 0; i < 8; i++) yield return null;
var scroll = _root.Q<ScrollView>("RouteMapScroll");
var canvas = _root.Q("RouteCanvas");
Assert.That(_root.Q("RunMap").Query<Label>().ToList().Any(l => l.text.Contains("/")), Is.False,
"Route labels should not use decorative slash separators.");
Assert.That(scroll.worldBound.width, Is.GreaterThan(size.x * .55f));
Assert.That(scroll.worldBound.height, Is.GreaterThan(size.y * .5f));
Assert.That(canvas.Query(className: "route-map-wave").ToList().Count, Is.EqualTo(9));