A Civilization-style strategy game about governing Israel from 15 May 1948. Real ministers, real map, every fact sourced. Unity + deterministic C# sim.
test(ui): two presses in one frame toggle the screen twice, as documented (fix round 2, R2-3)
eyalgolanc195179ad949
diff --git a/unity/Assets/Scripts/UI/ScreenNav.cs b/unity/Assets/Scripts/UI/ScreenNav.csindex c6e8df827..14436485b 100644--- a/unity/Assets/Scripts/UI/ScreenNav.cs+++ b/unity/Assets/Scripts/UI/ScreenNav.cs@@ -5,7 +5,9 @@ using UnityEngine.UIElements;namespace Statecraft.Game.UI{/// <summary>The top-bar buttons open the Cabinet, Budget, Defence and Why screens, one at a time; pressing the open- /// screen's button again closes it.</summary>+ /// screen's button again closes it. Every press toggles, synchronously, with no debounce: two presses in one frame (a+ /// double click, or a click plus Enter) open and close again, so the result depends only on the number of presses+ /// (HudTests.TwoPressesInOneFrameToggleTwice; playtest 1, item 11).</summary>public sealed class ScreenNav : System.IDisposable{public static readonly string[] Screens = { "cabinet", "budget", "defence", "why" };diff --git a/unity/Assets/Tests/EditMode/HudTests.cs b/unity/Assets/Tests/EditMode/HudTests.csindex 7bfdce8e3..e95bde8a6 100644--- a/unity/Assets/Tests/EditMode/HudTests.cs+++ b/unity/Assets/Tests/EditMode/HudTests.cs@@ -377,4 +377,28 @@ public class HudTestsAssert.AreEqual(Title(PlayerText.Target(C, "intl_standing")), Caption("meter-standing"));Assert.AreEqual(Title(PlayerText.Target(C, "fx_reserves")), Caption("meter-fx"));}++ /// <summary>Fix round 2 (R2-3, playtest 1 item 11): two Submit events on the Defence button within one frame (a+ /// double click, or a click plus Enter) each toggle the screen, as ScreenNav documents: no debounce. From closed the+ /// result is closed, from open it is open; the same input always gives the same state.</summary>+ [Test]+ public void TwoPressesInOneFrameToggleTwice()+ {+ using var ui = new UiTestKit();+ var nav = new ScreenNav(ui.Root);+ try+ {+ var defence = ui.Q<Button>("nav-defence");+ var frame = Time.frameCount;+ UiTestKit.Press(defence); UiTestKit.Press(defence);+ Assert.AreEqual(frame, Time.frameCount, "both presses in the same frame");+ Assert.IsNull(nav.Current, "closed -> open -> closed");+ Assert.AreEqual(DisplayStyle.None, ui.Q<VisualElement>("screen-defence").style.display.value);+ UiTestKit.Press(defence); // open it+ UiTestKit.Press(defence); UiTestKit.Press(defence);+ Assert.AreEqual("defence", nav.Current, "open -> closed -> open");+ Assert.AreEqual(DisplayStyle.Flex, ui.Q<VisualElement>("screen-defence").style.display.value);+ }+ finally { nav.Dispose(); }+ }}