Skip to content

A Civilization-style strategy game about governing Israel from 15 May 1948. Real ministers, real map, every fact sourced. Unity + deterministic C# sim.

UI: a GDD turn played with the keyboard alone, focus order of the card and End Turn pinned (refs #41) (#1330)

Beri6a7ae8f08cf7
diff --git a/changelog.d/ui-a11y-keyboard-turn-41.md b/changelog.d/ui-a11y-keyboard-turn-41.md
new file mode 100644
index 000000000..9abe3da21
--- /dev/null
+++ b/changelog.d/ui-a11y-keyboard-turn-41.md
@@ -0,0 +1,3 @@
+- Accessibility: a whole GDD turn plays from the keyboard (refs #41). Enter on a city panel button (Train, Assign,
+ Build) keeps the focus on it instead of dropping it, and Tab onto a Cabinet list's scroll bar no longer raises an
+ error. EditMode tests pin the focus order of the event card and End Turn, and play the turn with keys only.
diff --git a/docs/accessibility-audit-2026-10-14.md b/docs/accessibility-audit-2026-10-14.md
index a9740fb5a..2c4ca7b88 100644
--- a/docs/accessibility-audit-2026-10-14.md
+++ b/docs/accessibility-audit-2026-10-14.md
@@ -345,6 +345,44 @@ Escape closes the open screen; on the open card it is Hide; on the start screen
screen is set in a Hebrew face at 15:1; bars and seat colours meet 3:1 (`PromoScreensTests.BarsAndPartyColoursMeetThreeToOne`).
- Every change in the top bar carries its sign in the text, not only its colour.
+## The keyboard-only turn, 22 October 2026
+
+The done-when's turn, played again on main `5d5bee4d` after B1a (#890), B1b (#1134) and the city panel (#381, #1122,
+#1124): unit orders are left out until #754 closes (owner, 22 October 2026).
+
+- **How tested:** `KeyboardTurnTests` (EditMode) on Map.unity at 1280x720, a new GDD game with no start screen. Keys are
+ sent as the UI Toolkit events the Input System's UI provider makes of them (Tab and Shift+Tab: `NavigationMoveEvent`;
+ Enter: `KeyDownEvent` then `NavigationSubmitEvent`; Escape: `NavigationCancelEvent`), as `MapFocusTests` does. No
+ pointer event is sent after the game starts.
+- **The turn:** Tab once from the card to its first option, Enter (focus to End Turn). Tab to Budget, Enter, about 16 Tabs
+ to the screen's first control (the screens come after the HUD in the order), Tab to a line's +, Enter (focus stays,
+ H2), Tab to Submit, Enter. Tab to Cabinet, Enter, Tab to a minister's seat, Enter, Tab once to the first candidate,
+ Enter. Escape (focus to the Cabinet button, M1). Tab to the map stop, pan to Tel Aviv, Enter (the city panel shows),
+ Tab to Train halutzim, Enter. Tab to End Turn, Enter: the turn ends and the turn report takes the focus; Enter on its
+ Close hands it to the next card, or to End Turn when none opens.
+- **Attention:** the opening turn has 4 Attention; answering the card and Train halutzim cost 2 each, a budget and an
+ appointment 4 each, so the five steps take more than one turn's Attention. That is the game's rule, not the keyboard's:
+ the test raises the Attention to check the path. With 4, the budget and the appointment are refused with the toast
+ ("Not enough attention (need 4.0, have 2.0)"), as for a mouse player.
+
+What failed, and what changed:
+
+| | Finding | Fix |
+|---|---|---|
+| K1 | Tab after the Cabinet's last card (and after the last candidate) lands on the list's own scroll bar. `FocusScroll` then called `ScrollView.ScrollTo` on it, which throws for anything outside the list's content: an error on every such Tab. | `FocusScroll` leaves an element outside the view's content alone (the scroll bar is always in sight). |
+| K2 | Enter on a city panel button (Train, Assign, Build) rebuilt the panel and took the focus with it; the next Tab started again at Cabinet, as H2 did on the Budget. | `InfoPanelPresenter` gives the focus to the rebuilt button of the same name after a keyboard press; a mouse press still leaves none (PointerBlur's rule). |
+
+Still open, not blocking the turn:
+
+- The Cabinet's two scroll bars are each one extra Tab stop.
+- A city panel button that is gone or disabled after the press (Assign's - at 0) still drops the focus.
+- From a screen's button it takes about 16 Tabs to reach the screen's first control.
+
+Pinned in EditMode: the card's order (the card, each option, Hide, the side menu, New Game, End Turn, Star, Report,
+Share, the card again; Shift+Tab the reverse), End Turn's (the map stop, the minimap's three buttons, Star, Report,
+Share, the side menu, New Game, End Turn; Shift+Tab to New Game) and where the focus goes after End Turn
+(`KeyboardTurnTests`). No UI string was added, so nothing goes to #564.
+
## Screenshots
In `.superpowers/a11y-2026-10-14/` (1568x752 unless noted), with the driver and the contrast, colour-vision and
diff --git a/unity/Assets/Scripts/UI/FocusScroll.cs b/unity/Assets/Scripts/UI/FocusScroll.cs
index 0304aee3c..3a993ca5d 100644
--- a/unity/Assets/Scripts/UI/FocusScroll.cs
+++ b/unity/Assets/Scripts/UI/FocusScroll.cs
@@ -75,7 +75,9 @@ namespace Statecraft.Game.UI
static bool Settled(VisualElement target)
{
var view = target.GetFirstAncestorOfType<ScrollView>();
- if (view == null) return true;
+ // The view's own scroll bar takes Tab too (#41, keyboard-only turn): it is always in sight, and ScrollTo throws
+ // for anything outside the content.
+ if (view == null || !view.contentContainer.Contains(target)) return true;
Rect r = target.worldBound, v = view.contentViewport.worldBound;
if (!LaidOut(r) || !LaidOut(v)) return false;
if (r.yMin >= v.yMin - 0.5f && r.yMax <= v.yMax + 0.5f && r.xMin >= v.xMin - 0.5f && r.xMax <= v.xMax + 0.5f) return true;
diff --git a/unity/Assets/Scripts/UI/InfoPanelPresenter.cs b/unity/Assets/Scripts/UI/InfoPanelPresenter.cs
index 95282a562..31a5d4fa2 100644
--- a/unity/Assets/Scripts/UI/InfoPanelPresenter.cs
+++ b/unity/Assets/Scripts/UI/InfoPanelPresenter.cs
@@ -49,6 +49,9 @@ namespace Statecraft.Game.UI
readonly MapRegions? regions;
readonly System.Func<string, (int q, int r)>? townHex;
readonly IReadOnlyDictionary<string, string>? townNamesHe;
+ /// <summary>Whether the last press in the panel came from the keyboard: only then does a rebuilt GDD part give the
+ /// focus back (RenderLines).</summary>
+ readonly PressSource presses;
/// <param name="localitiesAt">The 1948 localities that lie in a hex (null: the panel lists none); they are listed under the
/// settlements with today's name where the shared rule (Localities.TodayName) allows (#245).</param>
@@ -101,6 +104,7 @@ namespace Statecraft.Game.UI
onFortify = () => GiveOrder(Orders.Fortify); onHold = () => GiveOrder(Orders.Hold);
fortifyButton.clicked += onFortify; holdButton.clicked += onHold;
fortifyButton.text = text["unit.order.fortify"]; holdButton.text = text["unit.order.hold"];
+ presses = new PressSource(panel);
this.unitName = unitName;
attackButton = panel.Q<Button>("info-attack");
onAttack = () => TogglePick(attack: true);
@@ -114,7 +118,7 @@ namespace Statecraft.Game.UI
void OnHudGeometry(GeometryChangedEvent e) => panel.EnableInClassList(ShortClass, e.newRect.height < ShortBelowPx);
/// <summary>Unsubscribes from the bridge and the buttons (the owner calls this when disabled).</summary>
- public void Dispose() { bridge.Changed -= Render; panel.parent?.UnregisterCallback<GeometryChangedEvent>(OnHudGeometry); campButton.clicked -= onCamp; housingButton.clicked -= onHousing; defenceButton.clicked -= onDefence; moveButton.clicked -= onMove; fortifyButton.clicked -= onFortify; holdButton.clicked -= onHold; attackButton.clicked -= onAttack; EndPick(); }
+ public void Dispose() { presses.Dispose(); bridge.Changed -= Render; panel.parent?.UnregisterCallback<GeometryChangedEvent>(OnHudGeometry); campButton.clicked -= onCamp; housingButton.clicked -= onHousing; defenceButton.clicked -= onDefence; moveButton.clicked -= onMove; fortifyButton.clicked -= onFortify; holdButton.clicked -= onHold; attackButton.clicked -= onAttack; EndPick(); }
/// <summary>Below this window height (logical px; 1366x657 is about 998) the panel gets ShortClass, and the city's own
/// hex folds its projects behind their toggle as on a stacked bar (GddHexPanel.ToggleName): there the full list ran into
@@ -448,7 +452,21 @@ namespace Statecraft.Game.UI
var owned = c.SettlementHexes.Where(x => x.Q == q && x.R == r).Select(x => TownName(x.Id)).ToList(); // strict: every settlement hex has a name (final review M4)
title.text = owned.Count > 0 ? owned[0] : hex == null ? text["info.off_map"] : text["info.biome." + hex.Biome];
// The GDD loop's city or designated site (#381); a site's hex has no settlement, so its name is the title.
+ // GddHexPanel rebuilds its part on every render, so a button pressed from the keyboard (Train, Assign, Build) went
+ // with the focus and the next Tab started again at Cabinet (#41, the keyboard-only turn): the rebuilt button of
+ // the same name takes it back. A pointer press leaves no focus (PointerBlur), so it gets none. PressSource reads
+ // "keyboard" until the first pointer press in the panel; here that only means a focus nobody pressed stays put.
+ // A hex with two sites (the Hula swamp and its field) or two corridor segments gives each part buttons of the same
+ // names (site-build-<unit>, site-stop), so the button is looked up inside the part it was in.
+ var focused = presses.ByKeyboard ? panel.focusController?.focusedElement as VisualElement : null;
+ var keep = focused != null && (gdd.Contains(focused) || projects.Contains(focused)) ? focused.name : null;
+ var part = keep == null ? null : focused!.parent;
+ while (part != null && !(part.name is { } pn && (pn.StartsWith("site-part-", System.StringComparison.Ordinal) || pn.StartsWith("corridor-part-", System.StringComparison.Ordinal))))
+ part = part.parent;
+ var partName = part?.name;
var siteName = GddHexPanel.Render(gdd, projects, bridge, text, q, r, TownName);
+ if (!string.IsNullOrEmpty(keep))
+ FocusReturn.To(partName != null ? gdd.Q(partName)?.Q(keep) : gdd.Q(keep) ?? projects.Q(keep));
if (siteName != null && owned.Count == 0) title.text = siteName;
subtitle.text = hex == null ? "" : text.Format("info.hex", text["info.biome." + hex.Biome], hex.ElevM); // no debug coordinates in player text (playtest 2, P2-6)
// The armistice zone in force, else the sub-district on 15 May 1948, and any armistice line in force through the
diff --git a/unity/Assets/Tests/EditMode/CityPanelTests.cs b/unity/Assets/Tests/EditMode/CityPanelTests.cs
index 43e7f67e1..de9f30f2c 100644
--- a/unity/Assets/Tests/EditMode/CityPanelTests.cs
+++ b/unity/Assets/Tests/EditMode/CityPanelTests.cs
@@ -484,6 +484,31 @@ public class CityPanelTests
Assert.AreEqual((Projects.DrySwamp, "hula"), (order?.Action, order?.Site));
}
+ /// <summary>#41 (review of #1330): on a hex with two sites both parts hold a site-build-&lt;unit&gt; button; when the panel
+ /// is rebuilt (any bridge change), the focus goes back to the button in the part that had it, not the first part's.</summary>
+ [Test]
+ public void ARebuiltSiteHexKeepsTheFocusInThePartThatHadIt()
+ {
+ var camp = Def("camp_80");
+ var field = new Statecraft.Sim.Site { Id = "a_camp_field", Name = "A camp field", Q = camp.Q, R = camp.R, Kinds = new System.Collections.Generic.List<string> { "field" } };
+ C.Sites.Add(field);
+ try
+ {
+ using var ui = new UiTestKit();
+ int a = -1;
+ var bridge = Bridge(En, s => a = AddHalutz(s));
+ using var panel = Panel(ui, bridge, En);
+ panel.Show(camp.Q, camp.R);
+ Assert.IsNotNull(SiteBox(ui, camp.Id).Q<Button>($"site-build-{a}"), "precondition: the camp's part, first, has the same button");
+ SiteBox(ui, field.Id).Q<Button>($"site-build-{a}").Focus();
+ panel.Render();
+ var focused = ui.Root.focusController.focusedElement as VisualElement;
+ Assert.AreEqual($"site-build-{a}", focused?.name);
+ Assert.IsTrue(SiteBox(ui, field.Id).Contains(focused), "the field's rebuilt Build, not the camp's");
+ }
+ finally { C.Sites.Remove(field); }
+ }
+
/// <summary>#1124 (R-FIELD-001): a yishuv's field waits while the yishuv is not built, and offers Plow once it is.</summary>
[Test]
public void AYishuvsFieldIsPlowedOnceTheYishuvIsBuilt()
diff --git a/unity/Assets/Tests/EditMode/DecisionCardTests.cs b/unity/Assets/Tests/EditMode/DecisionCardTests.cs
index 97c768dfa..bd02d4c59 100644
--- a/unity/Assets/Tests/EditMode/DecisionCardTests.cs
+++ b/unity/Assets/Tests/EditMode/DecisionCardTests.cs
@@ -369,7 +369,7 @@ public class DecisionCardTests
/// <summary>A mouse press as the player makes it: pointer down (which also gives the button the focus), then the
/// button's Clickable fires `clicked` on pointer up. UiTestKit.Press is the keyboard's Submit instead.</summary>
- static void PressWithPointer(Button b)
+ internal static void PressWithPointer(Button b)
{
b.Focus();
using (var down = PointerDownEvent.GetPooled()) { down.target = b; b.SendEvent(down); }
diff --git a/unity/Assets/Tests/EditMode/KeyboardTurnTests.cs b/unity/Assets/Tests/EditMode/KeyboardTurnTests.cs
new file mode 100644
index 000000000..46301c186
--- /dev/null
+++ b/unity/Assets/Tests/EditMode/KeyboardTurnTests.cs
@@ -0,0 +1,267 @@
+#nullable enable
+using System;
+using System.Collections;
+using System.Collections.Generic;
+using System.IO;
+using System.Linq;
+using NUnit.Framework;
+using Statecraft.Game;
+using Statecraft.Game.Map;
+using Statecraft.Game.UI;
+using Statecraft.Sim;
+using UnityEditor.SceneManagement;
+using UnityEngine;
+using UnityEngine.TestTools;
+using UnityEngine.UIElements;
+using Object = UnityEngine.Object;
+
+/// <summary>#41's done-when (owner, 22 October 2026): one GDD turn played with the keyboard alone (answer the event card,
+/// change a budget line, appoint a minister, give a training order in a city, end the turn), and the focus order of the
+/// event card and of End Turn pinned. Map.unity as the player gets it, at 1280x720. Keys reach the UI as the UI Toolkit
+/// events the Input System's UI provider makes of them (Tab and Shift+Tab: NavigationMoveEvent Next and Previous; Enter:
+/// KeyDownEvent then NavigationSubmitEvent; Escape: NavigationCancelEvent), as in MapFocusTests: an edit-mode panel gets no
+/// device input.</summary>
+public class KeyboardTurnTests
+{
+ string saveDir = "";
+ RenderTexture? rt; PanelSettings? ps;
+ VisualElement ui = null!;
+ GameRoot root = null!;
+
+ [SetUp] public void TempSaves() => saveDir = Path.Combine(Path.GetTempPath(), "statecraft-kbturn-" + Guid.NewGuid().ToString("N"));
+
+ [TearDown]
+ public void DiscardScene()
+ {
+ EditorSceneManager.NewScene(NewSceneSetup.EmptyScene, NewSceneMode.Single);
+ if (ps != null) Object.DestroyImmediate(ps);
+ if (rt != null) { rt.Release(); Object.DestroyImmediate(rt); }
+ if (Directory.Exists(saveDir)) Directory.Delete(saveDir, true);
+ }
+
+ /// <summary>Map.unity on a 1280x720 panel, a new GDD game begun as GameBoot.Ready does with no start screen: the opening
+ /// event card is open and has the focus.</summary>
+ IEnumerator Boot()
+ {
+ EditorSceneManager.OpenScene("Assets/Map.unity", OpenSceneMode.Single);
+ var doc = Object.FindFirstObjectByType<UIDocument>();
+ rt = new RenderTexture(1280, 720, 0);
+ ps = Object.Instantiate(doc.panelSettings);
+ ps.targetTexture = rt;
+ doc.panelSettings = ps;
+ Object.FindFirstObjectByType<MapScene>().Build(MapFocusTests.Inputs.Map);
+ root = Object.FindFirstObjectByType<GameRoot>();
+ root.Store = new SaveStore(saveDir);
+ root.Begin(MapFocusTests.Inputs, 0);
+ ui = doc.rootVisualElement;
+ for (int i = 0; i < 30 && !(ui.Q("top-bar").worldBound.height > 0); i++) yield return null;
+ yield return Frames(5);
+ Assert.IsTrue(Bridge.Content.IsGdd, "precondition: the GDD loop");
+ }
+
+ SimBridge Bridge => root.Bridge!;
+ static IEnumerator Frames(int n) { for (int i = 0; i < n; i++) yield return null; }
+ Focusable? Focused => ui.panel.focusController.focusedElement;
+ string FocusedName => (Focused as VisualElement)?.name is string n && n.Length > 0 ? n : Focused == null ? "none" : Focused.GetType().Name;
+ VisualElement At => Focused as VisualElement ?? throw new AssertionException("nothing has the focus");
+
+ IEnumerator Tab(bool back = false)
+ {
+ var at = At;
+ using (var e = NavigationMoveEvent.GetPooled(back ? NavigationMoveEvent.Direction.Previous : NavigationMoveEvent.Direction.Next)) { e.target = at; at.SendEvent(e); }
+ yield return null;
+ }
+
+ IEnumerator Enter()
+ {
+ var at = At;
+ using (var e = KeyDownEvent.GetPooled('\n', KeyCode.Return, EventModifiers.None)) { e.target = at; at.SendEvent(e); }
+ using (var e = NavigationSubmitEvent.GetPooled()) { e.target = at; at.SendEvent(e); }
+ yield return Frames(3);
+ }
+
+ IEnumerator Escape()
+ {
+ var at = At;
+ using (var e = NavigationCancelEvent.GetPooled()) { e.target = at; at.SendEvent(e); }
+ yield return Frames(3);
+ }
+
+ /// <summary>Tabs until <paramref name="want"/> has the focus, at most <paramref name="max"/> times; fails with the path
+ /// taken.</summary>
+ IEnumerator TabTo(Func<VisualElement, bool> want, string what, int max = 60)
+ {
+ var seen = new List<string> { FocusedName };
+ for (int i = 0; i < max && !want(At); i++) { yield return Tab(); seen.Add(FocusedName); }
+ Assert.IsTrue(want(At), $"Tab reaches {what}: {string.Join(" > ", seen)}");
+ }
+
+ IEnumerator TabTo(string name) => TabTo(v => v.name == name, name);
+
+ /// <summary>The names Tab (or Shift+Tab) visits from the focused element, <paramref name="n"/> presses.</summary>
+ IEnumerator Order(List<string> into, int n, bool back = false)
+ {
+ into.Add(FocusedName);
+ for (int i = 0; i < n; i++) { yield return Tab(back); into.Add(FocusedName); }
+ }
+
+ /// <summary>The side menu, New Game, End Turn: the HUD's own controls, in the order Game.uxml gives them.</summary>
+ static readonly string[] Menu = { "nav-cabinet", "nav-budget", "nav-defence", "nav-why", "nav-timeline", "nav-how-to-play", "nav-objectives", "nav-settings", "new-game", "end-turn" };
+
+ /// <summary>The open card takes the focus; Tab runs the card, each option in its order, Hide, then the HUD from the side
+ /// menu on (the map stop, the minimap and the info panel are under the card's backdrop and out of reach), and round to
+ /// the card again; Shift+Tab runs the same order backwards.</summary>
+ [UnityTest]
+ public IEnumerator TheEventCardsFocusOrderIsTheCardItsOptionsHideThenTheHud()
+ {
+ yield return Boot();
+ Assert.AreEqual("event-card", FocusedName, "the open card has the focus");
+ var options = ui.Q("event-options").Query<Button>().ToList().Select(b => b.name).ToList();
+ Assert.GreaterOrEqual(options.Count, 2, "precondition: the opening card offers a choice");
+ Assert.AreEqual(DisplayStyle.None, ui.Q("event-illustration").resolvedStyle.display, "precondition: no clip, so no Illustration switch");
+ var expected = new[] { "event-card" }.Concat(options).Concat(new[] { "event-hide" }).Concat(Menu)
+ .Concat(new[] { "hud-star", "hud-report", "hud-share", "event-card" }).ToList();
+ var seen = new List<string>();
+ yield return Order(seen, expected.Count - 1);
+ CollectionAssert.AreEqual(expected, seen, "Tab from the card: " + string.Join(" > ", seen));
+ var back = new List<string>();
+ yield return Order(back, expected.Count - 1, back: true);
+ expected.Reverse();
+ CollectionAssert.AreEqual(expected, back, "Shift+Tab from the card: " + string.Join(" > ", back));
+ }
+
+ /// <summary>With no card open (the opening one answered from the keyboard, which hands the focus to End Turn), End Turn
+ /// comes after the side menu and New Game; Tab from it goes to the map stop, the minimap's buttons, Star, Report and
+ /// Share, and round to the side menu; Shift+Tab from it goes back to New Game. Enter on it ends the turn: the turn report
+ /// takes the focus, and closing it with Enter hands the focus on (to the next card if one opens, else End Turn), so
+ /// the next turn is played from the keyboard too.</summary>
+ [UnityTest]
+ public IEnumerator EndTurnsPlaceInTheOrderAndWhereTheFocusGoesAfterIt()
+ {
+ yield return Boot();
+ yield return TabTo(v => v.ClassListContains(EventCardPresenter.OptionClass), "an option");
+ yield return Enter();
+ Assert.AreEqual("end-turn", FocusedName, "the last card answered from the keyboard hands the focus to End Turn");
+ var expected = new[] { "end-turn", "map-focus", "minimap-overview", "minimap-labels", "minimap-borders", "hud-star", "hud-report", "hud-share" }
+ .Concat(Menu).ToList();
+ var seen = new List<string>();
+ yield return Order(seen, expected.Count - 1);
+ CollectionAssert.AreEqual(expected, seen, "Tab from End Turn round the HUD: " + string.Join(" > ", seen));
+ var back = new List<string>();
+ yield return Order(back, 1, back: true);
+ CollectionAssert.AreEqual(new[] { "end-turn", "new-game" }, back, "Shift+Tab from End Turn");
+ yield return TabTo("end-turn");
+
+ var turn = Bridge.State.Turn;
+ yield return Enter();
+ yield return Frames(5);
+ Assert.AreEqual(turn + 1, Bridge.State.Turn, "Enter on End Turn ends the turn");
+ Assert.AreEqual("turn-report-close", FocusedName, "the turn report takes the focus");
+ yield return Enter();
+ yield return Frames(5);
+ var card = ui.Q("event-card");
+ var next = card.enabledInHierarchy && card.resolvedStyle.display == DisplayStyle.Flex ? "event-card" : "end-turn";
+ Assert.AreEqual(next, FocusedName, "closing the report hands the focus on");
+ }
+
+ /// <summary>The done-when's turn, keys only: answer the opening card; open Budget, raise a line with its + and submit;
+ /// open the Cabinet, select a seat, appoint a candidate; close it with Escape; Tab to the map stop over Tel Aviv, Enter
+ /// to pick it, Tab to Train halutzim in its city panel and press it; Tab to End Turn and end the turn. Each order is
+ /// queued, and a press that rebuilds what it is part of keeps the focus there. The opening turn's attention (4) pays for
+ /// two of these orders; the test raises it, since what is checked is the keyboard's path, not the attention rule.</summary>
+ [UnityTest]
+ public IEnumerator AWholeTurnPlaysWithTheKeyboardAlone()
+ {
+ yield return Boot();
+ Bridge.State.Attention = 100;
+
+ // The event card.
+ yield return TabTo(v => v.ClassListContains(EventCardPresenter.OptionClass), "an option");
+ yield return Enter();
+ Assert.IsTrue(Bridge.Queued.OfType<ChooseEventOption>().Any(), "the card is answered");
+ Assert.AreEqual("end-turn", FocusedName);
+
+ // A budget line.
+ yield return TabTo("nav-budget");
+ yield return Enter();
+ Assert.AreEqual("budget", ScreenOpen(), "Enter opens Budget");
+ yield return TabTo(v => v.name.StartsWith("budget-", StringComparison.Ordinal) && v.name.EndsWith("-up", StringComparison.Ordinal), "a budget line's +");
+ var plus = FocusedName;
+ yield return Enter();
+ Assert.AreEqual(plus, FocusedName, "the + keeps the focus (H2)");
+ yield return TabTo("budget-submit");
+ yield return Enter();
+ Assert.IsTrue(Bridge.Queued.OfType<AllocateBudget>().Any(), "the budget is submitted");
+
+ // A minister.
+ yield return TabTo("nav-cabinet");
+ yield return Enter();
+ Assert.AreEqual("cabinet", ScreenOpen(), "Enter opens the Cabinet");
+ yield return TabTo(v => v.name.StartsWith("seat-", StringComparison.Ordinal) && v.name != "seat-prime_minister", "a minister's seat");
+ yield return Enter();
+ yield return TabTo(v => ui.Q("cabinet-candidates").Contains(v), "a candidate");
+ yield return Enter();
+ Assert.IsTrue(Bridge.Queued.OfType<Appoint>().Any(), "the appointment is ordered");
+ // The candidate list's and the seat list's own scroll bars take Tab after their last row: no error, and Tab goes on.
+ yield return TabTo(v => v.name == "seat-chief_of_staff", "the last seat, past every candidate", 120);
+ yield return Tab();
+ Assert.IsTrue(At is Scroller || At.GetFirstAncestorOfType<Scroller>() != null, $"the Tab after the last seat lands on a scroll bar (K1), not {FocusedName}");
+ yield return TabTo("nav-cabinet");
+ yield return Escape();
+ Assert.IsNull(ScreenOpen(), "Escape closes the Cabinet");
+ Assert.AreEqual("nav-cabinet", FocusedName, "and hands the focus to its button (M1)");
+
+ // A training order in a city.
+ yield return TabTo("map-focus");
+ LookAtTelAviv();
+ yield return Frames(3);
+ yield return Enter();
+ Assert.AreEqual("Tel Aviv", ui.Q<Label>("info-title").text, "Enter on the map stop picks Tel Aviv");
+ yield return TabTo("city-train-halutz");
+ yield return Enter();
+ Assert.IsTrue(Bridge.Queued.OfType<Train>().Any(t => t.Track == "halutz"), "the training order is queued");
+ Assert.AreEqual("city-train-halutz", FocusedName, "the rebuilt panel gives the focus back to Train halutzim");
+
+ // End the turn.
+ yield return TabTo("end-turn");
+ var turn = Bridge.State.Turn;
+ yield return Enter();
+ yield return Frames(5);
+ Assert.AreEqual(turn + 1, Bridge.State.Turn, "the turn ends");
+ }
+
+ /// <summary>The counterpart: Train halutzim pressed with the mouse gives the rebuilt button no focus (PointerBlur's rule,
+ /// a click leaves no focus fill behind).</summary>
+ [UnityTest]
+ public IEnumerator ATrainingOrderByThePointerLeavesNoFocus()
+ {
+ yield return Boot();
+ Bridge.State.Attention = 100;
+ GameSceneTests.HideTheOpeningCard(ui);
+ LookAtTelAviv();
+ var stop = ui.Q("map-focus");
+ for (int i = 0; i < 10 && Focused != stop; i++) { yield return null; stop.Focus(); }
+ yield return Enter();
+ Assert.AreEqual("Tel Aviv", ui.Q<Label>("info-title").text, "precondition: Tel Aviv's city panel");
+ DecisionCardTests.PressWithPointer(ui.Q<Button>("city-train-halutz"));
+ yield return Frames(3);
+ Assert.IsTrue(Bridge.Queued.OfType<Train>().Any(t => t.Track == "halutz"), "the click queues the order");
+ Assert.AreNotEqual("city-train-halutz", FocusedName, "and leaves the rebuilt button unlit");
+ }
+
+ string? ScreenOpen() => ScreenNav.Screens.FirstOrDefault(s => ui.Q("nav-" + s).ClassListContains(ScreenNav.OpenClass));
+
+ /// <summary>Moves the camera's look-at point onto Tel Aviv's hex, on the ground, as a pan would (MapFocusTests).</summary>
+ static void LookAtTelAviv()
+ {
+ var map = Object.FindFirstObjectByType<MapScene>();
+ var c = MapFocusTests.Inputs.Content;
+ var tlv = c.SettlementHexes.Single(s => s.Id == "tel_aviv");
+ var hex = c.HexAt(tlv.Q, tlv.R)!;
+ var ground = map.Frame.ToWorld(hex.Lon, hex.Lat, 0);
+ ground.y = map.Terrain.SampleHeight(ground) + map.Terrain.transform.position.y;
+ var rig = Camera.main.GetComponent<CameraRig>();
+ rig.LookAt = ground; rig.Distance = 30000f;
+ rig.Apply();
+ }
+}
diff --git a/unity/Assets/Tests/EditMode/KeyboardTurnTests.cs.meta b/unity/Assets/Tests/EditMode/KeyboardTurnTests.cs.meta
new file mode 100644
index 000000000..b7b878dbe
--- /dev/null
+++ b/unity/Assets/Tests/EditMode/KeyboardTurnTests.cs.meta
@@ -0,0 +1,2 @@
+fileFormatVersion: 2
+guid: ff2cd95ee35ab06b19271852471d3cdb
\ No newline at end of file