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.

Tests: EditMode tests that claim GameRoot wiring go through it, or say they don't (Fixes #2663) (#2686)

Eyal Golan0050426ab58e
diff --git a/unity/Assets/Tests/EditMode/AdvisorGameTests.cs b/unity/Assets/Tests/EditMode/AdvisorGameTests.cs
index cd2b1da89..0b2ddb3f5 100644
--- a/unity/Assets/Tests/EditMode/AdvisorGameTests.cs
+++ b/unity/Assets/Tests/EditMode/AdvisorGameTests.cs
@@ -72,6 +72,28 @@ public class AdvisorGameTests
Assert.IsTrue(game.AdvisorSession!.AutoShow);
}
+ /// <summary>GameRoot's ordered Escape hook gives the advisor the key before ScreenNav closes the screen underneath it.</summary>
+ [Test]
+ public void GameRootEscapeHookClosesTheAdvisorBeforeTheOpenScreen()
+ {
+ var store = new SaveStore(TempDir());
+ store.WriteAutosave(GameSession.New(Inputs.Content, 9, Mode.Historical).Save.Write());
+ var game = OpenScene(store, new SettingsStore(TempDir()));
+ game.Begin(Inputs, 0, startScreen: true);
+ Assert.IsTrue(game.AdvisorSession!.AutoShow, "precondition: a player boot offers advisor signals");
+ UiTestKit.Press(Ui.Q<Button>("start-continue"));
+ game.Card!.Collapse(takeFocus: false);
+ UiTestKit.Press(Ui.Q<Button>("nav-budget"));
+ game.Advisor!.Notice(AdvisorSignals.BudgetUnsubmitted);
+ Assert.IsTrue(game.Advisor.IsOpen, "precondition: the advisor is open over Budget");
+ var gotIt = Ui.Q<Button>("advisor-got-it");
+ gotIt.Focus();
+ using (var esc = NavigationCancelEvent.GetPooled()) { esc.target = gotIt; gotIt.SendEvent(esc); }
+ Assert.IsFalse(game.Advisor.IsOpen, "Escape closes the advisor");
+ Assert.AreEqual(DisplayStyle.Flex, Ui.Q("screen-budget").style.display.value,
+ "GameRoot's TakesEscape hook consumed the key before ScreenNav");
+ }
+
[Test]
public void TheLanguageSwitchKeepsTheAdvisorsSession()
{
diff --git a/unity/Assets/Tests/EditMode/AdvisorMediaTests.cs b/unity/Assets/Tests/EditMode/AdvisorMediaTests.cs
index 2e7f101a6..5def811e5 100644
--- a/unity/Assets/Tests/EditMode/AdvisorMediaTests.cs
+++ b/unity/Assets/Tests/EditMode/AdvisorMediaTests.cs
@@ -188,7 +188,7 @@ public class AdvisorMediaTests
}
[Test]
- public void TheOverlayClosesWithItsXOrEscapeAndStopsBoth()
+ public void AnInjectedEscapeChainClosesTheOverlayAndStopsBoth()
{
using var rig = new AdvisorPopupTests.Rig(text: Text);
var pic = new FakePicture { Ready = true }; var output = new FakeOutput();
@@ -196,7 +196,7 @@ public class AdvisorMediaTests
rig.Advisor.ForceInline = false;
rig.Advisor.NewGame();
// ScreenNav's Cancel trickles down from the root and closes the open screen unless a layer takes it first: GameRoot
- // gives the overlay that turn through TakesEscape (GameRoot.cs, nav!.TakesEscape), wired here the same way.
+ // gives the overlay that turn through TakesEscape (GameRoot.cs, nav!.TakesEscape); this unit fixture injects that ordering.
rig.Nav.TakesEscape = () => rig.Advisor.CloseOverlay() || rig.Advisor.OverlayClosedThisFrame || rig.Advisor.Escape();
rig.Ui.Press("nav-budget"); // a screen under the overlay
Assert.AreEqual("budget", rig.Nav.Current, "precondition");
diff --git a/unity/Assets/Tests/EditMode/AdvisorOpeningParityTests.cs b/unity/Assets/Tests/EditMode/AdvisorOpeningParityTests.cs
index d13ed011b..e444635ab 100644
--- a/unity/Assets/Tests/EditMode/AdvisorOpeningParityTests.cs
+++ b/unity/Assets/Tests/EditMode/AdvisorOpeningParityTests.cs
@@ -418,7 +418,7 @@ public class AdvisorOpeningParityTests
Assert.IsTrue(rig.Advisor.Escape(), "Escape skips it");
Assert.IsFalse(rig.Advisor.InChain);
// The guide's "Escape does nothing when closed" cannot be asked again here: Time.frameCount does not move in an
- // edit-mode test, so Escape keeps answering "used this frame" (AdvisorPopupTests.OneEscapeInThePopupLeavesTheScreenUnderItOpen).
+ // edit-mode test, so Escape keeps answering "used this frame" (AdvisorPopupTests.AnInjectedScreenNavHookLeavesTheScreenUnderThePopupOpen).
Assert.IsFalse(rig.Ui.Root.Q("root").ClassListContains(AdvisorPresenter.OpenClass), "and it stays closed");
rig.Card.Collapse(); // the player hid the card before opening the advisor
diff --git a/unity/Assets/Tests/EditMode/AdvisorPopupTests.cs b/unity/Assets/Tests/EditMode/AdvisorPopupTests.cs
index 26559bddf..bcbc2135e 100644
--- a/unity/Assets/Tests/EditMode/AdvisorPopupTests.cs
+++ b/unity/Assets/Tests/EditMode/AdvisorPopupTests.cs
@@ -238,11 +238,12 @@ public class AdvisorPopupTests
}
/// <summary>Spec 16: one Escape with the focus in the popup closes the popup only, as in the report panel (#1169).
- /// ScreenNav's Cancel asks it first (TakesEscape, as GameRoot wires it), and GameRoot's Escape poll asks it before it
+ /// This unit fixture injects ScreenNav's TakesEscape ordering; GameRoot's boot hookup is covered by AdvisorGameTests.
+ /// The Escape poll asks the popup before it
/// closes the screen, also in the frame its Cancel already closed it. (Time.frameCount does not move in an edit-mode
/// test, so after this the popup keeps saying "used this frame".)</summary>
[Test]
- public void OneEscapeInThePopupLeavesTheScreenUnderItOpen()
+ public void AnInjectedScreenNavHookLeavesTheScreenUnderThePopupOpen()
{
using var rig = new Rig();
rig.Nav.TakesEscape = rig.Advisor.Escape;
diff --git a/unity/Assets/Tests/EditMode/AdvisorSignalsTests.cs b/unity/Assets/Tests/EditMode/AdvisorSignalsTests.cs
index df21cc72e..1a086cc11 100644
--- a/unity/Assets/Tests/EditMode/AdvisorSignalsTests.cs
+++ b/unity/Assets/Tests/EditMode/AdvisorSignalsTests.cs
@@ -72,24 +72,34 @@ public class AdvisorSignalsTests
CollectionAssert.Contains(Waiting(game.AdvisorSession!, bridge), "meyerson.debt_ceiling");
}
- /// <summary>Review (must-fix 3): Submit takes the unsubmitted-budget warning back, shown or waiting, as GameRoot wires the
- /// Budget screen to the advisor.</summary>
+ /// <summary>Review (must-fix 3): Submit takes the unsubmitted-budget warning back, shown or waiting, through the real
+ /// GameRoot.Begin hookup from the Budget screen to the advisor.</summary>
[Test]
public void SubmittingTheBudgetTakesItsWarningBack()
{
- var text = UiText.Parse(AssetDatabase.LoadAssetAtPath<TextAsset>(UiPaths.Strings).text);
- using var rig = new AdvisorPopupTests.Rig(catalog: System.IO.File.ReadAllText(AdvisorCatalog.Path), text: text);
- using var budget = new BudgetPresenter(rig.Ui.Root, rig.Bridge, text);
- budget.UnsubmittedChanged += rig.Advisor.BudgetUnsubmitted;
- rig.Ui.Press("budget-education_minister-up");
- Assert.AreEqual("meyerson.budget_unsubmitted", rig.Advisor.Shown?.Id, "an edit not submitted");
- rig.Ui.Press("budget-submit");
- Assert.AreNotEqual("meyerson.budget_unsubmitted", rig.Advisor.Shown?.Id, "submitted: no longer true");
- CollectionAssert.DoesNotContain(Drain(rig), "meyerson.budget_unsubmitted", "nor waiting");
+ var store = new SaveStore(TempDir());
+ store.WriteAutosave(GameSession.New(C, 9, Mode.Historical).Save.Write());
+ EditorSceneManager.OpenScene("Assets/Map.unity", OpenSceneMode.Single);
+ var inputs = GameInputs.FromDisk(Paths.Content, Paths.StreamingMap);
+ Object.FindFirstObjectByType<MapScene>().Build(inputs.Map);
+ var game = Object.FindFirstObjectByType<GameRoot>();
+ game.Store = store; game.Settings = new SettingsStore(TempDir()); game.Language = UiLanguage.English;
+ game.Begin(inputs, 0, startScreen: true);
+ Assert.IsTrue(game.AdvisorSession!.AutoShow, "precondition: a player boot offers advisor signals");
+ var ui = Object.FindFirstObjectByType<UIDocument>().rootVisualElement;
+ UiTestKit.Press(ui.Q<Button>("start-continue"));
+ game.Card!.Collapse(takeFocus: false);
+ UiTestKit.Press(ui.Q<Button>("nav-budget"));
+ UiTestKit.Press(ui.Q<Button>("budget-education_minister-up"));
+ Assert.AreEqual("meyerson.budget_unsubmitted", game.Advisor!.Shown?.Id, "an edit not submitted");
+ UiTestKit.Press(ui.Q<Button>("budget-submit"));
+ Assert.AreNotEqual("meyerson.budget_unsubmitted", game.Advisor.Shown?.Id, "submitted: no longer true");
+ CollectionAssert.DoesNotContain(Waiting(game.AdvisorSession, game.Bridge!), "meyerson.budget_unsubmitted", "nor waiting");
}
- /// <summary>Owner, 1 Nov 2026 (#2110): the budget warning's cause is the unsubmitted edit, not the turn its signal fired.
- /// Put off with Not now, it survives the next turn while the edit is unsubmitted, and goes once it is submitted.</summary>
+ /// <summary>Agent-recorded scope for #2110 (1 Nov 2026): the budget warning's cause is the unsubmitted edit, not the turn its signal fired.
+ /// Put off with Not now, it survives the next turn while the edit is unsubmitted, and goes once it is submitted. This is
+ /// a presenter-level lifetime test; the fixture injects the subscription covered by SubmittingTheBudgetTakesItsWarningBack.</summary>
[Test]
public void APutOffBudgetWarningLastsWhileTheEditIsUnsubmitted()
{
@@ -109,8 +119,9 @@ public class AdvisorSignalsTests
Assert.AreEqual(AdvisorQueue.Outcome.Missed, rig.Session.Queue.History.Last(h => h.Id == id).Outcome);
}
- /// <summary>Owner, 1 Nov 2026 (#2110): the cover path checks the same cause. Covered by a layer, the budget warning
- /// survives End turn while the edit is unsubmitted, and comes back when the layer closes.</summary>
+ /// <summary>Agent-recorded scope for #2110 (1 Nov 2026): the cover path checks the same cause. Covered by a layer, the budget warning
+ /// survives End turn while the edit is unsubmitted, and comes back when the layer closes. This is a presenter-level
+ /// lifetime test; the fixture injects the subscription covered by SubmittingTheBudgetTakesItsWarningBack.</summary>
[Test]
public void ACoveredBudgetWarningLastsWhileTheEditIsUnsubmitted()
{
@@ -236,9 +247,9 @@ public class AdvisorSignalsTests
Assert.IsTrue(rig.Session.Catalog.Find(id)!.ApprovedIn(hebrew: true), id);
}
- /// <summary>Task 18: an unsubmitted budget change (BudgetPresenter.UnsubmittedChanged, wired by GameRoot) is a warning.</summary>
+ /// <summary>Task 18: the budget-unsubmitted advisor signal is classified as a warning.</summary>
[Test]
- public void AnUnsubmittedBudgetIsAWarning()
+ public void BudgetUnsubmittedSignalIsWarningLevel()
{
var text = UiText.Parse(AssetDatabase.LoadAssetAtPath<TextAsset>(UiPaths.Strings).text);
using var rig = new AdvisorPopupTests.Rig(catalog: System.IO.File.ReadAllText(AdvisorCatalog.Path), text: text);
diff --git a/unity/Assets/Tests/EditMode/GameSceneTests.cs b/unity/Assets/Tests/EditMode/GameSceneTests.cs
index b70f8b995..3f5697b8a 100644
--- a/unity/Assets/Tests/EditMode/GameSceneTests.cs
+++ b/unity/Assets/Tests/EditMode/GameSceneTests.cs
@@ -9,12 +9,14 @@ using NUnit.Framework;
using Statecraft.Game;
using Statecraft.Game.Boot;
using Statecraft.Game.Map;
+using Statecraft.Game.Map.Collection;
using Statecraft.Game.UI;
using Statecraft.Sim;
using UnityEditor;
using UnityEditor.SceneManagement;
using UnityEngine;
using UnityEngine.InputSystem;
+using UnityEngine.InputSystem.LowLevel;
using UnityEngine.TestTools;
using UnityEngine.UIElements;
using Object = UnityEngine.Object;
@@ -509,7 +511,7 @@ public class GameSceneTests
}
/// <summary>#1063 (player report: a city is hard to tell from the land round it and hard to click). Hovering Tel Aviv's
- /// hex or its name pill lights the pill (GameRoot.HoverCity); a hex with no city lights nothing. A click on the hex and a
+ /// hex or its name pill lights the pill through GameRoot.LateUpdate; a hex with no city lights nothing. A click on the hex and a
/// click on the pill each open the city panel, the pill's also where the land under the pill is another hex.</summary>
[UnityTest]
public IEnumerator ACitysHexAndItsNamePillBothOpenTheCityPanel()
@@ -521,8 +523,10 @@ public class GameSceneTests
var camRt = new RenderTexture(1920, 1080, 24); // the camera fills the panel, as in the game (MapLabelsPresenter)
var ps = Object.Instantiate(doc.panelSettings);
ps.targetTexture = rt;
+ var mouse = InputSystem.AddDevice<Mouse>();
try
{
+ Assert.AreSame(mouse, UnityEngine.InputSystem.Pointer.current, "precondition: LateUpdate reads the test mouse");
doc.panelSettings = ps;
cam.targetTexture = camRt;
var map = Object.FindFirstObjectByType<MapScene>();
@@ -554,7 +558,10 @@ public class GameSceneTests
// The hex.
Assert.AreEqual((tlv.Q, tlv.R), Land(onHex), "precondition: the probe is on Tel Aviv's hex");
- Assert.AreEqual("tel_aviv", root.HoverCity(onHex), "the pointer over Tel Aviv's hex");
+ InputSystem.QueueStateEvent(mouse, new MouseState { position = onHex });
+ InputSystem.Update();
+ // In edit mode GameRoot.LateUpdate runs only when the player loop is asked for (as HudTests does).
+ for (int i = 0; i < 5 && !label.ClassListContains(MapLabelsPresenter.HoverClass); i++) { EditorApplication.QueuePlayerLoopUpdate(); yield return null; }
Assert.IsTrue(label.ClassListContains(MapLabelsPresenter.HoverClass), "lights Tel Aviv's pill");
Assert.IsTrue(pointer.HandleClick(onHex));
Assert.AreEqual("Tel Aviv", ui.Q<Label>("info-title").text);
@@ -565,7 +572,9 @@ public class GameSceneTests
var seaHex = Land(sea);
Assert.IsNotNull(seaHex, "precondition: the sea probe is on the map");
Assert.IsFalse(c.SettlementHexes.Any(x => (x.Q, x.R) == seaHex!.Value && root.Bridge!.State.Cities.ContainsKey(x.Id)), "precondition: no city there");
- Assert.IsNull(root.HoverCity(sea), "no city under the pointer");
+ InputSystem.QueueStateEvent(mouse, new MouseState { position = sea });
+ InputSystem.Update();
+ for (int i = 0; i < 5 && label.ClassListContains(MapLabelsPresenter.HoverClass); i++) { EditorApplication.QueuePlayerLoopUpdate(); yield return null; }
Assert.IsFalse(label.ClassListContains(MapLabelsPresenter.HoverClass), "Tel Aviv's pill is out");
Assert.IsTrue(pointer.HandleClick(sea));
Assert.AreNotEqual(DisplayStyle.Flex, host.style.display.value, "precondition: the panel shows the sea, no city");
@@ -577,7 +586,9 @@ public class GameSceneTests
var off = points.Where(p => Land(CameraPixel(p)) is (int q, int r) && (q, r) != (tlv.Q, tlv.R)).Cast<Vector2?>().FirstOrDefault();
Assert.IsNotNull(off, $"precondition: some point of the pill {pill} lies over another hex than Tel Aviv's");
var onPill = ScreenFor(off!.Value);
- Assert.AreEqual("tel_aviv", root.HoverCity(onPill), "the pointer over Tel Aviv's pill");
+ InputSystem.QueueStateEvent(mouse, new MouseState { position = onPill });
+ InputSystem.Update();
+ for (int i = 0; i < 5 && !label.ClassListContains(MapLabelsPresenter.HoverClass); i++) { EditorApplication.QueuePlayerLoopUpdate(); yield return null; }
Assert.IsTrue(label.ClassListContains(MapLabelsPresenter.HoverClass), "lights the pill");
Assert.IsTrue(pointer.HandleClick(onPill), "the pill takes the click");
Assert.AreEqual("Tel Aviv", ui.Q<Label>("info-title").text);
@@ -585,6 +596,7 @@ public class GameSceneTests
}
finally
{
+ if (mouse.added) InputSystem.RemoveDevice(mouse);
cam.targetTexture = null;
EditorSceneManager.NewScene(NewSceneSetup.EmptyScene, NewSceneMode.Single);
if (ps != null) Object.DestroyImmediate(ps);
@@ -593,6 +605,40 @@ public class GameSceneTests
}
}
+ [Test]
+ public void ABridgeChangeRunsGameRootsCollectionRedraw()
+ {
+ var saved = SpecialBuildingModels.Request;
+ SpecialBuildingModels.Request = TalModelsShots.Answer(Array.Empty<string>());
+ try
+ {
+ // Arms workshops are drawn under gdd-0.3 only (SpecialBuildingModels.ArmsWorkshops), so the game runs gdd-0.3, on a
+ // fresh copy of the inputs (the cached Inputs stay gdd-0.1 for the other tests), as ArmsWorkshopVisibilityTests does.
+ var inputs = GameInputs.FromDisk(Paths.Content, Paths.StreamingMap);
+ foreach (var era in inputs.Content.Eras) { era.Systems.Ruleset = SaveGame.Gdd03Ruleset; era.Systems.Loop = EraSystems.Gdd; }
+ EditorSceneManager.OpenScene("Assets/Map.unity", OpenSceneMode.Single);
+ var map = Object.FindFirstObjectByType<MapScene>();
+ map.Build(inputs.Map);
+ // The layer answers its models through SpecialBuildingModels.Request (stubbed above) at once, as the collection tests'
+ // layer does; GameRoot's ShowAt keeps a layer that is already configured, so the redraw below is still GameRoot's.
+ CollectionGeometryFixture.Special(map, inputs.Content.Rules.Start);
+ var root = Object.FindFirstObjectByType<GameRoot>();
+ root.Store = new SaveStore(saveDir);
+ root.Begin(inputs, 0);
+ Assert.AreEqual(SaveGame.Gdd03Ruleset, root.Bridge!.Content.Ruleset, "precondition: the gdd-0.3 game, which draws arms workshops");
+ var state = root.Bridge!.State;
+ var city = root.Bridge.Content.SettlementHexes.Single(x => x.Id == "tel_aviv");
+ int id = state.NextId++;
+ state.CityProjects.Add(id, new CityProject(
+ id, Workshops.ArmsWorkshop, city.Id, city.Q, city.R, 0, state.Date));
+ root.Bridge.Skip(state.Units.Keys.First());
+ var layer = Object.FindFirstObjectByType<MapScene>().Terrain.transform.Find(SpecialBuildingModels.Name);
+ Assert.IsNotNull(layer?.Find(SpecialBuildingModels.WorkshopKey(id)),
+ "the real Changed hookup redraws a newly built workshop");
+ }
+ finally { SpecialBuildingModels.Request = saved; }
+ }
+
// One label each presenter writes on every change: HUD, toast, info panel, Why, Budget, Defence, Cabinet, event card
// (the card writes its title while an event is open, so the test opens one first).
static readonly string[] Watched = { "year", "toast", "info-title", "why-turn", "budget-money", "mob-level", "cabinet-coalition", "event-title" };
diff --git a/unity/Assets/Tests/EditMode/HexPropModelsTests.cs b/unity/Assets/Tests/EditMode/HexPropModelsTests.cs
index b5d54e4d3..0f16e11db 100644
--- a/unity/Assets/Tests/EditMode/HexPropModelsTests.cs
+++ b/unity/Assets/Tests/EditMode/HexPropModelsTests.cs
@@ -823,10 +823,10 @@ namespace Statecraft.Game.Tests
Assert.AreEqual(0, moved, "no prop moves when another model is missing or the answers come in another order");
}
- /// <summary>Review of #2266 at f9802bed6, C2: a camera that asks for the props while rendering does not get its answer
- /// built inside the render, even when the answer comes at once: the request waits for LateUpdate.</summary>
+ /// <summary>Review of #2266 at f9802bed6, C2: the ChooseCore render-mode branch does not build an immediate answer;
+ /// the request waits for LateUpdate.</summary>
[Test]
- public void NothingIsBuiltInsideACameraRender()
+ public void RenderModeDefersHexPropsUntilLateUpdate()
{
var map = OpenMap();
HexPropModels.Request = (id, done) => done(AssetDatabase.LoadAssetAtPath<GameObject>(HexProps.PrefabPath(id))); // answers at once
diff --git a/unity/Assets/Tests/EditMode/KitTests.cs b/unity/Assets/Tests/EditMode/KitTests.cs
index 70a758a45..d9a814da3 100644
--- a/unity/Assets/Tests/EditMode/KitTests.cs
+++ b/unity/Assets/Tests/EditMode/KitTests.cs
@@ -849,11 +849,10 @@ public class KitTests
}
}
- /// <summary>A real render callback in edit mode (a Scene or Game view camera) never instantiates or destroys the khaki tent
- /// models mid-render: coming close or leaving only marks the camp, and the models come and go at the next LateUpdate
- /// (AdvanceCameraFrame), as in play mode.</summary>
+ /// <summary>The render-mode branch never instantiates or destroys the khaki tent models mid-render: coming close or leaving
+ /// only marks the camp, and AdvanceCameraFrame applies the change afterward.</summary>
[Test]
- public void AnEditModeRenderCallbackDefersTheTentModelsToLateUpdate()
+ public void RenderModeDefersTentModelsUntilAdvanceCameraFrame()
{
var saved = Statecraft.Game.Map.Collection.CampTentModels.Acquire;
var root = new GameObject("deferred tent fixture");
diff --git a/unity/Assets/Tests/EditMode/OutcomeClipTests.cs b/unity/Assets/Tests/EditMode/OutcomeClipTests.cs
index d86e907cf..a2a728c49 100644
--- a/unity/Assets/Tests/EditMode/OutcomeClipTests.cs
+++ b/unity/Assets/Tests/EditMode/OutcomeClipTests.cs
@@ -7,9 +7,12 @@ using System.Linq;
using System.Reflection;
using NUnit.Framework;
using Statecraft.Game;
+using Statecraft.Game.Boot;
+using Statecraft.Game.Map;
using Statecraft.Game.UI;
using Statecraft.Sim;
using UnityEditor;
+using UnityEditor.SceneManagement;
using UnityEngine;
using UnityEngine.TestTools;
using UnityEngine.UIElements;
@@ -260,8 +263,8 @@ public class OutcomeClipTests
}
}
- /// <summary>The outcome code subscribes to TurnEnded before the autosave (as in GameRoot). A throw anywhere in it is
- /// caught there, so the turn is still saved.</summary>
+ /// <summary>GameRoot subscribes the outcome handler before autosave. SimBridge independently isolates TurnEnded handlers,
+ /// so this observes production order and final saving without attributing autosave survival only to the outcome catch.</summary>
[Test]
public void AThrowInTheOutcomeCodeNeverSkipsTheAutosave()
{
@@ -269,18 +272,35 @@ public class OutcomeClipTests
try
{
var store = new SaveStore(dir);
- using var r = new Rig(new[] { "maabarot_policy" });
- using var save = GameStart.Autosave(r.Bridge, store, Text);
- r.Outcomes.BeforeTurn = () => throw new InvalidOperationException("outcome failure");
- r.Order("maabarot_policy", "maabarot");
+ Assert.IsFalse(CardVideo.ForcedOff(), "precondition: GameRoot constructs outcomes");
+ EditorSceneManager.OpenScene("Assets/Map.unity", OpenSceneMode.Single);
+ var inputs = GameInputs.FromDisk(Paths.Content, Paths.StreamingMap);
+ Object.FindFirstObjectByType<MapScene>().Build(inputs.Map);
+ var game = Object.FindFirstObjectByType<GameRoot>();
+ game.Store = store;
+ game.Begin(inputs, 0);
+ var outcomes = (OutcomePresenter?)typeof(GameRoot)
+ .GetField("outcomes", BindingFlags.Instance | BindingFlags.NonPublic)!.GetValue(game);
+ Assert.IsNotNull(outcomes, "production OutcomePresenter was constructed");
+ Assert.IsFalse(File.Exists(store.AutosavePath), "precondition: no turn has been saved");
+ bool savedBeforeOutcome = false;
+ outcomes!.BeforeTurn = () =>
+ {
+ savedBeforeOutcome = File.Exists(store.AutosavePath);
+ throw new InvalidOperationException("outcome failure");
+ };
LogAssert.Expect(LogType.Exception, new System.Text.RegularExpressions.Regex("outcome failure"));
- r.Bridge.EndTurn();
+ game.Bridge!.EndTurn();
+ Assert.IsFalse(savedBeforeOutcome, "GameRoot subscribes the outcome before autosave");
Assert.IsTrue(File.Exists(store.AutosavePath), "the turn was saved");
Assert.IsNotEmpty(File.ReadAllText(store.AutosavePath));
- Assert.IsNull(r.Outcomes.Showing);
- Assert.IsFalse(r.Open, "nothing is left half open");
+ Assert.IsNull(outcomes.Showing);
+ }
+ finally
+ {
+ EditorSceneManager.NewScene(NewSceneSetup.EmptyScene, NewSceneMode.Single);
+ if (Directory.Exists(dir)) Directory.Delete(dir, true);
}
- finally { if (Directory.Exists(dir)) Directory.Delete(dir, true); }
}
/// <summary>The build gate reads the outcome clips from the mapping (Build.GatedClips, used by RefuseUnlessShareable):
diff --git a/unity/Assets/Tests/EditMode/SettingsScreenTests.cs b/unity/Assets/Tests/EditMode/SettingsScreenTests.cs
index ce8c9e691..b335cd4f7 100644
--- a/unity/Assets/Tests/EditMode/SettingsScreenTests.cs
+++ b/unity/Assets/Tests/EditMode/SettingsScreenTests.cs
@@ -543,11 +543,11 @@ public class SettingsScreenTests
finally { ExternalLink.Opener = ExternalLink.Default; }
}
- /// <summary>#1169: with the screens' navigation wired as GameRoot wires it, Esc in the report panel closes the panel
+ /// <summary>#1169: with the unit fixture's injected ScreenNav hook, Esc in the report panel closes the panel
/// only; ScreenNav's Cancel handler trickles down from the root before the panel's own and asks the panel first.
/// (Time.frameCount does not move in an edit-mode test, so after this the panel keeps saying "used this frame".)</summary>
[Test]
- public void EscapeInTheReportPanelLeavesTheSettingsScreenOpen()
+ public void AnInjectedScreenNavHookLeavesSettingsUnderTheReportPanelOpen()
{
using var ui = new UiTestKit();
using var nav = new ScreenNav(ui.Root);
diff --git a/unity/Assets/Tests/EditMode/ShareShotTests.cs b/unity/Assets/Tests/EditMode/ShareShotTests.cs
index 8235edd69..3374c0a2e 100644
--- a/unity/Assets/Tests/EditMode/ShareShotTests.cs
+++ b/unity/Assets/Tests/EditMode/ShareShotTests.cs
@@ -282,10 +282,10 @@ public class ShareShotTests
finally { ShareShot.Keep = ShareShot.DefaultKeep; }
}
- /// <summary>With the screens' navigation wired as GameRoot wires it, Esc in the share panel closes the panel only:
+ /// <summary>With the unit fixture's injected ScreenNav hook, Esc in the share panel closes the panel only:
/// ScreenNav's Cancel handler trickles down from the root before the panel's own and asks the panel first.</summary>
[Test]
- public void EscapeInTheSharePanelLeavesTheSettingsScreenOpen()
+ public void AnInjectedScreenNavHookLeavesSettingsUnderTheSharePanelOpen()
{
ShareShot.Keep = (png, name) => { };
try
diff --git a/unity/Assets/Tests/EditMode/SpecialBuildingModelsTests.cs b/unity/Assets/Tests/EditMode/SpecialBuildingModelsTests.cs
index 9aefc21cb..1dfe3fa5f 100644
--- a/unity/Assets/Tests/EditMode/SpecialBuildingModelsTests.cs
+++ b/unity/Assets/Tests/EditMode/SpecialBuildingModelsTests.cs
@@ -881,13 +881,13 @@ namespace Statecraft.Game.Tests
finally { CivilianPeople.Request = savedPeople; RuralLife.Request = savedRural; }
}
- /// <summary>The layer never rebuilds per frame, only on an event (53 on #2274: "never per frame"). Shown as GameRoot's
- /// RenderPlacementsIfChanged shows it (the civilians, the farm scenes, then the specials), three frames with the same
+ /// <summary>The layer never rebuilds per frame, only on an event (53 on #2274: "never per frame"). The unit fixture calls
+ /// the three collection helpers in production order, then three frames with the same
/// inputs and the layers' per-frame LateUpdate keep every drawn model and ask for nothing. Then an event, a change of the
/// farm scenes' plan while the well (which keeps off the farm scenes) stands, rebuilds it: the old fort is destroyed,
/// which shows the frames' identity check can see a rebuild.</summary>
[Test]
- public void NoRebuildAcrossFramesWithoutAnEventOneOnARuralPlanChange()
+ public void CollectionHelpersDoNotRebuildWithoutAnInputChange()
{
var map = OpenMap();
var c = Statecraft.Sim.ContentLoader.Load(Statecraft.Game.Paths.Content);
diff --git a/unity/Assets/Tests/EditMode/StartScreenTests.cs b/unity/Assets/Tests/EditMode/StartScreenTests.cs
index d11ce1175..83b65ff31 100644
--- a/unity/Assets/Tests/EditMode/StartScreenTests.cs
+++ b/unity/Assets/Tests/EditMode/StartScreenTests.cs
@@ -451,60 +451,58 @@ public class StartScreenTests
/// <summary>#400: a turn-1 save keeps the build buttons disabled anyway, so the test above cannot see them. With a save
/// from after August 1950, a selected hex and an event waiting, the build buttons and the event's options are live, and
/// still none of them takes the focus under the start screen.
- /// Built in GameRoot's order: the HUD, ScreenNav, the info panel and the event card, then the screen.</summary>
+ /// Booted through GameRoot.Begin: the HUD, ScreenNav, the info panel and the event card, then the screen.</summary>
[UnityTest]
- public IEnumerator ASaveFrom1950KeepsTheLiveHudOutOfReach()
+ public IEnumerator AContinuedGameBootKeepsTheLiveHudOutOfReach()
{
- var legacy = SimBridgeGddTests.Legacy; // the live Build buttons are the legacy loop's (R-PROJ-004)
- var g = GameSession.New(legacy, 9, Mode.Historical);
- while (g.State.Date < new DateTime(1950, 8, 1) || g.State.PendingEvents.Count == 0) g.Step(HistoricalAI.Commands(legacy, g.State));
+ var g = GameSession.New(Inputs.Content, 9, Mode.Historical);
+ while (g.State.Date < new DateTime(1950, 8, 1) || g.State.PendingEvents.Count == 0)
+ g.Step(HistoricalAI.Commands(Inputs.Content, g.State));
var store = TempStore();
store.WriteAutosave(g.Save.Write());
- using var ui = new RenderedUi();
- var bridge = new SimBridge(GameStart.Begin(legacy, store, () => 4UL, new List<string>(), Text, out var resumed), Text);
- var owned = new List<IDisposable>();
- try
+ var root = OpenScene(store);
+ root.Begin(Inputs, 0, startScreen: true);
+ var ui = Ui;
+ var offers = (from hex in Inputs.Content.Hexes
+ where hex.Land
+ where !Inputs.Content.SettlementHexes.Any(x => x.Q == hex.Q && x.R == hex.R
+ && root.Bridge!.State.Cities.ContainsKey(x.Id))
+ from city in Projects.CitiesFor(Inputs.Content, root.Bridge!.State, hex.Q, hex.R)
+ from kind in Inputs.Content.ProjectKinds
+ where Projects.CheckCityReason(Inputs.Content, root.Bridge!.State, kind.Id, city, hex.Q, hex.R) == null
+ select (hex, kind)).ToList();
+ Assert.IsNotEmpty(offers, "precondition: the continued current-ruleset state has a build action");
+ var offer = offers[0];
+ root.Info!.Show(offer.hex.Q, offer.hex.R);
+ for (int i = 0; i < 4; i++) yield return null;
+ Assert.GreaterOrEqual(root.Bridge!.State.Date, new DateTime(1950, 8, 1), "precondition: the 1950 save is continued");
+ var build = ui.Q<Button>("city-project-" + offer.kind.Id);
+ Assert.IsNotNull(build, "precondition: the eligible current-ruleset city-project build action exists");
+ Assert.IsTrue(build.enabledSelf && build.resolvedStyle.display != DisplayStyle.None,
+ "precondition: the current-ruleset city-project build action is enabled and visible");
+ Assert.IsNotNull(ui.Q("event-options").Q<Button>(), "precondition: an event's options are shown");
+ void NoneReachable(string where)
{
- ui.Root.Q("root").RemoveFromClassList("loading");
- owned.Add(new HudPresenter(ui.Root, bridge, Text));
- owned.Add(new ScreenNav(ui.Root));
- var info = new InfoPanelPresenter(ui.Root, bridge, Text, legacy.SettlementHexes.ToDictionary(x => x.Id, x => x.Id)); owned.Add(info);
- var card = new EventCardPresenter(ui.Root, bridge, Text, null); owned.Add(card);
- var toast = new ToastPresenter(ui.Root, bridge, Text); owned.Add(toast);
- var newGame = new NewGamePresenter(ui.Root, bridge, store, toast, Text, () => 5UL); owned.Add(newGame);
- var tlv = legacy.SettlementHexes.Single(x => x.Id == "tel_aviv");
- info.Show(tlv.Q, tlv.R);
- var start = new StartScreenPresenter(ui.Root, newGame, resumed); owned.Add(start);
- start.Show();
- for (int i = 0; i < 4; i++) yield return null;
- Assert.IsTrue(resumed, "precondition: the 1950 save is continued");
- var build = ui.Q<Button>("build-camp");
- Assert.IsTrue(build.enabledSelf && build.style.display.value == DisplayStyle.Flex, "precondition: build-camp is live: " + ui.Q<Label>("info-reason").text);
- Assert.IsNotNull(ui.Root.Q("event-options").Q<Button>(), "precondition: an event's options are shown");
- void NoneReachable(string where)
- {
- foreach (var region in new[] { "top-bar", "right-column", "info-panel", "event-layer" })
- foreach (var b in ui.Root.Q(region).Query<Button>().ToList())
- {
- Assert.IsFalse(b.canGrabFocus, $"{where}: {region} {b.name} cannot take the focus under the start screen");
- b.Focus();
- Assert.AreNotSame(b, ui.Root.focusController?.focusedElement, $"{where}: {region} {b.name} is not focused");
- }
- }
- NoneReachable("under the start screen");
- ui.Press("start-continue");
- yield return null; yield return null;
- // The waiting event's card opens in the middle (decision cards) and takes the focus (review S1); its options are
- // in reach, the panels under its backdrop are not; Hide gives them back.
- yield return null;
- Assert.AreSame(ui.Root.Q("event-card"), ui.Root.panel.focusController.focusedElement, "the event card has the focus once the screen closes");
- Assert.IsTrue(ui.Root.Q("event-options").Q<Button>().canGrabFocus, "the event's options are in reach once the screen closes");
- Assert.IsFalse(build.canGrabFocus, "the info panel waits under the decision card's backdrop");
- card.Collapse();
- yield return null;
- Assert.IsTrue(build.canGrabFocus, "the build button is back once the card is hidden");
+ foreach (var region in new[] { "top-bar", "right-column", "info-panel", "event-layer" })
+ foreach (var b in ui.Q(region).Query<Button>().ToList())
+ {
+ Assert.IsFalse(b.canGrabFocus, $"{where}: {region} {b.name} cannot take the focus under the start screen");
+ b.Focus();
+ Assert.AreNotSame(b, ui.focusController?.focusedElement, $"{where}: {region} {b.name} is not focused");
+ }
}
- finally { for (int i = owned.Count - 1; i >= 0; i--) owned[i].Dispose(); }
+ NoneReachable("under the start screen");
+ UiTestKit.Press(ui.Q<Button>("start-continue"));
+ yield return null; yield return null;
+ // The waiting event's card opens in the middle (decision cards) and takes the focus (review S1); its options are
+ // in reach, the panels under its backdrop are not; Hide gives them back.
+ yield return null;
+ Assert.AreSame(ui.Q("event-card"), ui.panel.focusController.focusedElement, "the event card has the focus once the screen closes");
+ Assert.IsTrue(ui.Q("event-options").Q<Button>().canGrabFocus, "the event's options are in reach once the screen closes");
+ Assert.IsFalse(build!.canGrabFocus, "the info panel waits under the decision card's backdrop");
+ root.Card!.Collapse();
+ yield return null;
+ Assert.IsTrue(build.canGrabFocus, "the build button is back once the card is hidden");
}
// --- Layout ------------------------------------------------------------------------------------------------------