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
6 changes: 3 additions & 3 deletions Assets/Tests/CustomElementTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -91,21 +91,21 @@ public async Task ConsoleView_SearchAndCategorizeMessages_WorksCorrectly(
Assert.That(items.Count, Is.GreaterThanOrEqualTo(3), "There are fewer than 3 items in the ListView.");

var mouse = InputSystem.AddDevice<Mouse>();
await ClickAtPositionAsync(mouse, new Vector2(positionX0, 824));
await ClickAtPositionAsync(mouse, new Vector2(positionX0, 852));

var filteredItems = listView.itemsSource;
Assert.That(filteredItems, Is.Not.Null, "1: The type of the filter result is incorrect.");
Assert.That(filteredItems.Count, Is.EqualTo(2), "1: The search results are not filtered correctly.");

await ClickAtPositionAsync(mouse, new Vector2(positionX1, 824));
await ClickAtPositionAsync(mouse, new Vector2(positionX1, 852));

filteredItems = listView.itemsSource;
Assert.That(filteredItems, Is.Not.Null, "2: The type of the filter result is incorrect.");
Assert.That(filteredItems.Count, Is.EqualTo(1), "2: The search results are not filtered correctly.");
var logEntry = filteredItems[0] as (string, string, LogType, DateTime)?;
Assert.That(logEntry?.Item3, Is.EqualTo(type), "2: The log type of the filter result is not a warning.");

await ClickAtPositionAsync(mouse, new Vector2(positionX2, 824));
await ClickAtPositionAsync(mouse, new Vector2(positionX2, 852));

filteredItems = listView.itemsSource;
Assert.That(filteredItems, Is.Not.Null, "3: The type of the filter result is incorrect.");
Expand Down
21 changes: 9 additions & 12 deletions Assets/Tests/TestBase.cs
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ namespace DebugToolkit.Tests
{
public abstract class TestBase
{
protected readonly InputTestFixture Input = new();
private readonly InputTestFixture _input = new();

public virtual void OneTimeSetUp()
{
Expand All @@ -29,14 +29,14 @@ public virtual async Task SetUp()
Object.DestroyImmediate(document.gameObject);
}

Input.Setup();
_input.Setup();
InputSystem.settings.backgroundBehavior = InputSettings.BackgroundBehavior.IgnoreFocus;
await SceneManager.LoadSceneAsync("DefaultTests", LoadSceneMode.Additive);
}

public virtual async Task TearDown()
{
Input.TearDown();
_input.TearDown();
InputSystem.settings.backgroundBehavior = InputSettings.BackgroundBehavior.ResetAndDisableNonBackgroundDevices;
var testScene = SceneManager.GetSceneByName("DefaultTests");
if (testScene.isLoaded)
Expand All @@ -46,27 +46,24 @@ public virtual async Task TearDown()
}

[Test]
public void InputNullTest()
{
Assert.That(Input, Is.Not.Null);
}
public void InputNullTest() => Assert.That(_input, Is.Not.Null);

private static EditorWindow GetGameView()
=> EditorWindow.GetWindow(System.Type.GetType("UnityEditor.GameView,UnityEditor"));

protected async Awaitable ClickAtPositionAsync(Mouse mouse, Vector2 position)
{
Input.Set(mouse.position, position);
Input.Click(mouse.leftButton);
// Wait for two frames to ensure InputSystem events are processed
_input.Set(mouse.position, position);
_input.Click(mouse.leftButton);
// Wait for ensure InputSystem events are processed
Comment thread
syogakusya marked this conversation as resolved.
await Awaitable.NextFrameAsync();
await Awaitable.NextFrameAsync();
}

protected async Awaitable ScrollAtPositionAsync(Mouse mouse, Vector2 position, Vector2 scrollDelta)
{
Input.Set(mouse.position, position);
Input.Set(mouse.scroll, scrollDelta);
_input.Set(mouse.position, position);
_input.Set(mouse.scroll, scrollDelta);
await Awaitable.NextFrameAsync();
}
}
Expand Down
28 changes: 23 additions & 5 deletions Assets/Tests/UssTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -42,12 +42,20 @@ public override async Task TearDown()
public async Task UssWindow_AllElementsTest()
{
var window = _debugViewUssTest.Root.AddWindow("UssWindowTest");
var scrollview = new ScrollView();
window.Add(scrollview);
AddAllUIElements(scrollview);
var scrollView = new ScrollView();
window.Add(scrollView);
AddAllUIElements(scrollView);

var mouse = InputSystem.AddDevice<Mouse>();
await ClickAtPositionAsync(mouse, new Vector2(133, 865));

var toggle = _debugViewUssTest.Root.Query<Toggle>().First();
Comment thread
syogakusya marked this conversation as resolved.
Assert.That(toggle, Is.Not.Null);
Assert.That(toggle.value, Is.False, "Toggle should be false initially");

await ClickAtPositionAsync(mouse, new Vector2(133, 910));

// ここで実際にボタンが押せたかアサート
Assert.That(toggle.value, Is.True, "Not Push the Button");
Comment thread
syogakusya marked this conversation as resolved.

await CaptureScreenAsync(nameof(UssWindow_AllElementsTest) + "_scroll-before");

Expand All @@ -66,7 +74,15 @@ public async Task UssTab_AllElementsTest()
AddAllUIElements(tab1);

var mouse = InputSystem.AddDevice<Mouse>();
await ClickAtPositionAsync(mouse, new Vector2(133, 865));
var toggle = _debugViewUssTest.Root.Query<Toggle>().First();
Comment thread
syogakusya marked this conversation as resolved.

Assert.That(toggle, Is.Not.Null);
Assert.That(toggle.value, Is.False, "Toggle should be false initially");

await ClickAtPositionAsync(mouse, new Vector2(133, 910));

// ここで実際にボタンが押せたかアサート
Assert.That(toggle.value, Is.True, "Not Push the Button");
Comment thread
syogakusya marked this conversation as resolved.

await CaptureScreenAsync(nameof(UssTab_AllElementsTest) + "_scroll-before");

Expand All @@ -83,6 +99,8 @@ private static async Awaitable<string> CaptureScreenAsync(string fineName)

await Awaitable.EndOfFrameAsync();
var result = Path.Combine(directoryPath, fineName + ".png");
Comment thread
syogakusya marked this conversation as resolved.

// スクリーンショット撮影
Comment thread
syogakusya marked this conversation as resolved.
ScreenCapture.CaptureScreenshot(result);
Debug.Log($"Screenshot captured: {result}");
return result;
Expand Down
Loading