Add test for clear button

This commit is contained in:
Joehu
2020-08-02 12:41:35 -07:00
parent b96e32b0bb
commit ba77fa2945
2 changed files with 47 additions and 7 deletions

View File

@ -64,5 +64,45 @@ namespace osu.Game.Tests.Visual.Settings
}, 0, true); }, 0, true);
}); });
} }
[Test]
public void TestClearButtonOnBindings()
{
KeyBindingRow backBindingRow = null;
AddStep("click back binding row", () =>
{
backBindingRow = panel.ChildrenOfType<KeyBindingRow>().ElementAt(10);
InputManager.MoveMouseTo(backBindingRow);
InputManager.Click(MouseButton.Left);
});
clickClearButton();
AddAssert("first binding cleared", () => string.IsNullOrEmpty(backBindingRow.Buttons.First().Text.Text));
AddStep("click second binding", () =>
{
var target = backBindingRow.Buttons.ElementAt(1);
InputManager.MoveMouseTo(target);
InputManager.Click(MouseButton.Left);
});
clickClearButton();
AddAssert("second binding cleared", () => string.IsNullOrEmpty(backBindingRow.Buttons.ElementAt(1).Text.Text));
void clickClearButton()
{
AddStep("click clear button", () =>
{
var clearButton = backBindingRow.ChildrenOfType<KeyBindingRow.ClearButton>().Single();
InputManager.MoveMouseTo(clearButton);
InputManager.Click(MouseButton.Left);
});
}
}
} }
} }

View File

@ -50,7 +50,7 @@ namespace osu.Game.Overlays.KeyBinding
private OsuSpriteText text; private OsuSpriteText text;
private Drawable pressAKey; private Drawable pressAKey;
private FillFlowContainer<KeyButton> buttons; public FillFlowContainer<KeyButton> Buttons;
public IEnumerable<string> FilterTerms => bindings.Select(b => b.KeyCombination.ReadableString()).Prepend((string)text.Text); public IEnumerable<string> FilterTerms => bindings.Select(b => b.KeyCombination.ReadableString()).Prepend((string)text.Text);
@ -93,7 +93,7 @@ namespace osu.Game.Overlays.KeyBinding
Text = action.GetDescription(), Text = action.GetDescription(),
Margin = new MarginPadding(padding), Margin = new MarginPadding(padding),
}, },
buttons = new FillFlowContainer<KeyButton> Buttons = new FillFlowContainer<KeyButton>
{ {
AutoSizeAxes = Axes.Both, AutoSizeAxes = Axes.Both,
Anchor = Anchor.TopRight, Anchor = Anchor.TopRight,
@ -116,7 +116,7 @@ namespace osu.Game.Overlays.KeyBinding
}; };
foreach (var b in bindings) foreach (var b in bindings)
buttons.Add(new KeyButton(b)); Buttons.Add(new KeyButton(b));
} }
public void RestoreDefaults() public void RestoreDefaults()
@ -125,7 +125,7 @@ namespace osu.Game.Overlays.KeyBinding
foreach (var d in Defaults) foreach (var d in Defaults)
{ {
var button = buttons[i++]; var button = Buttons[i++];
button.UpdateKeyCombination(d); button.UpdateKeyCombination(d);
store.Update(button.KeyBinding); store.Update(button.KeyBinding);
} }
@ -187,7 +187,7 @@ namespace osu.Game.Overlays.KeyBinding
if (bindTarget.IsHovered) if (bindTarget.IsHovered)
finalise(); finalise();
else if (buttons.Any(b => b.IsHovered)) else if (Buttons.Any(b => b.IsHovered))
updateBindTarget(); updateBindTarget();
} }
@ -326,7 +326,7 @@ namespace osu.Game.Overlays.KeyBinding
private void updateBindTarget() private void updateBindTarget()
{ {
if (bindTarget != null) bindTarget.IsBinding = false; if (bindTarget != null) bindTarget.IsBinding = false;
bindTarget = buttons.FirstOrDefault(b => b.IsHovered) ?? buttons.FirstOrDefault(); bindTarget = Buttons.FirstOrDefault(b => b.IsHovered) ?? Buttons.FirstOrDefault();
if (bindTarget != null) bindTarget.IsBinding = true; if (bindTarget != null) bindTarget.IsBinding = true;
} }
@ -357,7 +357,7 @@ namespace osu.Game.Overlays.KeyBinding
} }
} }
private class KeyButton : Container public class KeyButton : Container
{ {
public readonly Framework.Input.Bindings.KeyBinding KeyBinding; public readonly Framework.Input.Bindings.KeyBinding KeyBinding;