mirror of
https://github.com/ppy/osu
synced 2024-12-28 18:02:53 +00:00
Add test coverage
This commit is contained in:
parent
62b6cadb64
commit
37f6ceef79
@ -6,6 +6,7 @@ using System.Linq;
|
||||
using NUnit.Framework;
|
||||
using osu.Framework.Testing;
|
||||
using osu.Framework.Threading;
|
||||
using osu.Game.Graphics.Sprites;
|
||||
using osu.Game.Overlays;
|
||||
using osu.Game.Overlays.KeyBinding;
|
||||
using osuTK.Input;
|
||||
@ -28,6 +29,39 @@ namespace osu.Game.Tests.Visual.Settings
|
||||
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]
|
||||
public void TestClickTwiceOnClearButton()
|
||||
{
|
||||
@ -135,5 +169,37 @@ namespace osu.Game.Tests.Visual.Settings
|
||||
|
||||
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 };
|
||||
}
|
||||
|
||||
protected class SettingsSectionsContainer : SectionsContainer<SettingsSection>
|
||||
public class SettingsSectionsContainer : SectionsContainer<SettingsSection>
|
||||
{
|
||||
public SearchContainer<SettingsSection> SearchContainer;
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user