1
0
mirror of https://github.com/ppy/osu.git synced 2024-12-21 07:53:38 +08:00
osu-lazer/osu.Game.Tests/Visual/Settings/TestSceneKeyBindingPanel.cs

140 lines
4.7 KiB
C#
Raw Normal View History

// Copyright (c) ppy Pty Ltd <contact@ppy.sh>. Licensed under the MIT Licence.
// See the LICENCE file in the repository root for full licence text.
2018-04-13 17:19:50 +08:00
using System.Diagnostics;
using System.Linq;
2018-04-13 17:19:50 +08:00
using NUnit.Framework;
using osu.Framework.Testing;
using osu.Framework.Threading;
2018-04-13 17:19:50 +08:00
using osu.Game.Overlays;
using osu.Game.Overlays.KeyBinding;
using osuTK.Input;
2018-04-13 17:19:50 +08:00
2019-03-25 00:02:36 +08:00
namespace osu.Game.Tests.Visual.Settings
2018-04-13 17:19:50 +08:00
{
[TestFixture]
public class TestSceneKeyBindingPanel : OsuManualInputManagerTestScene
2018-04-13 17:19:50 +08:00
{
private readonly KeyBindingPanel panel;
2018-04-13 17:19:50 +08:00
public TestSceneKeyBindingPanel()
2018-04-13 17:19:50 +08:00
{
Child = panel = new KeyBindingPanel();
2018-04-13 17:19:50 +08:00
}
protected override void LoadComplete()
{
base.LoadComplete();
panel.Show();
2018-04-13 17:19:50 +08:00
}
[Test]
public void TestClickTwiceOnClearButton()
{
KeyBindingRow firstRow = null;
AddStep("click first row", () =>
{
firstRow = panel.ChildrenOfType<KeyBindingRow>().First();
InputManager.MoveMouseTo(firstRow);
InputManager.Click(MouseButton.Left);
});
AddStep("schedule button clicks", () =>
{
var clearButton = firstRow.ChildrenOfType<KeyBindingRow.ClearButton>().Single();
InputManager.MoveMouseTo(clearButton);
int buttonClicks = 0;
ScheduledDelegate clickDelegate = null;
clickDelegate = Scheduler.AddDelayed(() =>
{
2020-11-05 22:41:56 +08:00
InputManager.Click(MouseButton.Left);
if (++buttonClicks == 2)
{
// ReSharper disable once AccessToModifiedClosure
Debug.Assert(clickDelegate != null);
// ReSharper disable once AccessToModifiedClosure
clickDelegate.Cancel();
}
}, 0, true);
});
}
2020-08-03 03:41:35 +08:00
[Test]
public void TestClearButtonOnBindings()
{
KeyBindingRow multiBindingRow = null;
2020-08-03 03:41:35 +08:00
AddStep("click first row with two bindings", () =>
2020-08-03 03:41:35 +08:00
{
multiBindingRow = panel.ChildrenOfType<KeyBindingRow>().First(row => row.Defaults.Count() > 1);
InputManager.MoveMouseTo(multiBindingRow);
2020-08-03 03:41:35 +08:00
InputManager.Click(MouseButton.Left);
});
clickClearButton();
AddAssert("first binding cleared", () => string.IsNullOrEmpty(multiBindingRow.ChildrenOfType<KeyBindingRow.KeyButton>().First().Text.Text));
2020-08-03 03:41:35 +08:00
AddStep("click second binding", () =>
{
var target = multiBindingRow.ChildrenOfType<KeyBindingRow.KeyButton>().ElementAt(1);
2020-08-03 03:41:35 +08:00
InputManager.MoveMouseTo(target);
InputManager.Click(MouseButton.Left);
});
clickClearButton();
AddAssert("second binding cleared", () => string.IsNullOrEmpty(multiBindingRow.ChildrenOfType<KeyBindingRow.KeyButton>().ElementAt(1).Text.Text));
2020-08-03 03:41:35 +08:00
void clickClearButton()
{
AddStep("click clear button", () =>
{
var clearButton = multiBindingRow.ChildrenOfType<KeyBindingRow.ClearButton>().Single();
2020-08-03 03:41:35 +08:00
InputManager.MoveMouseTo(clearButton);
InputManager.Click(MouseButton.Left);
});
}
}
[Test]
public void TestClickRowSelectsFirstBinding()
{
KeyBindingRow multiBindingRow = null;
AddStep("click first row with two bindings", () =>
{
multiBindingRow = panel.ChildrenOfType<KeyBindingRow>().First(row => row.Defaults.Count() > 1);
InputManager.MoveMouseTo(multiBindingRow);
InputManager.Click(MouseButton.Left);
});
AddAssert("first binding selected", () => multiBindingRow.ChildrenOfType<KeyBindingRow.KeyButton>().First().IsBinding);
AddStep("click second binding", () =>
{
var target = multiBindingRow.ChildrenOfType<KeyBindingRow.KeyButton>().ElementAt(1);
InputManager.MoveMouseTo(target);
InputManager.Click(MouseButton.Left);
});
AddStep("click back binding row", () =>
{
multiBindingRow = panel.ChildrenOfType<KeyBindingRow>().ElementAt(10);
InputManager.MoveMouseTo(multiBindingRow);
InputManager.Click(MouseButton.Left);
});
AddAssert("first binding selected", () => multiBindingRow.ChildrenOfType<KeyBindingRow.KeyButton>().First().IsBinding);
}
2018-04-13 17:19:50 +08:00
}
}