1233 lines
63 KiB
C#
1233 lines
63 KiB
C#
using System;
|
|
using System.Collections;
|
|
using System.Reflection;
|
|
using KernelPanic.Combat;
|
|
using KernelPanic.Core;
|
|
using KernelPanic.Data;
|
|
using KernelPanic.Meta;
|
|
using KernelPanic.UI;
|
|
using NUnit.Framework;
|
|
using UnityEditor;
|
|
using UnityEngine;
|
|
using UnityEngine.TestTools;
|
|
using UnityEngine.UIElements;
|
|
|
|
public class TerminalUiTests
|
|
{
|
|
private static readonly Assembly Runtime = typeof(MainMenuController).Assembly;
|
|
private static readonly BindingFlags Private = BindingFlags.Instance | BindingFlags.NonPublic;
|
|
|
|
[UnityTest]
|
|
public IEnumerator SymbolButtonsStayCenteredWithoutRealigningTerminalCommands()
|
|
{
|
|
if (SystemInfo.graphicsDeviceType == UnityEngine.Rendering.GraphicsDeviceType.Null)
|
|
Assert.Ignore("Resolved style tests require an editor panel; run Unity without -nographics.");
|
|
var window = ScriptableObject.CreateInstance<TerminalFocusTestWindow>();
|
|
try
|
|
{
|
|
window.position = new Rect(0, 0, 400, 300);
|
|
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 });
|
|
var menu = AssetDatabase.LoadAssetAtPath<VisualTreeAsset>("Assets/UI/MainMenu.uxml").CloneTree();
|
|
var plus = menu.Q<Button>("RootCreditsToEntropyButton");
|
|
var close = menu.Q<Button>("RootCreditExchangeCloseButton");
|
|
var dynamicClose = new Button { text = "x" };
|
|
dynamicClose.AddToClassList("modal-close-button");
|
|
var symbols = new[] { plus, close, dynamicClose };
|
|
foreach (var symbol in symbols)
|
|
{
|
|
root.Add(symbol);
|
|
// Keep the close controls in normal flow for this style fixture.
|
|
symbol.style.position = Position.Relative;
|
|
symbol.style.top = 0;
|
|
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;
|
|
root.Add(stepRow);
|
|
foreach (var step in steps) stepRow.Add(step);
|
|
var command = new Button { text = "> boot" };
|
|
command.AddToClassList("terminal-button");
|
|
root.Add(command);
|
|
|
|
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;
|
|
foreach (var symbol in symbols)
|
|
{
|
|
var style = symbol.resolvedStyle;
|
|
Assert.That(style.unityTextAlign, Is.EqualTo(TextAnchor.MiddleCenter), symbol.text);
|
|
Assert.That(style.paddingLeft, Is.Zero);
|
|
Assert.That(style.paddingRight, Is.Zero);
|
|
Assert.That(style.paddingTop, Is.Zero);
|
|
Assert.That(style.paddingBottom, Is.Zero);
|
|
Assert.That(style.flexShrink, Is.Zero);
|
|
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();
|
|
}
|
|
finally { window.Close(); }
|
|
}
|
|
|
|
[UnityTest]
|
|
public IEnumerator FocusRevealIgnoresScrollViewChrome()
|
|
{
|
|
if (SystemInfo.graphicsDeviceType == UnityEngine.Rendering.GraphicsDeviceType.Null)
|
|
Assert.Ignore("Focus event tests require an editor panel; run Unity without -nographics.");
|
|
var window = ScriptableObject.CreateInstance<TerminalFocusTestWindow>();
|
|
try
|
|
{
|
|
window.position = new Rect(0, 0, 360, 260);
|
|
window.Show();
|
|
var root = window.rootVisualElement;
|
|
Runtime.GetType("KernelPanic.UI.TerminalTheme").GetMethod("Attach").Invoke(null, new object[] { root });
|
|
var scroll = new ScrollView(ScrollViewMode.VerticalAndHorizontal);
|
|
scroll.style.width = 240;
|
|
scroll.style.height = 160;
|
|
var content = new VisualElement();
|
|
content.style.width = 800;
|
|
content.style.height = 800;
|
|
scroll.Add(content);
|
|
root.Add(scroll);
|
|
yield return null;
|
|
yield return null;
|
|
|
|
// Scrollbar controls are descendants of ScrollView, but not of its contentContainer.
|
|
foreach (var control in new VisualElement[]
|
|
{
|
|
scroll.verticalScroller.slider, scroll.verticalScroller.lowButton, scroll.verticalScroller.highButton,
|
|
scroll.horizontalScroller.slider, scroll.horizontalScroller.lowButton, scroll.horizontalScroller.highButton,
|
|
scroll.contentViewport, scroll.contentContainer, scroll
|
|
})
|
|
{
|
|
control.focusable = true;
|
|
control.Focus();
|
|
yield return null;
|
|
Assert.That(root.focusController.focusedElement, Is.SameAs(control));
|
|
LogAssert.NoUnexpectedReceived();
|
|
}
|
|
}
|
|
finally { window.Close(); }
|
|
}
|
|
|
|
[UnityTest]
|
|
public IEnumerator FocusRevealStillScrollsNestedContentIntoView()
|
|
{
|
|
if (SystemInfo.graphicsDeviceType == UnityEngine.Rendering.GraphicsDeviceType.Null)
|
|
Assert.Ignore("Focus event tests require an editor panel; run Unity without -nographics.");
|
|
var window = ScriptableObject.CreateInstance<TerminalFocusTestWindow>();
|
|
try
|
|
{
|
|
window.position = new Rect(0, 0, 360, 260);
|
|
window.Show();
|
|
var root = window.rootVisualElement;
|
|
Runtime.GetType("KernelPanic.UI.TerminalTheme").GetMethod("Attach").Invoke(null, new object[] { root });
|
|
var outer = new ScrollView();
|
|
outer.style.width = 260;
|
|
outer.style.height = 180;
|
|
var outerSpacer = new VisualElement();
|
|
outerSpacer.style.height = 400;
|
|
outer.Add(outerSpacer);
|
|
var inner = new ScrollView();
|
|
inner.style.height = 100;
|
|
inner.style.flexShrink = 0;
|
|
var innerSpacer = new VisualElement();
|
|
innerSpacer.style.height = 400;
|
|
inner.Add(innerSpacer);
|
|
var target = new Button { text = "last operation" };
|
|
inner.Add(target);
|
|
outer.Add(inner);
|
|
root.Add(outer);
|
|
yield return null;
|
|
yield return null;
|
|
|
|
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(); }
|
|
}
|
|
|
|
[Test]
|
|
public void SharedScreenFramesGiveTemplatesOneExplicitLayoutSlot()
|
|
{
|
|
var root = AssetDatabase.LoadAssetAtPath<VisualTreeAsset>("Assets/UI/MainMenu.uxml").CloneTree();
|
|
foreach (var id in new[] { "CollectionPanel", "GachaPanel", "SettingsPanel" })
|
|
{
|
|
var panel = root.Q(id);
|
|
var frame = new ScreenFrameController();
|
|
frame.Bind(panel, "$ test", "[esc] back [tab] focus", () => { });
|
|
Assert.That(panel.parent.ClassListContains("screen-slot"), Is.True, id);
|
|
Assert.That(panel.parent.ClassListContains("hidden"), Is.True, id);
|
|
Assert.That(panel.Q<Button>(className: "screen-back").focusable, Is.True);
|
|
Assert.That(panel.Q<Label>(className: "screen-frame-hint").text, Is.EqualTo("[tab] focus"));
|
|
}
|
|
}
|
|
|
|
[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()
|
|
{
|
|
var root = AssetDatabase.LoadAssetAtPath<VisualTreeAsset>("Assets/UI/MainMenu.uxml").CloneTree();
|
|
var screen = new GachaScreenController();
|
|
screen.Bind(root, null, null, null, new GachaService(), new PlayerCollection(), new EntropyWallet(),
|
|
null, null, () => { }, () => { }, null);
|
|
screen.Open();
|
|
|
|
var bannerList = root.Q("GachaBannerList");
|
|
var branches = bannerList.Query<Button>(className: "gacha-banner-row").ToList();
|
|
Assert.That(branches.Count, Is.EqualTo(3));
|
|
Assert.That(bannerList.Q<Label>(className: "gacha-branch-command").text, Is.EqualTo("$ git branch --list"));
|
|
Assert.That(branches[0].Q<Label>(className: "command-cursor").text, Is.EqualTo("*"));
|
|
Assert.That(branches[0].Q<Label>(className: "command-text").text, Is.EqualTo("beginner"));
|
|
Assert.That(branches[1].Q<Label>(className: "command-text").text, Is.EqualTo("stable"));
|
|
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);
|
|
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");
|
|
Assert.That(overlay, Is.Not.Null);
|
|
Assert.That(overlay.ClassListContains("modal-open"), Is.True);
|
|
Assert.That(overlay.ClassListContains("hidden"), Is.False);
|
|
Assert.That(overlay.Q<Label>(className: "gacha-detail-title").text, Is.EqualTo("[ git log --pulls ]"));
|
|
Assert.That(overlay.Q<Label>(className: "gacha-history-empty").text, Does.StartWith("fatal: no committed pulls found"));
|
|
Assert.That(overlay.Q<Button>("ClosePullHistory"), Is.Not.Null);
|
|
Assert.That(bannerList.Query<Button>(className: "selected").ToList().Count, Is.EqualTo(1),
|
|
"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()
|
|
{
|
|
var root = AssetDatabase.LoadAssetAtPath<VisualTreeAsset>("Assets/UI/MainMenu.uxml").CloneTree();
|
|
var unit = AssetDatabase.LoadAssetAtPath<DistroDefinition>("Assets/Data/Distros/Ubuntu.asset");
|
|
var owned = new PlayerCollection(); owned.Add(unit);
|
|
var screen = new CollectionScreenController();
|
|
screen.Bind(root, null, null, null, owned, packageLoadout: new PackageLoadout(owned, null));
|
|
screen.RefreshUnits(owned.OwnedUnits);
|
|
screen.ActivateSelected();
|
|
var identity = root.Q(className: "unit-detail-header");
|
|
var tabs = root.Q(className: "unit-detail-tabs");
|
|
for (int i = 0; i < 4; i++)
|
|
{
|
|
screen.SwitchUnitDetailTabRelative(1);
|
|
Assert.That(root.Q(className: "unit-detail-header"), Is.SameAs(identity));
|
|
Assert.That(root.Q(className: "unit-detail-tabs"), Is.SameAs(tabs));
|
|
Assert.That(screen.IsUnitDetail, Is.True);
|
|
if (i == 2)
|
|
{
|
|
Assert.That(root.Q(className: "collection-manifest"), Is.Not.Null);
|
|
Assert.That(root.Q<ScrollView>("CollectionList").Query<Button>().ToList().Count, Is.GreaterThan(0));
|
|
}
|
|
}
|
|
Assert.That(screen.BackFromSubview(), Is.True);
|
|
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()
|
|
{
|
|
var root = AssetDatabase.LoadAssetAtPath<VisualTreeAsset>("Assets/UI/MainMenu.uxml").CloneTree();
|
|
var unit = AssetDatabase.LoadAssetAtPath<DistroDefinition>("Assets/Data/Distros/Ubuntu.asset");
|
|
var package = AssetDatabase.LoadAssetAtPath<PackageDefinition>("Assets/Data/Packages/AptFast.asset");
|
|
var database = AssetDatabase.LoadAssetAtPath<PackageDatabase>("Assets/Data/Packages/PackageDatabase.asset");
|
|
var owned = new PlayerCollection();
|
|
owned.Add(unit);
|
|
owned.AddPackage(package);
|
|
var loadout = new PackageLoadout(owned, database);
|
|
Assert.That(loadout.TryEquip(unit.Id, package.Slot, package.Id, out _), Is.True);
|
|
|
|
var screen = new CollectionScreenController();
|
|
screen.Bind(root, null, null, null, owned, packageDatabase: database, packageLoadout: loadout);
|
|
screen.RefreshUnits(owned.OwnedUnits);
|
|
|
|
var row = root.Q<Button>(className: "unit-overview-row");
|
|
var packages = row.Q<Label>(className: "unit-loadout-line");
|
|
Assert.That(packages, Is.Not.Null);
|
|
Assert.That(packages.text, Does.Contain(package.DisplayName));
|
|
Assert.That(packages.text, Does.Contain("system=").And.Contain("tools=").And.Contain("services="));
|
|
Assert.That(row.tooltip, Does.Contain(package.DisplayName));
|
|
}
|
|
|
|
[Test]
|
|
public void InventoryRowsUseCompactMetadataAndKeepEffectsInDetails()
|
|
{
|
|
var root = AssetDatabase.LoadAssetAtPath<VisualTreeAsset>("Assets/UI/MainMenu.uxml").CloneTree();
|
|
var owned = new PlayerCollection();
|
|
var package = AssetDatabase.LoadAssetAtPath<PackageDefinition>("Assets/Data/Packages/Aur.asset");
|
|
owned.AddPackage(package);
|
|
var screen = new CollectionScreenController();
|
|
screen.Bind(root, null, null, null, owned, getSaveData: () => new SaveData());
|
|
screen.ShowPackages();
|
|
var row = root.Q<Button>(className: "inventory-row");
|
|
Assert.That(row, Is.Not.Null);
|
|
Assert.That(row.Q<Label>(className: "inventory-name").text, Is.Not.Empty);
|
|
Assert.That(row.Q(className: "inventory-metadata"), Is.Not.Null);
|
|
Assert.That(row.Q(className: "package-slot-effect"), Is.Null);
|
|
Assert.That(root.Q("CollectionFilters").Query<Button>().ToList().Count, Is.EqualTo(4));
|
|
Assert.That(root.Q("CollectionDetail").Q(className: "destructive-action"), Is.Not.Null);
|
|
}
|
|
|
|
[TestCase("AptFast", 3)]
|
|
[TestCase("CinnamonPackage", 4)]
|
|
[TestCase("GentooPortage", 4)]
|
|
[TestCase("GentooCcache", 4)]
|
|
[TestCase("GentooOpenRC", 5)]
|
|
[TestCase("Apt", 5)]
|
|
public void PackageRarityUsesTheSameBadgeInInventoryDetailsAndEquipment(string asset, int stars)
|
|
{
|
|
var root = AssetDatabase.LoadAssetAtPath<VisualTreeAsset>("Assets/UI/MainMenu.uxml").CloneTree();
|
|
var package = AssetDatabase.LoadAssetAtPath<PackageDefinition>($"Assets/Data/Packages/{asset}.asset");
|
|
var unit = AssetDatabase.LoadAssetAtPath<DistroDefinition>("Assets/Data/Distros/Ubuntu.asset");
|
|
var database = AssetDatabase.LoadAssetAtPath<PackageDatabase>("Assets/Data/Packages/PackageDatabase.asset");
|
|
var owned = new PlayerCollection();
|
|
owned.Add(unit);
|
|
owned.AddPackage(package);
|
|
var loadout = new PackageLoadout(owned, database);
|
|
var screen = new CollectionScreenController();
|
|
screen.Bind(root, null, null, null, owned, packageLoadout: loadout, getSaveData: () => new SaveData());
|
|
screen.ShowPackages();
|
|
|
|
var inventory = root.Q<Button>(className: "inventory-row");
|
|
var detail = root.Q("CollectionDetail").Q(className: "package-heading");
|
|
Assert.That(inventory.Q(className: "inventory-metadata").Q(className: "package-rarity"), Is.Null);
|
|
Assert.That(inventory.Q(className: "package-heading").Q(className: "package-rarity"), Is.Not.Null);
|
|
typeof(CollectionScreenController).GetMethod("OpenPackageEquipWindow", Private)
|
|
.Invoke(screen, new object[] { unit, package.Slot });
|
|
var equip = root.Q<Button>(className: "package-equip-row");
|
|
|
|
Assert.That(loadout.TryEquip(unit.Id, package.Slot, package.Id, out _), Is.True);
|
|
var slots = new VisualElement();
|
|
typeof(CollectionScreenController).GetMethod("AddPackageSlotSummaryRow", Private)
|
|
.Invoke(screen, new object[] { slots, unit, package.Slot });
|
|
foreach (var view in new[] { inventory, detail, equip, slots.Q(className: "package-slot-row") })
|
|
{
|
|
Assert.That(view.ClassListContains("package-tier"), Is.True);
|
|
Assert.That(view.ClassListContains($"rarity-{stars}"), Is.True);
|
|
var badge = view.Q<Label>(className: "package-rarity");
|
|
Assert.That(badge.text, Is.EqualTo($"{stars}★"));
|
|
Assert.That(badge.tooltip, Is.EqualTo($"{stars}-star package"));
|
|
}
|
|
|
|
loadout.TryUnequip(unit.Id, package.Slot, out _);
|
|
slots.Clear();
|
|
typeof(CollectionScreenController).GetMethod("AddPackageSlotSummaryRow", Private)
|
|
.Invoke(screen, new object[] { slots, unit, package.Slot });
|
|
Assert.That(slots.Q(className: "package-rarity"), Is.Null, "Empty slots must not imply a rarity.");
|
|
}
|
|
|
|
[UnityTest]
|
|
public IEnumerator PackageRarityColorsAndBadgesSurviveSelectionAndNarrowRows()
|
|
{
|
|
if (SystemInfo.graphicsDeviceType == UnityEngine.Rendering.GraphicsDeviceType.Null)
|
|
Assert.Ignore("Resolved style tests require an editor panel; run Unity without -nographics.");
|
|
var window = ScriptableObject.CreateInstance<TerminalFocusTestWindow>();
|
|
try
|
|
{
|
|
window.position = new Rect(0, 0, 400, 650);
|
|
window.Show();
|
|
var root = window.rootVisualElement;
|
|
root.styleSheets.Add(AssetDatabase.LoadAssetAtPath<StyleSheet>("Assets/UI/MainMenu.uss"));
|
|
root.styleSheets.Add(Resources.Load<StyleSheet>("RarityPresentation"));
|
|
Runtime.GetType("KernelPanic.UI.TerminalTheme").GetMethod("Attach").Invoke(null, new object[] { root });
|
|
var collection = new PlayerCollection();
|
|
var screen = new CollectionScreenController();
|
|
var assets = new[] { "AptFast", "CinnamonPackage", "Apt" };
|
|
var colors = new[] { "#9aaa9f", "#83c6cc", "#e7bb72" };
|
|
for (int i = 0; i < assets.Length; i++)
|
|
{
|
|
var package = AssetDatabase.LoadAssetAtPath<PackageDefinition>($"Assets/Data/Packages/{assets[i]}.asset");
|
|
collection.AddPackage(package);
|
|
var row = (Button)typeof(CollectionScreenController).GetMethod("BuildPackageInventoryRow", Private)
|
|
.Invoke(screen, new object[] { collection.GetOwnedPackage(package.Id), 10000, 10000 });
|
|
root.Add(row);
|
|
var name = row.Q<Label>(className: "inventory-name");
|
|
name.text += " / long package name";
|
|
var badge = row.Q<Label>(className: "package-rarity");
|
|
ColorUtility.TryParseHtmlString(colors[i], out var color);
|
|
foreach (int width in new[] { 220, 340 })
|
|
{
|
|
row.style.width = width;
|
|
foreach (bool selected in new[] { false, true })
|
|
{
|
|
row.EnableInClassList("selected", selected);
|
|
if (selected) row.Focus();
|
|
yield return null;
|
|
yield return null;
|
|
Assert.That(badge.resolvedStyle.color, Is.EqualTo(color));
|
|
Assert.That(name.resolvedStyle.color, Is.EqualTo(color));
|
|
Assert.That(badge.worldBound.xMax, Is.LessThanOrEqualTo(row.worldBound.xMax));
|
|
Assert.That(name.worldBound.xMax, Is.LessThanOrEqualTo(badge.worldBound.xMin));
|
|
Assert.That(row.Q(className: "inventory-metadata").worldBound.yMin,
|
|
Is.GreaterThanOrEqualTo(name.worldBound.yMax));
|
|
}
|
|
}
|
|
}
|
|
LogAssert.NoUnexpectedReceived();
|
|
}
|
|
finally { window.Close(); }
|
|
}
|
|
|
|
[Test]
|
|
public void CommandsUseExistingActionIndicesAndRejectShellInput()
|
|
{
|
|
var root = new VisualElement();
|
|
var input = new TextField { name = "CommandInput" };
|
|
root.Add(input);
|
|
root.Add(new Label { name = "CommandOutput" });
|
|
int activated = -1;
|
|
var type = Runtime.GetType("KernelPanic.UI.TerminalCommandLine");
|
|
var line = Activator.CreateInstance(type, root, (Action<int>)(i => activated = i), (Func<bool>)(() => true));
|
|
var commands = (string[])type.GetField("Commands", BindingFlags.Static | BindingFlags.NonPublic).GetValue(null);
|
|
Assert.That(commands, Is.EqualTo(new[]
|
|
{
|
|
"./start_run", "ls ~/collection", "curl gacha.sh | sh", "dpkg-reconfigure", "history --runs", "shutdown -h now", "cat /etc/cron.daily/quests", "git log --pulls"
|
|
}));
|
|
for (int i = 0; i < commands.Length; i++)
|
|
{
|
|
input.value = commands[i];
|
|
type.GetMethod("Submit", Private).Invoke(line, null);
|
|
Assert.That(activated, Is.EqualTo(i));
|
|
Assert.That(input.value, Is.Empty);
|
|
}
|
|
input.value = "./start_run; shutdown";
|
|
type.GetMethod("Submit", Private).Invoke(line, null);
|
|
Assert.That(activated, Is.EqualTo(7));
|
|
Assert.That(root.Q<Label>("CommandOutput").text, Does.Contain("command not found"));
|
|
}
|
|
|
|
[TestCase("his", "history --runs", 4)]
|
|
[TestCase("shut", "shutdown -h now", 5)]
|
|
[TestCase("cat /etc/cron", "cat /etc/cron.daily/quests", 6)]
|
|
[TestCase("git log", "git log --pulls", 7)]
|
|
public void ArchiveAndQuitCommandsCompleteAndKeepTheirOwnActionIndices(string prefix, string command, int index)
|
|
{
|
|
var root = new VisualElement();
|
|
var input = new TextField { name = "CommandInput" };
|
|
root.Add(input);
|
|
root.Add(new Label { name = "CommandOutput" });
|
|
int activated = -1;
|
|
var type = Runtime.GetType("KernelPanic.UI.TerminalCommandLine");
|
|
var line = Activator.CreateInstance(type, root, (Action<int>)(i => activated = i), (Func<bool>)(() => true));
|
|
input.value = prefix;
|
|
Send(type, line, KeyCode.Tab);
|
|
Assert.That(input.value, Is.EqualTo(command));
|
|
Send(type, line, KeyCode.Return);
|
|
Assert.That(activated, Is.EqualTo(index));
|
|
}
|
|
|
|
[TestCase(KeyCode.Alpha5, 4)]
|
|
[TestCase(KeyCode.Keypad5, 4)]
|
|
[TestCase(KeyCode.Alpha6, 5)]
|
|
[TestCase(KeyCode.Keypad6, 5)]
|
|
public void NumberShortcutsIncludeArchiveAndTheMovedQuitCommand(KeyCode key, int expected)
|
|
{
|
|
var type = Runtime.GetType("KernelPanic.UI.CommandKeyBindings");
|
|
Assert.That(type.GetMethod("GetDigitIndex").Invoke(null, new object[] { key }), Is.EqualTo(expected));
|
|
}
|
|
|
|
[Test]
|
|
public void RunArchiveCommandSitsBetweenSettingsAndQuitWithSharedScreenChrome()
|
|
{
|
|
var root = AssetDatabase.LoadAssetAtPath<VisualTreeAsset>("Assets/UI/MainMenu.uxml").CloneTree();
|
|
var commands = root.Q("MainMenuPanel").Query<VisualElement>(className: "command-row").ToList();
|
|
Assert.That(commands.ConvertAll(command => command.name), Is.EqualTo(new[]
|
|
{
|
|
"CommandStartRun", "CommandCollection", "CommandGacha", "CommandSettings", "CommandRunArchive", "CommandQuit"
|
|
}));
|
|
var archiveCommand = root.Q("CommandRunArchive");
|
|
Assert.That(archiveCommand.Q<Label>(className: "command-text").text, Is.EqualTo("history --runs"));
|
|
Assert.That(archiveCommand.Q<Label>(className: "command-description").text, Is.EqualTo("run archive"));
|
|
var panel = root.Q("RunArchivePanel");
|
|
Assert.That(panel.ClassListContains("hidden"), Is.True);
|
|
Assert.That(panel.Q("RunArchiveActions"), Is.Not.Null);
|
|
var frame = new ScreenFrameController();
|
|
frame.Bind(panel, "$ history --runs", "[esc] back [tab/enter] actions", () => { });
|
|
Assert.That(panel.Q<Label>(className: "screen-frame-title").text, Is.EqualTo("$ history --runs"));
|
|
Assert.That(panel.Q<Button>(className: "screen-back").focusable, Is.True);
|
|
Assert.That(panel.Q<Label>(className: "screen-frame-hint").text, Is.EqualTo("[tab/enter] actions"));
|
|
}
|
|
|
|
[Test]
|
|
public void HistoryRestoresDraftAndTabCompletes()
|
|
{
|
|
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 = "ls ~/collection";
|
|
type.GetMethod("Submit", Private).Invoke(line, null);
|
|
input.value = "./st";
|
|
Send(type, line, KeyCode.UpArrow);
|
|
Assert.That(input.value, Is.EqualTo("ls ~/collection"));
|
|
Send(type, line, KeyCode.DownArrow);
|
|
Assert.That(input.value, Is.EqualTo("./st"));
|
|
Send(type, line, KeyCode.Tab);
|
|
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);
|
|
type.GetMethod("OnKeyDown", Private).Invoke(line, new object[] { evt });
|
|
}
|
|
|
|
[Test]
|
|
public void ManifestKeepsExactRulesAndShowsMutableStates()
|
|
{
|
|
var card = AssetDatabase.LoadAssetAtPath<CardDefinition>("Assets/Data/Cards/Languages/C/Malloc.asset");
|
|
Assert.That(card, Is.Not.Null);
|
|
var instance = new CardInstance(card) { IsBroken = true };
|
|
instance.ApplyDrawRider(2);
|
|
var face = new VisualElement();
|
|
Runtime.GetType("KernelPanic.UI.SoftwareCardView").GetMethod("Populate", new[] { typeof(VisualElement), typeof(CardInstance), typeof(int) }).Invoke(null, new object[] { face, instance, 3 });
|
|
Assert.That(face.ClassListContains("software-c"), Is.True);
|
|
Assert.That(face.ClassListContains("software-corrupted"), Is.True);
|
|
Assert.That(face.Q<Label>(className: "software-cost").text, Is.EqualTo("3c"));
|
|
Assert.That(face.tooltip, Does.StartWith(CardEffectFactory.GetRulesText(instance)));
|
|
Assert.That(face.tooltip, Does.Contain("Draw 2."));
|
|
Assert.That(face.Q<Label>(className: "software-state").text, Does.Contain("CORRUPTED"));
|
|
}
|
|
|
|
[Test]
|
|
public void EveryCardRetainsItsCompleteRulesInTheManifest()
|
|
{
|
|
var populate = Runtime.GetType("KernelPanic.UI.SoftwareCardView").GetMethod("Populate", new[] { typeof(VisualElement), typeof(CardInstance), typeof(int) });
|
|
var guids = AssetDatabase.FindAssets("t:CardDefinition", new[] { "Assets/Data/Cards" });
|
|
Assert.That(guids.Length, Is.GreaterThan(0));
|
|
foreach (string guid in guids)
|
|
{
|
|
var definition = AssetDatabase.LoadAssetAtPath<CardDefinition>(AssetDatabase.GUIDToAssetPath(guid));
|
|
var instance = new CardInstance(definition);
|
|
var face = new VisualElement();
|
|
populate.Invoke(null, new object[] { face, instance, CombatManager.GetCardCost(instance) });
|
|
string rules = face.Q<Label>(className: "software-effect").text;
|
|
foreach (var conditions in face.Query<Label>(className: "software-conditions").ToList())
|
|
rules += " " + conditions.text;
|
|
var role = face.Q<Label>(className: "software-python-role");
|
|
if (role != null) rules = role.text.ToLowerInvariant() + ": " + rules;
|
|
Assert.That(rules, Is.EqualTo(CardEffectFactory.GetRulesText(instance)), definition.name);
|
|
}
|
|
}
|
|
|
|
[Test]
|
|
public void TrackViewsMatchActualDequeueAndPopOrder()
|
|
{
|
|
var a = new CardInstance(null);
|
|
var b = new CardInstance(null);
|
|
var queue = new InterpreterQueue();
|
|
var stack = new LazyStack();
|
|
queue.Enqueue(a); queue.Enqueue(b);
|
|
stack.Enqueue(a); stack.Enqueue(b);
|
|
Assert.That(queue.Cards[0], Is.SameAs(a));
|
|
Assert.That(stack.Cards[0], Is.SameAs(b));
|
|
queue.TryDequeue(out var first);
|
|
stack.TryPop(out var top);
|
|
Assert.That(first, Is.SameAs(a));
|
|
Assert.That(top, Is.SameAs(b));
|
|
}
|
|
|
|
[Test]
|
|
public void MenuImportsWithPromptAndAllScreenBindings()
|
|
{
|
|
var tree = AssetDatabase.LoadAssetAtPath<VisualTreeAsset>("Assets/UI/MainMenu.uxml");
|
|
var root = tree.CloneTree();
|
|
foreach (string id in new[] { "MainMenuPanel", "RunSetupPanel", "CollectionPanel", "GachaPanel", "SettingsPanel", "RunArchivePanel", "StarterModal", "RootCreditExchangeModal" })
|
|
Assert.That(root.Q(id), Is.Not.Null, id);
|
|
Assert.That(root.Q<TextField>("CommandInput"), Is.Not.Null);
|
|
Assert.That(root.Q<Toggle>("ReducedMotionToggle"), Is.Not.Null);
|
|
Assert.That(root.Q<SliderInt>("SoundVolumeSlider"), Is.Not.Null);
|
|
Assert.That(root.Q<Button>("SoundVolumeButton"), Is.Null);
|
|
Assert.That(AssetDatabase.LoadAssetAtPath<StyleSheet>("Assets/Resources/KernelTheme.uss"), Is.Not.Null);
|
|
Assert.That(AssetDatabase.LoadAssetAtPath<StyleSheet>("Assets/Resources/TerminalProgram.uss"), Is.Not.Null);
|
|
Assert.That(AssetDatabase.LoadAssetAtPath<Font>("Assets/Resources/Fonts/JetBrainsMono-Regular.ttf"), Is.Not.Null,
|
|
"The terminal must ship one deterministic monospace font instead of depending on the host OS.");
|
|
}
|
|
}
|
|
|
|
public sealed class TerminalFocusTestWindow : EditorWindow { }
|