using NUnit.Framework;using UnityEngine;using UnityEngine.UI;using DevilLink2.UI;using DevilLink2.Gameplay; namespace DevilLink2.Tests {public sealed partial class UIScreenTests { [Test]public void GameplayBackHasOneArrowAndCenteredLabel(){var b=ui.LobbyButton;Assert.That(b.GetComponentInChildren(true).text,Is.EqualTo("LOBBY"));var c=(RectTransform)b.transform.Find("ControlContentRoot");Assert.That(c.anchoredPosition.x+c.rect.width/2,Is.EqualTo(41));Assert.That(c.Find("UI11BIcon"),Is.Not.Null);} [TestCase(GameMode.Classic)][TestCase(GameMode.TimeAttack)][TestCase(GameMode.Zen)]public void ModeLinesHaveBalancedPaddingAndKeepFont(GameMode mode){ui.ShowLobby();ui.SelectMode(mode);var v=ui.Hud.GetComponent();v.Refresh();var source=ui.Hud.ModeLabel;var a=source.transform.Find("ModeName").GetComponent();var b=source.transform.Find("LevelNumber").GetComponent();Assert.That(a.text,Is.EqualTo(UIManager.ModeName(mode)));Assert.That(b.text,Does.Contain("LEVEL"));Assert.That(a.fontSize,Is.EqualTo(source.fontSize));Assert.That(b.fontSize,Is.EqualTo(source.fontSize));Assert.That(a.rectTransform.anchoredPosition.y,Is.EqualTo(-3));Assert.That(b.rectTransform.anchoredPosition.y,Is.EqualTo(-24));Assert.That(source.rectTransform.sizeDelta,Is.EqualTo(new Vector2(252,44)));} [Test]public void PauseFaceAndIconShareGeometricCenter(){var b=ui.Hud.PauseButton;foreach(string n in new[]{"UI11BIcon","UI11BButtonFace"}){var r=(RectTransform)b.transform.Find(n);Assert.That(r.anchoredPosition,Is.EqualTo(Vector2.zero));Assert.That(r.pivot,Is.EqualTo(new Vector2(.5f,.5f)));Assert.That(r.anchorMin,Is.EqualTo(r.pivot));Assert.That(r.anchorMax,Is.EqualTo(r.pivot));}Assert.That(((RectTransform)b.transform).sizeDelta,Is.EqualTo(new Vector2(48,36)));} [TestCase(0)][TestCase(1)][TestCase(2)]public void ItemLayoutSeparatesIconAndTwoTexts(int index){var b=ui.Hud.ItemButtons[index];var icon=(RectTransform)b.transform.Find("IconRoot");var text=(RectTransform)b.transform.Find("TextRoot");Assert.That(icon.anchoredPosition,Is.EqualTo(new Vector2(10,-18)));Assert.That(text.anchoredPosition,Is.EqualTo(new Vector2(42,-8)));Assert.That(icon.anchoredPosition.x+icon.rect.width+8,Is.EqualTo(text.anchoredPosition.x));Assert.That(text.Find("Label"),Is.Not.Null);Assert.That(text.Find("InventoryCount"),Is.Not.Null);Assert.That(((RectTransform)b.transform).sizeDelta,Is.EqualTo(new Vector2(126,60)));} [TestCase(0)][TestCase(1)][TestCase(2)]public void ItemStatesDoNotRepositionContents(int index){var b=ui.Hud.ItemButtons[index];var r=(RectTransform)b.transform.Find("TextRoot");var original=r.anchoredPosition;var size=r.sizeDelta;b.interactable=false;Assert.That(r.anchoredPosition,Is.EqualTo(original));b.interactable=true;b.OnPointerDown(new UnityEngine.EventSystems.PointerEventData(null){button=UnityEngine.EventSystems.PointerEventData.InputButton.Left});Assert.That(r.anchoredPosition,Is.EqualTo(original));b.OnPointerUp(new UnityEngine.EventSystems.PointerEventData(null));Assert.That(r.sizeDelta,Is.EqualTo(size));Assert.That(b.spriteState.pressedSprite,Is.Not.Null);} [Test]public void ShopGroupIsCenteredAndSpaced(){var c=(RectTransform)ui.GameShopButton.transform.Find("ControlContentRoot");Assert.That(c.anchoredPosition.x+c.rect.width/2,Is.EqualTo(63));var t=c.GetComponentInChildren();Assert.That(t.rectTransform.anchoredPosition.x,Is.EqualTo(30));Assert.That(c.Find("UI11BIcon"),Is.Not.Null);} [Test]public void ControlsKeepNavigationAndInventoryBinding(){ui.ShowLobby();ui.SelectMode(GameMode.Classic);var h=ui.Hud;h.PauseButton.onClick.Invoke();Assert.That(bootstrap.Flow.State,Is.EqualTo(GameFlowState.Paused));h.Pause.ResumeButton.onClick.Invoke();ui.GameShopButton.onClick.Invoke();Assert.That(ui.Shop.IsVisible,Is.True);ui.CloseShop();h.Refresh();h.GetComponent().Refresh();for(int i=0;i<3;i++)Assert.That(h.ItemButtons[i].transform.Find("TextRoot/InventoryCount").GetComponent().text,Is.EqualTo(player.Economy.Inventory.GetCount((ItemType)i).ToString()));} [Test]public void ControlsReinstallDoesNotDuplicateNodes(){int count=ui.Gameplay.GetComponentsInChildren(true).Length;for(int i=0;i<5;i++)GameplayControlsLayout.Install(ui.Hud,ui.GameShopButton);Assert.That(ui.Gameplay.GetComponentsInChildren(true).Length,Is.EqualTo(count));} }}