Implement overall improvements for code stability, fallbacks and keyboard interactions
This commit is contained in:
@@ -45,6 +45,7 @@ public class TerminalUiTests
|
||||
symbol.style.right = 0;
|
||||
}
|
||||
var steps = menu.Query<Button>(className: "exchange-step-button").ToList();
|
||||
Assert.That(steps.Count, Is.EqualTo(6));
|
||||
var stepRow = new VisualElement();
|
||||
stepRow.style.flexDirection = FlexDirection.Row;
|
||||
stepRow.style.flexWrap = Wrap.Wrap;
|
||||
@@ -57,6 +58,7 @@ public class TerminalUiTests
|
||||
foreach (int state in new[] { 0, 1, 2 })
|
||||
{
|
||||
foreach (var symbol in symbols) symbol.SetEnabled(state != 2);
|
||||
foreach (var step in steps) step.SetEnabled(state != 2);
|
||||
if (state == 1) dynamicClose.Focus();
|
||||
yield return null;
|
||||
yield return null;
|
||||
@@ -72,7 +74,15 @@ public class TerminalUiTests
|
||||
Assert.That(style.whiteSpace, Is.EqualTo(WhiteSpace.NoWrap));
|
||||
}
|
||||
foreach (var step in steps)
|
||||
{
|
||||
if (state == 1)
|
||||
{
|
||||
step.Focus();
|
||||
yield return null;
|
||||
Assert.That(root.focusController.focusedElement, Is.SameAs(step));
|
||||
}
|
||||
Assert.That(step.resolvedStyle.unityTextAlign, Is.EqualTo(TextAnchor.MiddleCenter), step.text);
|
||||
}
|
||||
Assert.That(command.resolvedStyle.unityTextAlign, Is.EqualTo(TextAnchor.MiddleLeft));
|
||||
}
|
||||
LogAssert.NoUnexpectedReceived();
|
||||
@@ -154,9 +164,22 @@ public class TerminalUiTests
|
||||
|
||||
target.Focus();
|
||||
yield return null;
|
||||
yield return null;
|
||||
Assert.That(root.focusController.focusedElement, Is.SameAs(target));
|
||||
Assert.That(inner.scrollOffset.y, Is.GreaterThan(0));
|
||||
Assert.That(outer.scrollOffset.y, Is.GreaterThan(0));
|
||||
Assert.That(target.worldBound.width, Is.GreaterThan(0));
|
||||
Assert.That(target.worldBound.height, Is.GreaterThan(0));
|
||||
foreach (var scroll in new[] { inner, outer })
|
||||
{
|
||||
var viewport = scroll.contentViewport.worldBound;
|
||||
var bounds = target.worldBound;
|
||||
const float tolerance = 1f; // Allow subpixel layout rounding.
|
||||
Assert.That(bounds.xMin, Is.GreaterThanOrEqualTo(viewport.xMin - tolerance));
|
||||
Assert.That(bounds.xMax, Is.LessThanOrEqualTo(viewport.xMax + tolerance));
|
||||
Assert.That(bounds.yMin, Is.GreaterThanOrEqualTo(viewport.yMin - tolerance));
|
||||
Assert.That(bounds.yMax, Is.LessThanOrEqualTo(viewport.yMax + tolerance));
|
||||
}
|
||||
LogAssert.NoUnexpectedReceived();
|
||||
}
|
||||
finally { window.Close(); }
|
||||
@@ -178,6 +201,370 @@ public class TerminalUiTests
|
||||
}
|
||||
}
|
||||
|
||||
[UnityTest]
|
||||
public IEnumerator CollectionRefreshPreservesUnitFocusAndFallsBackWhenItDisappears()
|
||||
{
|
||||
if (SystemInfo.graphicsDeviceType == UnityEngine.Rendering.GraphicsDeviceType.Null)
|
||||
Assert.Ignore("Focus restoration tests require an editor panel; run Unity without -nographics.");
|
||||
var window = ScriptableObject.CreateInstance<TerminalFocusTestWindow>();
|
||||
try
|
||||
{
|
||||
window.position = new Rect(0, 0, 900, 700);
|
||||
window.Show();
|
||||
var root = window.rootVisualElement;
|
||||
root.styleSheets.Add(AssetDatabase.LoadAssetAtPath<StyleSheet>("Assets/UI/MainMenu.uss"));
|
||||
Runtime.GetType("KernelPanic.UI.TerminalTheme").GetMethod("Attach").Invoke(null, new object[] { root });
|
||||
root.Add(AssetDatabase.LoadAssetAtPath<VisualTreeAsset>("Assets/UI/CollectionScreen.uxml").CloneTree());
|
||||
root.Q("CollectionPanel").RemoveFromClassList("hidden");
|
||||
var outside = new Button { text = "outside collection" };
|
||||
root.Add(outside);
|
||||
var ubuntu = AssetDatabase.LoadAssetAtPath<DistroDefinition>("Assets/Data/Distros/Ubuntu.asset");
|
||||
var arch = AssetDatabase.LoadAssetAtPath<DistroDefinition>("Assets/Data/Distros/Arch.asset");
|
||||
var fedora = AssetDatabase.LoadAssetAtPath<DistroDefinition>("Assets/Data/Distros/Fedora.asset");
|
||||
var owned = new PlayerCollection();
|
||||
foreach (var unit in new[] { ubuntu, arch, fedora }) owned.Add(unit);
|
||||
var screen = new CollectionScreenController();
|
||||
screen.Bind(root, null, null, null, owned);
|
||||
screen.RefreshUnits(new[] { ubuntu, arch, fedora });
|
||||
yield return null;
|
||||
yield return null;
|
||||
|
||||
var original = root.Q<Button>($"CollectionUnit_{arch.Id}");
|
||||
Assert.That(original, Is.Not.Null);
|
||||
original.Focus();
|
||||
Assert.That(root.focusController.focusedElement, Is.SameAs(original));
|
||||
// Move the focused unit to a different index and change its displayed version.
|
||||
owned.Add(arch);
|
||||
screen.RefreshUnits(new[] { fedora, ubuntu, arch });
|
||||
yield return null;
|
||||
yield return null;
|
||||
var replacement = root.Q<Button>($"CollectionUnit_{arch.Id}");
|
||||
Assert.That(replacement, Is.Not.SameAs(original));
|
||||
Assert.That(root.focusController.focusedElement, Is.SameAs(replacement));
|
||||
Assert.That(replacement.ClassListContains("selected"), Is.True);
|
||||
|
||||
// Both rebuilds happen before either scheduled restoration can execute.
|
||||
screen.RefreshUnits(new[] { arch, ubuntu });
|
||||
var intermediate = root.Q<Button>($"CollectionUnit_{arch.Id}");
|
||||
screen.RefreshUnits(new[] { fedora, ubuntu, arch });
|
||||
yield return null;
|
||||
yield return null;
|
||||
var finalRow = root.Q<Button>($"CollectionUnit_{arch.Id}");
|
||||
Assert.That(finalRow, Is.Not.SameAs(intermediate));
|
||||
Assert.That(intermediate.panel, Is.Null);
|
||||
Assert.That(root.focusController.focusedElement, Is.SameAs(finalRow), "Consecutive refreshes restore into the final list.");
|
||||
|
||||
screen.RefreshUnits(new[] { fedora, ubuntu });
|
||||
yield return null;
|
||||
yield return null;
|
||||
var fallback = root.Q<Button>($"CollectionUnit_{fedora.Id}");
|
||||
Assert.That(root.focusController.focusedElement, Is.SameAs(fallback), "A removed unit falls back to the first available row.");
|
||||
Assert.That(fallback.ClassListContains("selected"), Is.True);
|
||||
|
||||
screen.RefreshUnits(Array.Empty<DistroDefinition>());
|
||||
yield return null;
|
||||
yield return null;
|
||||
Assert.That(root.focusController.focusedElement,
|
||||
Is.SameAs(root.Q<ScrollView>("CollectionDetail").contentContainer), "An empty list retains focus in its content region.");
|
||||
Assert.That(root.Q("CollectionEmptyTitle"), Is.Not.Null);
|
||||
|
||||
outside.Focus();
|
||||
screen.RefreshUnits(new[] { ubuntu, arch });
|
||||
yield return null;
|
||||
yield return null;
|
||||
Assert.That(root.focusController.focusedElement, Is.SameAs(outside), "Refreshing an unfocused collection must not steal focus.");
|
||||
|
||||
root.Q<Button>($"CollectionUnit_{arch.Id}").Focus();
|
||||
screen.RefreshUnits(new[] { ubuntu, arch });
|
||||
outside.Focus();
|
||||
Assert.That(root.focusController.focusedElement, Is.SameAs(outside));
|
||||
yield return null;
|
||||
yield return null;
|
||||
Assert.That(root.focusController.focusedElement, Is.SameAs(outside), "A newer focus choice wins over a pending restoration.");
|
||||
LogAssert.NoUnexpectedReceived();
|
||||
}
|
||||
finally { window.Close(); }
|
||||
}
|
||||
|
||||
[UnityTest]
|
||||
public IEnumerator FocusRestorationSkipsUnavailableMatchesAndFallbacks()
|
||||
{
|
||||
if (SystemInfo.graphicsDeviceType == UnityEngine.Rendering.GraphicsDeviceType.Null)
|
||||
Assert.Ignore("Focus restoration tests require an editor panel; run Unity without -nographics.");
|
||||
var window = ScriptableObject.CreateInstance<TerminalFocusTestWindow>();
|
||||
try
|
||||
{
|
||||
window.Show();
|
||||
var root = window.rootVisualElement;
|
||||
var region = new VisualElement();
|
||||
root.Add(region);
|
||||
var preserve = Runtime.GetType("KernelPanic.UI.TerminalTheme").GetMethod("PreserveFocus");
|
||||
foreach (string state in new[] { "disabled", "hidden", "invisible", "unfocusable", "disabled ancestor", "hidden ancestor" })
|
||||
{
|
||||
region.Clear();
|
||||
var original = new Button { name = "selected-item", text = "inspect" };
|
||||
region.Add(original);
|
||||
yield return null;
|
||||
yield return null;
|
||||
original.Focus();
|
||||
Assert.That(root.focusController.focusedElement, Is.SameAs(original), state);
|
||||
preserve.Invoke(null, new object[] { region });
|
||||
region.Clear();
|
||||
|
||||
var unavailable = new VisualElement();
|
||||
region.Add(unavailable);
|
||||
var byName = new Button { name = "selected-item", text = "updated inspect" };
|
||||
var byText = new Button { text = "inspect" };
|
||||
var firstFallback = new Button { text = "unavailable fallback" };
|
||||
foreach (var button in new[] { byName, byText, firstFallback })
|
||||
{
|
||||
unavailable.Add(button);
|
||||
switch (state)
|
||||
{
|
||||
case "disabled": button.SetEnabled(false); break;
|
||||
case "hidden": button.style.display = DisplayStyle.None; break;
|
||||
case "invisible": button.style.visibility = Visibility.Hidden; break;
|
||||
case "unfocusable": button.focusable = false; break;
|
||||
}
|
||||
}
|
||||
if (state == "disabled ancestor") unavailable.SetEnabled(false);
|
||||
if (state == "hidden ancestor") unavailable.style.display = DisplayStyle.None;
|
||||
var fallback = new Button { text = "available fallback" };
|
||||
region.Add(fallback);
|
||||
yield return null;
|
||||
yield return null;
|
||||
Assert.That(root.focusController.focusedElement, Is.SameAs(fallback), state);
|
||||
}
|
||||
LogAssert.NoUnexpectedReceived();
|
||||
}
|
||||
finally { window.Close(); }
|
||||
}
|
||||
|
||||
[UnityTest]
|
||||
public IEnumerator ModalNavigationWrapsAndSkipsUnavailableControls()
|
||||
{
|
||||
if (SystemInfo.graphicsDeviceType == UnityEngine.Rendering.GraphicsDeviceType.Null)
|
||||
Assert.Ignore("Modal navigation tests require an editor panel; run Unity without -nographics.");
|
||||
var window = ScriptableObject.CreateInstance<TerminalFocusTestWindow>();
|
||||
try
|
||||
{
|
||||
window.Show();
|
||||
var root = window.rootVisualElement;
|
||||
root.Add(new Button { text = "behind modal" });
|
||||
var overlay = new VisualElement();
|
||||
root.Add(overlay);
|
||||
Runtime.GetType("KernelPanic.UI.TerminalTheme").GetMethod("ConstrainModalFocus")
|
||||
.Invoke(null, new object[] { overlay });
|
||||
var first = new Button { text = "first" };
|
||||
overlay.Add(first);
|
||||
var disabled = new Button { text = "disabled" };
|
||||
disabled.SetEnabled(false);
|
||||
overlay.Add(disabled);
|
||||
var hidden = new Button { text = "hidden" };
|
||||
hidden.style.display = DisplayStyle.None;
|
||||
overlay.Add(hidden);
|
||||
var hiddenParent = new VisualElement();
|
||||
hiddenParent.style.display = DisplayStyle.None;
|
||||
hiddenParent.Add(new Button { text = "hidden by parent" });
|
||||
overlay.Add(hiddenParent);
|
||||
var disabledParent = new VisualElement();
|
||||
disabledParent.SetEnabled(false);
|
||||
disabledParent.Add(new Button { text = "disabled by parent" });
|
||||
overlay.Add(disabledParent);
|
||||
overlay.Add(new Button { text = "excluded from tab order", tabIndex = -1 });
|
||||
var input = new TextField();
|
||||
overlay.Add(input);
|
||||
var last = new Toggle("last");
|
||||
overlay.Add(last);
|
||||
int escapedEvents = 0;
|
||||
root.RegisterCallback<NavigationMoveEvent>(_ => escapedEvents++);
|
||||
yield return null;
|
||||
yield return null;
|
||||
|
||||
void Move(NavigationMoveEvent.Direction direction, VisualElement expected)
|
||||
{
|
||||
var focused = root.focusController.focusedElement as VisualElement;
|
||||
Assert.That(focused, Is.Not.Null);
|
||||
using var evt = NavigationMoveEvent.GetPooled(direction);
|
||||
evt.target = focused;
|
||||
focused.SendEvent(evt);
|
||||
var actual = root.focusController.focusedElement as VisualElement;
|
||||
Assert.That(actual == expected || expected.Contains(actual), Is.True, direction.ToString());
|
||||
Assert.That(escapedEvents, Is.Zero, "Modal navigation must not also reach the background screen.");
|
||||
}
|
||||
|
||||
first.Focus();
|
||||
Move(NavigationMoveEvent.Direction.Previous, last);
|
||||
Move(NavigationMoveEvent.Direction.Next, first);
|
||||
Move(NavigationMoveEvent.Direction.Next, input);
|
||||
Move(NavigationMoveEvent.Direction.Next, last);
|
||||
Move(NavigationMoveEvent.Direction.Previous, input);
|
||||
Move(NavigationMoveEvent.Direction.Previous, first);
|
||||
|
||||
// Update eligibility while the modal is open, leaving a single tab stop.
|
||||
input.SetEnabled(false);
|
||||
last.style.display = DisplayStyle.None;
|
||||
yield return null;
|
||||
yield return null;
|
||||
Move(NavigationMoveEvent.Direction.Next, first);
|
||||
Move(NavigationMoveEvent.Direction.Previous, first);
|
||||
LogAssert.NoUnexpectedReceived();
|
||||
}
|
||||
finally { window.Close(); }
|
||||
}
|
||||
|
||||
[UnityTest]
|
||||
public IEnumerator PullHistoryCloseRestoresOpenerOrAvailableFallback()
|
||||
{
|
||||
if (SystemInfo.graphicsDeviceType == UnityEngine.Rendering.GraphicsDeviceType.Null)
|
||||
Assert.Ignore("Modal focus tests require an editor panel; run Unity without -nographics.");
|
||||
var window = ScriptableObject.CreateInstance<TerminalFocusTestWindow>();
|
||||
try
|
||||
{
|
||||
window.position = new Rect(0, 0, 900, 700);
|
||||
window.Show();
|
||||
var root = window.rootVisualElement;
|
||||
root.styleSheets.Add(AssetDatabase.LoadAssetAtPath<StyleSheet>("Assets/UI/MainMenu.uss"));
|
||||
Runtime.GetType("KernelPanic.UI.TerminalTheme").GetMethod("Attach").Invoke(null, new object[] { root });
|
||||
root.Add(AssetDatabase.LoadAssetAtPath<VisualTreeAsset>("Assets/UI/GachaScreen.uxml").CloneTree());
|
||||
root.Q("GachaPanel").RemoveFromClassList("hidden");
|
||||
var screen = new GachaScreenController();
|
||||
screen.Bind(root, null, null, null, new GachaService(), new PlayerCollection(), new EntropyWallet(),
|
||||
null, null, () => { }, () => { }, null);
|
||||
screen.Open();
|
||||
var toolbar = root.Q<Button>("GachaPullHistoryButton");
|
||||
yield return null;
|
||||
yield return null;
|
||||
|
||||
foreach (string state in new[] { "available", "removed", "disabled", "hidden", "toolbar removed" })
|
||||
{
|
||||
var opener = state == "toolbar removed" ? toolbar : new Button { text = "open history" };
|
||||
if (opener != toolbar) root.Add(opener);
|
||||
yield return null;
|
||||
opener.Focus();
|
||||
Assert.That(root.focusController.focusedElement, Is.SameAs(opener), state);
|
||||
screen.OpenPullHistory();
|
||||
yield return null;
|
||||
yield return null;
|
||||
var overlay = root.Q("GachaPullHistoryOverlay");
|
||||
var close = overlay.Q<Button>("ClosePullHistory");
|
||||
Assert.That(root.focusController.focusedElement, Is.SameAs(close), "Opening history focuses its close control.");
|
||||
if (state == "removed" || state == "toolbar removed") opener.RemoveFromHierarchy();
|
||||
if (state == "disabled") opener.SetEnabled(false);
|
||||
if (state == "hidden") opener.style.display = DisplayStyle.None;
|
||||
|
||||
if (state == "available" || state == "disabled")
|
||||
{
|
||||
using var submit = NavigationSubmitEvent.GetPooled();
|
||||
submit.target = close;
|
||||
close.SendEvent(submit);
|
||||
}
|
||||
else
|
||||
{
|
||||
using var escape = KeyDownEvent.GetPooled('\0', KeyCode.Escape, EventModifiers.None);
|
||||
escape.target = close;
|
||||
close.SendEvent(escape);
|
||||
}
|
||||
VisualElement expected = state == "available" ? opener : state == "toolbar removed"
|
||||
? root.Q("GachaBannerList").Q<Button>(className: "selected") : toolbar;
|
||||
Assert.That(overlay.ClassListContains("hidden"), Is.True, state);
|
||||
Assert.That(overlay.ClassListContains("modal-open"), Is.False, state);
|
||||
yield return null;
|
||||
yield return null;
|
||||
Assert.That(root.focusController.focusedElement, Is.SameAs(expected), state);
|
||||
opener.RemoveFromHierarchy();
|
||||
}
|
||||
LogAssert.NoUnexpectedReceived();
|
||||
}
|
||||
finally { window.Close(); }
|
||||
}
|
||||
|
||||
[UnityTest]
|
||||
public IEnumerator FiveStarSelectorCloseRestoresOpenerOrAvailableFallback()
|
||||
{
|
||||
if (SystemInfo.graphicsDeviceType == UnityEngine.Rendering.GraphicsDeviceType.Null)
|
||||
Assert.Ignore("Modal focus tests require an editor panel; run Unity without -nographics.");
|
||||
var window = ScriptableObject.CreateInstance<TerminalFocusTestWindow>();
|
||||
try
|
||||
{
|
||||
window.position = new Rect(0, 0, 900, 700);
|
||||
window.Show();
|
||||
var root = window.rootVisualElement;
|
||||
root.styleSheets.Add(AssetDatabase.LoadAssetAtPath<StyleSheet>("Assets/UI/MainMenu.uss"));
|
||||
Runtime.GetType("KernelPanic.UI.TerminalTheme").GetMethod("Attach").Invoke(null, new object[] { root });
|
||||
root.Add(AssetDatabase.LoadAssetAtPath<VisualTreeAsset>("Assets/UI/GachaScreen.uxml").CloneTree());
|
||||
root.Q("GachaPanel").RemoveFromClassList("hidden");
|
||||
var service = new GachaService();
|
||||
var save = SaveData.CreateDefault();
|
||||
save.beginnerBannerState.totalPulls = GachaService.BeginnerMaxPulls;
|
||||
save.standardBannerState.totalPulls = GachaService.StandardFiveStarSelectorInterval;
|
||||
service.LoadProgress(save);
|
||||
var screen = new GachaScreenController();
|
||||
screen.Bind(root, null, null, null, service, new PlayerCollection(), new EntropyWallet(),
|
||||
null, null, () => { }, () => { }, null);
|
||||
screen.Open();
|
||||
var toolbar = root.Q<Button>("GachaPullHistoryButton");
|
||||
var detail = root.Q("GachaBannerDetail");
|
||||
|
||||
foreach (string state in new[] { "available", "removed", "disabled", "hidden", "hidden ancestor", "rebuilt", "toolbar unavailable" })
|
||||
{
|
||||
detail.style.display = StyleKeyword.Null;
|
||||
screen.Refresh();
|
||||
yield return null;
|
||||
yield return null;
|
||||
var opener = detail.Query<Button>().Where(button => button.text.StartsWith("claim 5")).First();
|
||||
Assert.That(opener, Is.Not.Null, "A pending selector exposes its actual claim button.");
|
||||
opener.Focus();
|
||||
Assert.That(root.focusController.focusedElement, Is.SameAs(opener), state);
|
||||
using (var submit = NavigationSubmitEvent.GetPooled())
|
||||
{
|
||||
submit.target = opener;
|
||||
opener.SendEvent(submit);
|
||||
}
|
||||
yield return null;
|
||||
yield return null;
|
||||
var overlay = root.Q(className: "five-star-selector-overlay");
|
||||
Assert.That(overlay, Is.Not.Null);
|
||||
var close = overlay.Q<Button>(className: "modal-close-button");
|
||||
Assert.That(root.focusController.focusedElement, Is.SameAs(close), state);
|
||||
|
||||
if (state == "removed" || state == "toolbar unavailable") opener.RemoveFromHierarchy();
|
||||
if (state == "disabled") opener.SetEnabled(false);
|
||||
if (state == "hidden") opener.style.display = DisplayStyle.None;
|
||||
if (state == "hidden ancestor") detail.style.display = DisplayStyle.None;
|
||||
if (state == "rebuilt")
|
||||
{
|
||||
screen.Refresh();
|
||||
Assert.That(opener.panel, Is.Null, "Refreshing replaces the original claim button.");
|
||||
}
|
||||
if (state == "toolbar unavailable") toolbar.SetEnabled(false);
|
||||
|
||||
if (state == "available" || state == "disabled" || state == "rebuilt")
|
||||
{
|
||||
using var submit = NavigationSubmitEvent.GetPooled();
|
||||
submit.target = close;
|
||||
close.SendEvent(submit);
|
||||
}
|
||||
else
|
||||
{
|
||||
using var escape = KeyDownEvent.GetPooled('\0', KeyCode.Escape, EventModifiers.None);
|
||||
escape.target = close;
|
||||
close.SendEvent(escape);
|
||||
}
|
||||
VisualElement expected = state == "available" ? opener : state == "toolbar unavailable"
|
||||
? root.Q("GachaBannerList").Q<Button>(className: "selected") : toolbar;
|
||||
Assert.That(overlay.ClassListContains("hidden"), Is.True, state);
|
||||
Assert.That(overlay.ClassListContains("modal-open"), Is.False, state);
|
||||
yield return null;
|
||||
yield return null;
|
||||
Assert.That(root.focusController.focusedElement, Is.SameAs(expected), state);
|
||||
Assert.That(service.PendingStandardFiveStarSelectors, Is.EqualTo(1), "Dismissing the selector must not consume its reward.");
|
||||
}
|
||||
LogAssert.NoUnexpectedReceived();
|
||||
}
|
||||
finally { window.Close(); }
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void PullHistoryIsAToolbarModalAndNotABanner()
|
||||
{
|
||||
@@ -197,8 +584,13 @@ public class TerminalUiTests
|
||||
Assert.That(branches[2].Q<Label>(className: "command-text").text, Is.EqualTo("feature/nixos"));
|
||||
Assert.That(bannerList.Q("GachaPullHistoryButton"), Is.Null);
|
||||
Assert.That(root.Q<Button>("GachaPullHistoryButton"), Is.Not.Null);
|
||||
Assert.That(root.Q("GachaBannerDetail").Query<Label>(className: "gacha-detail-title").ToList(), Is.Empty,
|
||||
"The selected branch already identifies the banner; the detail pane should not repeat its title.");
|
||||
var detail = root.Q("GachaBannerDetail");
|
||||
Assert.That(detail.Q<Label>("GachaActiveCommand").text, Is.EqualTo("$ git checkout beginner"));
|
||||
Assert.That(detail.Q<Label>("GachaActiveTitle").text, Is.EqualTo("beginner install media"));
|
||||
Assert.That(detail.Query(className: "gacha-progress-metric").ToList().Count, Is.EqualTo(3));
|
||||
Assert.That(detail.Q<Button>("GachaPullSingleButton"), Is.Not.Null);
|
||||
Assert.That(detail.Q<Button>("GachaPullTenButton"), Is.Not.Null);
|
||||
Assert.That(root.Q<Button>("GachaPullHistoryButton").text, Does.Contain("git log --pulls").And.Contain("0 saved"));
|
||||
|
||||
screen.OpenPullHistory();
|
||||
var overlay = root.Q("GachaPullHistoryOverlay");
|
||||
@@ -212,6 +604,144 @@ public class TerminalUiTests
|
||||
"Opening history must not replace the selected banner.");
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void ExhaustedBeginnerBannerOpensOnStableBranch()
|
||||
{
|
||||
var root = AssetDatabase.LoadAssetAtPath<VisualTreeAsset>("Assets/UI/MainMenu.uxml").CloneTree();
|
||||
var service = new GachaService();
|
||||
var save = SaveData.CreateDefault();
|
||||
save.beginnerBannerState.totalPulls = GachaService.BeginnerMaxPulls;
|
||||
save.beginnerBannerState.exhausted = true;
|
||||
service.LoadProgress(save);
|
||||
var screen = new GachaScreenController();
|
||||
screen.Bind(root, null, null, null, service, new PlayerCollection(), new EntropyWallet(),
|
||||
null, null, () => { }, () => { }, null);
|
||||
|
||||
screen.Open();
|
||||
|
||||
var selected = root.Q("GachaBannerList").Q<Button>(className: "selected");
|
||||
Assert.That(selected.Q<Label>(className: "command-text").text, Is.EqualTo("stable"));
|
||||
Assert.That(root.Q<Label>("GachaActiveCommand").text, Is.EqualTo("$ git checkout stable"));
|
||||
Assert.That(root.Q<Label>("GachaActiveTitle").text, Is.EqualTo("stable branch"));
|
||||
Assert.That(root.Q<Label>("GachaBannerStatus_beginner").text, Does.StartWith("closed"));
|
||||
}
|
||||
|
||||
[UnityTest]
|
||||
public IEnumerator LimitedBannerHeroSpotlightsOnlyNixOS()
|
||||
{
|
||||
if (SystemInfo.graphicsDeviceType == UnityEngine.Rendering.GraphicsDeviceType.Null)
|
||||
Assert.Ignore("Pointer and focus tests require an editor panel; run Unity without -nographics.");
|
||||
var window = ScriptableObject.CreateInstance<TerminalFocusTestWindow>();
|
||||
try
|
||||
{
|
||||
window.position = new Rect(0, 0, 800, 700);
|
||||
window.Show();
|
||||
var root = AssetDatabase.LoadAssetAtPath<VisualTreeAsset>("Assets/UI/MainMenu.uxml").CloneTree();
|
||||
var database = AssetDatabase.LoadAssetAtPath<DistroDatabase>("Assets/Data/Distros/DistroDatabase.asset");
|
||||
var collection = new PlayerCollection();
|
||||
DistroDefinition opened = null;
|
||||
var screen = new GachaScreenController();
|
||||
screen.Bind(root, database, null, null, new GachaService(), collection, new EntropyWallet(),
|
||||
null, null, () => { }, () => { }, null, distro => opened = distro);
|
||||
screen.Open();
|
||||
|
||||
typeof(GachaScreenController).GetMethod("SelectBanner", Private).Invoke(screen, new object[] { 2 });
|
||||
|
||||
var hero = root.Q("GachaBannerDetail").Q(className: "gacha-hero");
|
||||
// Mount only the detail panel; the full menu contains hidden screen slots.
|
||||
window.rootVisualElement.Add(root.Q("GachaBannerDetail"));
|
||||
var other = new Button { text = "other focus target" };
|
||||
window.rootVisualElement.Add(other);
|
||||
yield return null;
|
||||
yield return null;
|
||||
var cards = hero.Query(className: "gacha-art-card").ToList();
|
||||
Assert.That(hero.ClassListContains("gacha-hero-single"), Is.True);
|
||||
Assert.That(cards.Count, Is.EqualTo(1));
|
||||
Assert.That(cards[0], Is.TypeOf<Button>());
|
||||
Assert.That(cards[0].focusable, Is.True);
|
||||
var ownership = cards[0].Q<Label>(className: "gacha-art-ownership");
|
||||
var inspect = cards[0].Q<Label>(className: "gacha-art-inspect");
|
||||
Assert.That(ownership.text, Is.EqualTo("NixOS · not installed"));
|
||||
Assert.That(ownership.ClassListContains("hidden"), Is.False);
|
||||
Assert.That(inspect.text, Is.EqualTo("[enter] cat /etc/distros/nixos.conf"));
|
||||
Assert.That(inspect.ClassListContains("hidden"), Is.True);
|
||||
using (var hover = PointerEnterEvent.GetPooled())
|
||||
{
|
||||
hover.target = cards[0];
|
||||
cards[0].SendEvent(hover);
|
||||
}
|
||||
Assert.That(ownership.ClassListContains("hidden"), Is.True);
|
||||
Assert.That(inspect.ClassListContains("hidden"), Is.False);
|
||||
using (var leave = PointerLeaveEvent.GetPooled())
|
||||
{
|
||||
leave.target = cards[0];
|
||||
cards[0].SendEvent(leave);
|
||||
}
|
||||
Assert.That(ownership.ClassListContains("hidden"), Is.False);
|
||||
Assert.That(inspect.ClassListContains("hidden"), Is.True);
|
||||
cards[0].Focus();
|
||||
yield return null;
|
||||
Assert.That(window.rootVisualElement.focusController.focusedElement, Is.SameAs(cards[0]));
|
||||
Assert.That(ownership.ClassListContains("hidden"), Is.True);
|
||||
Assert.That(inspect.ClassListContains("hidden"), Is.False);
|
||||
using (var leave = PointerLeaveEvent.GetPooled())
|
||||
{
|
||||
leave.target = cards[0];
|
||||
cards[0].SendEvent(leave);
|
||||
}
|
||||
Assert.That(inspect.ClassListContains("hidden"), Is.False, "Keyboard focus keeps the inspect cue visible after pointer exit.");
|
||||
using (var submit = NavigationSubmitEvent.GetPooled())
|
||||
{
|
||||
submit.target = cards[0];
|
||||
cards[0].SendEvent(submit);
|
||||
}
|
||||
Assert.That(opened?.Id, Is.EqualTo("nixos"));
|
||||
|
||||
other.Focus();
|
||||
yield return null;
|
||||
Assert.That(ownership.ClassListContains("hidden"), Is.False);
|
||||
Assert.That(inspect.ClassListContains("hidden"), Is.True);
|
||||
|
||||
collection.Add(database.FindById("nixos"), 3);
|
||||
screen.Refresh();
|
||||
ownership = window.rootVisualElement.Q("GachaBannerDetail").Q<Label>(className: "gacha-art-ownership");
|
||||
Assert.That(ownership.text, Is.EqualTo("NixOS · installed v3/5"));
|
||||
LogAssert.NoUnexpectedReceived();
|
||||
}
|
||||
finally { window.Close(); }
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void PullButtonsExplainReadinessAndKeepOddsCollapsed()
|
||||
{
|
||||
var root = AssetDatabase.LoadAssetAtPath<VisualTreeAsset>("Assets/UI/MainMenu.uxml").CloneTree();
|
||||
var database = AssetDatabase.LoadAssetAtPath<DistroDatabase>("Assets/Data/Distros/DistroDatabase.asset");
|
||||
var service = new GachaService();
|
||||
foreach (var distro in database.AllDistros) service.AddToBannerPool(distro);
|
||||
var wallet = new EntropyWallet();
|
||||
wallet.SetBalance(89);
|
||||
var screen = new GachaScreenController();
|
||||
screen.Bind(root, database, null, null, service, new PlayerCollection(), wallet,
|
||||
null, null, () => { }, () => { }, null);
|
||||
|
||||
screen.Open();
|
||||
|
||||
var single = root.Q<Button>("GachaPullSingleButton");
|
||||
var odds = root.Q<Foldout>("GachaOddsInspector");
|
||||
Assert.That(single.enabledSelf, Is.False);
|
||||
Assert.That(single.text, Does.Contain("blocked · 11 Entropy short"));
|
||||
Assert.That(odds.value, Is.False);
|
||||
Assert.That(odds.Q<Label>(className: "gacha-odds-copy").text, Does.Contain("5★ base 0.8%"));
|
||||
Assert.That(root.Q(className: "gacha-payment-note"), Is.Null);
|
||||
|
||||
wallet.SetBalance(100);
|
||||
screen.Refresh();
|
||||
|
||||
single = root.Q<Button>("GachaPullSingleButton");
|
||||
Assert.That(single.enabledSelf, Is.True);
|
||||
Assert.That(single.text, Does.Contain("ready · confirm 100 Entropy"));
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void UnitIdentityAndTabsSurviveAllFourDetailViews()
|
||||
{
|
||||
@@ -240,6 +770,30 @@ public class TerminalUiTests
|
||||
Assert.That(root.Q("CollectionContextHeader").ClassListContains("hidden"), Is.True);
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void BannerDistroDetailIsAReadOnlyOverview()
|
||||
{
|
||||
var root = AssetDatabase.LoadAssetAtPath<VisualTreeAsset>("Assets/UI/MainMenu.uxml").CloneTree();
|
||||
var database = AssetDatabase.LoadAssetAtPath<DistroDatabase>("Assets/Data/Distros/DistroDatabase.asset");
|
||||
var unit = database.FindById("nixos");
|
||||
var owned = new PlayerCollection();
|
||||
var screen = new CollectionScreenController();
|
||||
screen.Bind(root, null, null, null, owned, packageLoadout: new PackageLoadout(owned, null));
|
||||
screen.RefreshUnits(new[] { unit });
|
||||
|
||||
screen.ShowUnitDetail(unit, false, true);
|
||||
|
||||
Assert.That(screen.IsUnitDetail, Is.True);
|
||||
Assert.That(screen.CurrentHint, Is.EqualTo("[esc] back"));
|
||||
Assert.That(root.Q(className: "unit-detail-header"), Is.Not.Null);
|
||||
Assert.That(root.Q(className: "unit-detail-tabs"), Is.Null);
|
||||
Assert.That(root.Q(className: "unit-identity-section"), Is.Not.Null);
|
||||
|
||||
screen.SwitchUnitDetailTabRelative(1);
|
||||
Assert.That(root.Q(className: "unit-detail-tabs"), Is.Null);
|
||||
Assert.That(root.Q(className: "unit-identity-section"), Is.Not.Null);
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void UnitOverviewListsEquippedPackageLoadout()
|
||||
{
|
||||
@@ -484,6 +1038,118 @@ public class TerminalUiTests
|
||||
Assert.That(input.value, Is.EqualTo("./start_run"));
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void HistoryBoundariesPreserveFreshDraftsAndClampNavigation()
|
||||
{
|
||||
var root = new VisualElement();
|
||||
var input = new TextField { name = "CommandInput" };
|
||||
root.Add(input);
|
||||
root.Add(new Label { name = "CommandOutput" });
|
||||
var type = Runtime.GetType("KernelPanic.UI.TerminalCommandLine");
|
||||
var line = Activator.CreateInstance(type, root, (Action<int>)(_ => { }), (Func<bool>)(() => true));
|
||||
|
||||
input.value = "fresh draft";
|
||||
foreach (var key in new[] { KeyCode.DownArrow, KeyCode.DownArrow, KeyCode.UpArrow, KeyCode.UpArrow, KeyCode.DownArrow })
|
||||
{
|
||||
Send(type, line, key);
|
||||
Assert.That(input.value, Is.EqualTo("fresh draft"), "Empty history must preserve input.");
|
||||
}
|
||||
|
||||
foreach (var command in new[] { "./start_run", "ls ~/collection" })
|
||||
{
|
||||
input.value = command;
|
||||
Send(type, line, KeyCode.Return);
|
||||
}
|
||||
input.value = "new draft";
|
||||
Send(type, line, KeyCode.DownArrow);
|
||||
Assert.That(input.value, Is.EqualTo("new draft"));
|
||||
Send(type, line, KeyCode.UpArrow);
|
||||
Assert.That(input.value, Is.EqualTo("ls ~/collection"));
|
||||
for (int i = 0; i < 3; i++)
|
||||
{
|
||||
Send(type, line, KeyCode.UpArrow);
|
||||
Assert.That(input.value, Is.EqualTo("./start_run"), "Up clamps at the oldest entry.");
|
||||
}
|
||||
Send(type, line, KeyCode.DownArrow);
|
||||
Assert.That(input.value, Is.EqualTo("ls ~/collection"));
|
||||
Send(type, line, KeyCode.DownArrow);
|
||||
Assert.That(input.value, Is.EqualTo("new draft"));
|
||||
input.value = "edited draft";
|
||||
for (int i = 0; i < 3; i++)
|
||||
{
|
||||
Send(type, line, KeyCode.DownArrow);
|
||||
Assert.That(input.value, Is.EqualTo("edited draft"), "Down at the newest entry must not restore a stale draft.");
|
||||
}
|
||||
Send(type, line, KeyCode.UpArrow);
|
||||
Send(type, line, KeyCode.DownArrow);
|
||||
Assert.That(input.value, Is.EqualTo("edited draft"));
|
||||
}
|
||||
|
||||
[UnityTest]
|
||||
public IEnumerator CommandKeysRouteThroughFocusedInputWithoutAlsoActivatingMenu()
|
||||
{
|
||||
if (SystemInfo.graphicsDeviceType == UnityEngine.Rendering.GraphicsDeviceType.Null)
|
||||
Assert.Ignore("Keyboard routing tests require an editor panel; run Unity without -nographics.");
|
||||
var window = ScriptableObject.CreateInstance<TerminalFocusTestWindow>();
|
||||
try
|
||||
{
|
||||
window.Show();
|
||||
var root = window.rootVisualElement;
|
||||
var input = new TextField { name = "CommandInput" };
|
||||
var output = new Label { name = "CommandOutput" };
|
||||
root.Add(input);
|
||||
root.Add(output);
|
||||
int activations = 0, activated = -1, menuKeys = 0;
|
||||
bool available = true;
|
||||
Activator.CreateInstance(Runtime.GetType("KernelPanic.UI.TerminalCommandLine"), root,
|
||||
(Action<int>)(index => { activations++; activated = index; }), (Func<bool>)(() => available));
|
||||
root.RegisterCallback<KeyDownEvent>(_ => menuKeys++);
|
||||
yield return null;
|
||||
|
||||
void Key(KeyCode key)
|
||||
{
|
||||
var focused = root.focusController.focusedElement as VisualElement;
|
||||
Assert.That(focused == input || input.Contains(focused), Is.True, "Dispatch through the focused text editor.");
|
||||
using var evt = KeyDownEvent.GetPooled('\0', key, EventModifiers.None);
|
||||
evt.target = focused;
|
||||
focused.SendEvent(evt);
|
||||
}
|
||||
|
||||
foreach (var enter in new[] { KeyCode.Return, KeyCode.KeypadEnter })
|
||||
{
|
||||
input.Focus();
|
||||
input.value = "./st";
|
||||
Key(KeyCode.Tab);
|
||||
Assert.That(input.value, Is.EqualTo("./start_run"));
|
||||
int before = activations;
|
||||
Key(enter);
|
||||
Assert.That(activations, Is.EqualTo(before + 1));
|
||||
Assert.That(activated, Is.Zero);
|
||||
Assert.That(input.value, Is.Empty);
|
||||
}
|
||||
input.Focus();
|
||||
input.value = "draft";
|
||||
Key(KeyCode.UpArrow);
|
||||
Assert.That(input.value, Is.EqualTo("./start_run"));
|
||||
Key(KeyCode.DownArrow);
|
||||
Assert.That(input.value, Is.EqualTo("draft"));
|
||||
Key(KeyCode.Escape);
|
||||
Assert.That(input.value, Is.Empty);
|
||||
Assert.That(menuKeys, Is.Zero, "Handled command keys must not bubble into menu shortcuts.");
|
||||
|
||||
available = false;
|
||||
input.Focus();
|
||||
input.value = "ls ~/collection";
|
||||
string previousOutput = output.text;
|
||||
foreach (var enter in new[] { KeyCode.Return, KeyCode.KeypadEnter }) Key(enter);
|
||||
Assert.That(activations, Is.EqualTo(2), "Unavailable commands must not activate.");
|
||||
Assert.That(input.value, Is.EqualTo("ls ~/collection"));
|
||||
Assert.That(output.text, Is.EqualTo(previousOutput));
|
||||
LogAssert.NoUnexpectedReceived();
|
||||
}
|
||||
finally { window.Close(); }
|
||||
}
|
||||
|
||||
private static void Send(Type type, object line, KeyCode key)
|
||||
{
|
||||
using var evt = KeyDownEvent.GetPooled('\0', key, EventModifiers.None);
|
||||
|
||||
Reference in New Issue
Block a user