mirror of
https://github.com/osukey/osukey.git
synced 2025-07-02 00:40:09 +09:00
Add test coverage
This commit is contained in:
@ -6,6 +6,7 @@ using System.Linq;
|
|||||||
using NUnit.Framework;
|
using NUnit.Framework;
|
||||||
using osu.Framework.Testing;
|
using osu.Framework.Testing;
|
||||||
using osu.Framework.Threading;
|
using osu.Framework.Threading;
|
||||||
|
using osu.Game.Graphics.Sprites;
|
||||||
using osu.Game.Overlays;
|
using osu.Game.Overlays;
|
||||||
using osu.Game.Overlays.KeyBinding;
|
using osu.Game.Overlays.KeyBinding;
|
||||||
using osuTK.Input;
|
using osuTK.Input;
|
||||||
@ -28,6 +29,39 @@ namespace osu.Game.Tests.Visual.Settings
|
|||||||
panel.Show();
|
panel.Show();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
[SetUpSteps]
|
||||||
|
public void SetUpSteps()
|
||||||
|
{
|
||||||
|
AddStep("Scroll to top", () => panel.ChildrenOfType<SettingsPanel.SettingsSectionsContainer>().First().ScrollToTop());
|
||||||
|
AddWaitStep("wait for scroll", 5);
|
||||||
|
}
|
||||||
|
|
||||||
|
[Test]
|
||||||
|
public void TestBindingMouseWheelToNonGameplay()
|
||||||
|
{
|
||||||
|
scrollToAndStartBinding("Increase volume");
|
||||||
|
AddStep("press k", () => InputManager.Key(Key.K));
|
||||||
|
checkBinding("Increase volume", "K");
|
||||||
|
|
||||||
|
AddStep("click again", () => InputManager.Click(MouseButton.Left));
|
||||||
|
AddStep("scroll mouse wheel", () => InputManager.ScrollVerticalBy(1));
|
||||||
|
|
||||||
|
checkBinding("Increase volume", "Wheel Up");
|
||||||
|
}
|
||||||
|
|
||||||
|
[Test]
|
||||||
|
public void TestBindingMouseWheelToGameplay()
|
||||||
|
{
|
||||||
|
scrollToAndStartBinding("Left button");
|
||||||
|
AddStep("press k", () => InputManager.Key(Key.Z));
|
||||||
|
checkBinding("Left button", "Z");
|
||||||
|
|
||||||
|
AddStep("click again", () => InputManager.Click(MouseButton.Left));
|
||||||
|
AddStep("scroll mouse wheel", () => InputManager.ScrollVerticalBy(1));
|
||||||
|
|
||||||
|
checkBinding("Left button", "Z");
|
||||||
|
}
|
||||||
|
|
||||||
[Test]
|
[Test]
|
||||||
public void TestClickTwiceOnClearButton()
|
public void TestClickTwiceOnClearButton()
|
||||||
{
|
{
|
||||||
@ -135,5 +169,37 @@ namespace osu.Game.Tests.Visual.Settings
|
|||||||
|
|
||||||
AddAssert("first binding selected", () => multiBindingRow.ChildrenOfType<KeyBindingRow.KeyButton>().First().IsBinding);
|
AddAssert("first binding selected", () => multiBindingRow.ChildrenOfType<KeyBindingRow.KeyButton>().First().IsBinding);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private void checkBinding(string name, string keyName)
|
||||||
|
{
|
||||||
|
AddAssert($"Check {name} is bound to {keyName}", () =>
|
||||||
|
{
|
||||||
|
var firstRow = panel.ChildrenOfType<KeyBindingRow>().First(r => r.ChildrenOfType<OsuSpriteText>().Any(s => s.Text == name));
|
||||||
|
var firstButton = firstRow.ChildrenOfType<KeyBindingRow.KeyButton>().First();
|
||||||
|
|
||||||
|
return firstButton.Text.Text == keyName;
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
private void scrollToAndStartBinding(string name)
|
||||||
|
{
|
||||||
|
KeyBindingRow.KeyButton firstButton = null;
|
||||||
|
|
||||||
|
AddStep($"Scroll to {name}", () =>
|
||||||
|
{
|
||||||
|
var firstRow = panel.ChildrenOfType<KeyBindingRow>().First(r => r.ChildrenOfType<OsuSpriteText>().Any(s => s.Text == name));
|
||||||
|
firstButton = firstRow.ChildrenOfType<KeyBindingRow.KeyButton>().First();
|
||||||
|
|
||||||
|
panel.ChildrenOfType<SettingsPanel.SettingsSectionsContainer>().First().ScrollTo(firstButton);
|
||||||
|
});
|
||||||
|
|
||||||
|
AddWaitStep("wait for scroll", 5);
|
||||||
|
|
||||||
|
AddStep("click to bind", () =>
|
||||||
|
{
|
||||||
|
InputManager.MoveMouseTo(firstButton);
|
||||||
|
InputManager.Click(MouseButton.Left);
|
||||||
|
});
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -191,7 +191,7 @@ namespace osu.Game.Overlays
|
|||||||
Padding = new MarginPadding { Top = GetToolbarHeight?.Invoke() ?? 0 };
|
Padding = new MarginPadding { Top = GetToolbarHeight?.Invoke() ?? 0 };
|
||||||
}
|
}
|
||||||
|
|
||||||
protected class SettingsSectionsContainer : SectionsContainer<SettingsSection>
|
public class SettingsSectionsContainer : SectionsContainer<SettingsSection>
|
||||||
{
|
{
|
||||||
public SearchContainer<SettingsSection> SearchContainer;
|
public SearchContainer<SettingsSection> SearchContainer;
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user