Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 20 additions & 0 deletions Assets/Tests/Editor/UIElementAnnotatorCollectTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,26 @@ public void CollectInteractiveElements_WithEventHandlerScripts_ClassifiesThem()
Assert.That(typesByPath[root + "PointerDown"], Is.EqualTo("Button"));
}

/// <summary>
/// Verifies uGUI elements, both selectables and handler scripts, are tagged as coming from uGUI.
/// </summary>
[Test]
public void CollectInteractiveElements_WithUguiElements_TagsThemAsUgui()
{
Assume.That(EventSystem.current, Is.Null);
Transform canvas = CreateCanvas("UiSystem", RenderMode.ScreenSpaceOverlay, true, null);
CreateUiChild<Button>(canvas, "Button");
CreateUiChild<UIElementAnnotatorTestClickHandler>(canvas, "Click");

List<UIElementInfo> buttons = CollectByPath(Prefix + "UiSystem/Button");
List<UIElementInfo> handlers = CollectByPath(Prefix + "UiSystem/Click");

Assert.That(buttons.Count, Is.EqualTo(1));
Assert.That(buttons[0].UiSystem, Is.EqualTo("UGUI"));
Assert.That(handlers.Count, Is.EqualTo(1));
Assert.That(handlers[0].UiSystem, Is.EqualTo("UGUI"));
}

/// <summary>
/// Verifies an object with both a selectable and a handler script is collected once, as the selectable.
/// </summary>
Expand Down
37 changes: 37 additions & 0 deletions Assets/Tests/Editor/UIToolkitElementClassifierTests.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
using System;
using NUnit.Framework;
using UnityEngine.UIElements;

using io.github.hatayama.UnityCliLoop.FirstPartyTools;

namespace io.github.hatayama.UnityCliLoop.Tests.Editor
{
/// <summary>
/// Verifies which UI Toolkit controls are annotated and which uGUI-style type each one is reported as.
/// </summary>
public sealed class UIToolkitElementClassifierTests
{
/// <summary>
/// Verifies each supported control maps to its type, and plain elements map to null.
/// </summary>
[TestCase(typeof(Button), "Button")]
[TestCase(typeof(RepeatButton), "Button")]
[TestCase(typeof(Toggle), "Toggle")]
[TestCase(typeof(RadioButton), "Toggle")]
[TestCase(typeof(Scroller), "Scrollbar")]
[TestCase(typeof(Slider), "Slider")]
[TestCase(typeof(SliderInt), "Slider")]
[TestCase(typeof(MinMaxSlider), "Slider")]
[TestCase(typeof(TextField), "InputField")]
[TestCase(typeof(DropdownField), "Dropdown")]
[TestCase(typeof(EnumField), "Dropdown")]
[TestCase(typeof(Label), null)]
[TestCase(typeof(VisualElement), null)]
public void Classify_ShouldMapControlToType(Type elementType, string expectedType)
{
VisualElement element = (VisualElement)Activator.CreateInstance(elementType);

Assert.That(UIToolkitElementClassifier.Classify(element), Is.EqualTo(expectedType));
}
}
}
11 changes: 11 additions & 0 deletions Assets/Tests/Editor/UIToolkitElementClassifierTests.cs.meta

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

89 changes: 89 additions & 0 deletions Assets/Tests/Editor/UIToolkitPanelKindTests.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,89 @@
using NUnit.Framework;
using UnityEngine;
using UnityEngine.UIElements;

using io.github.hatayama.UnityCliLoop.FirstPartyTools;

namespace io.github.hatayama.UnityCliLoop.Tests.Editor
{
/// <summary>
/// Verifies how panels are told apart as world-space or screen-space. The project's Unity version has no
/// render mode on PanelSettings, so stand-in types exercise the property lookup and the value comparison.
/// </summary>
public sealed class UIToolkitPanelKindTests
{
/// <summary>
/// Verifies default panel settings are not world-space, including on versions without a render mode
/// property at all.
/// </summary>
[Test]
public void IsWorldSpace_WithDefaultPanelSettings_ShouldReturnFalse()
{
PanelSettings settings = ScriptableObject.CreateInstance<PanelSettings>();

bool isWorldSpace = UIToolkitPanelKind.IsWorldSpace(settings);

Object.DestroyImmediate(settings);
Assert.That(isWorldSpace, Is.False);
}

/// <summary>
/// Verifies an internal render mode set to WorldSpace is detected, as on the Unity 6 versions where the
/// property is not public.
/// </summary>
[Test]
public void HasWorldSpaceRenderMode_WithInternalWorldSpace_ShouldReturnTrue()
{
InternalRenderModeSettings settings = new InternalRenderModeSettings(StandInRenderMode.WorldSpace);

Assert.That(UIToolkitPanelKind.HasWorldSpaceRenderMode(settings), Is.True);
}

/// <summary>
/// Verifies a public render mode set to a screen-space value is not treated as world-space.
/// </summary>
[Test]
public void HasWorldSpaceRenderMode_WithPublicScreenSpaceOverlay_ShouldReturnFalse()
{
PublicRenderModeSettings settings = new PublicRenderModeSettings(StandInRenderMode.ScreenSpaceOverlay);

Assert.That(UIToolkitPanelKind.HasWorldSpaceRenderMode(settings), Is.False);
}

/// <summary>
/// Verifies an object without a render mode property is not treated as world-space.
/// </summary>
[Test]
public void HasWorldSpaceRenderMode_WithoutRenderMode_ShouldReturnFalse()
{
Assert.That(UIToolkitPanelKind.HasWorldSpaceRenderMode(new object()), Is.False);
}

private enum StandInRenderMode
{
ScreenSpaceOverlay,
WorldSpace
}

private sealed class InternalRenderModeSettings
{
internal InternalRenderModeSettings(StandInRenderMode renderMode)
{
this.renderMode = renderMode;
}

// The lower-case name matches the Unity property the lookup searches for.
internal StandInRenderMode renderMode { get; }
}

private sealed class PublicRenderModeSettings
{
public PublicRenderModeSettings(StandInRenderMode renderMode)
{
this.renderMode = renderMode;
}

public StandInRenderMode renderMode { get; }
}
}
}
11 changes: 11 additions & 0 deletions Assets/Tests/Editor/UIToolkitPanelKindTests.cs.meta

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

131 changes: 131 additions & 0 deletions Assets/Tests/Editor/UIToolkitReachabilityProbeTests.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,131 @@
using System;
using System.Collections.Generic;
using NUnit.Framework;
using UnityEngine;
using UnityEngine.UIElements;

using io.github.hatayama.UnityCliLoop.FirstPartyTools;

namespace io.github.hatayama.UnityCliLoop.Tests.Editor
{
/// <summary>
/// Verifies which probe point, if any, reaches a UI Toolkit element given what the panels in front of it
/// and its own panel pick at each point.
/// </summary>
public sealed class UIToolkitReachabilityProbeTests
{
private static readonly Vector2 Center = new Vector2(50f, 50f);
private static readonly Vector2 Second = new Vector2(25f, 25f);

private static readonly Vector2[] ProbePoints =
{
Center,
Second,
new Vector2(75f, 25f),
new Vector2(25f, 75f),
new Vector2(75f, 75f)
};

/// <summary>
/// Verifies the center is returned when the own panel picks the target there.
/// </summary>
[Test]
public void FindReachablePoint_TargetPickedAtCenter_ShouldReturnCenter()
{
VisualElement target = new VisualElement();

Vector2? point = UIToolkitReachabilityProbe.FindReachablePoint(
ProbePoints, target, NoFrontPanels(), _ => target);

Assert.That(point, Is.EqualTo(Center));
}

/// <summary>
/// Verifies a point taken by a front panel is skipped and the next point the target owns is returned.
/// </summary>
[Test]
public void FindReachablePoint_FrontPanelTakesCenter_ShouldReturnSecondPoint()
{
VisualElement target = new VisualElement();
VisualElement cover = new VisualElement();
Func<Vector2, VisualElement> frontPanel = point => point == Center ? cover : null;

Vector2? point = UIToolkitReachabilityProbe.FindReachablePoint(
ProbePoints, target, new List<Func<Vector2, VisualElement>> { frontPanel }, _ => target);

Assert.That(point, Is.EqualTo(Second));
}

/// <summary>
/// Verifies picking a descendant of the target counts as reaching the target.
/// </summary>
[Test]
public void FindReachablePoint_DescendantPicked_ShouldReturnCenter()
{
VisualElement target = new VisualElement();
VisualElement child = new VisualElement();
VisualElement grandChild = new VisualElement();
target.hierarchy.Add(child);
child.hierarchy.Add(grandChild);
Func<Vector2, VisualElement> frontPanel = _ => null;

Vector2? point = UIToolkitReachabilityProbe.FindReachablePoint(
ProbePoints, target, new List<Func<Vector2, VisualElement>> { frontPanel }, _ => grandChild);

Assert.That(point, Is.EqualTo(Center));
}

/// <summary>
/// Verifies the target is unreachable when its own panel always picks another element, such as a sibling
/// drawn on top or the target's parent.
/// </summary>
[Test]
public void FindReachablePoint_OtherElementPickedEverywhere_ShouldReturnNull()
{
VisualElement parent = new VisualElement();
VisualElement target = new VisualElement();
parent.hierarchy.Add(target);

Vector2? point = UIToolkitReachabilityProbe.FindReachablePoint(
ProbePoints, target, NoFrontPanels(), _ => parent);

Assert.That(point, Is.Null);
}

/// <summary>
/// Verifies the target is unreachable when its own panel picks nothing at any point.
/// </summary>
[Test]
public void FindReachablePoint_NothingPicked_ShouldReturnNull()
{
VisualElement target = new VisualElement();

Vector2? point = UIToolkitReachabilityProbe.FindReachablePoint(
ProbePoints, target, NoFrontPanels(), _ => null);

Assert.That(point, Is.Null);
}

/// <summary>
/// Verifies a front panel that picks something at every point hides the target even though its own
/// panel would pick it.
/// </summary>
[Test]
public void FindReachablePoint_FrontPanelTakesEveryPoint_ShouldReturnNull()
{
VisualElement target = new VisualElement();
VisualElement cover = new VisualElement();
Func<Vector2, VisualElement> frontPanel = _ => cover;

Vector2? point = UIToolkitReachabilityProbe.FindReachablePoint(
ProbePoints, target, new List<Func<Vector2, VisualElement>> { frontPanel }, _ => target);

Assert.That(point, Is.Null);
}

private static List<Func<Vector2, VisualElement>> NoFrontPanels()
{
return new List<Func<Vector2, VisualElement>>();
}
}
}
11 changes: 11 additions & 0 deletions Assets/Tests/Editor/UIToolkitReachabilityProbeTests.cs.meta

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading
Loading