Fix button input and tests

This commit is contained in:
smoogipoo 2020-09-08 14:36:38 +09:00
parent 8a3c8a6185
commit c2da3d9c84
2 changed files with 36 additions and 45 deletions

View File

@ -109,11 +109,7 @@ namespace osu.Game.Tests.Visual.SongSelect
dropdown.Current.Value = dropdown.ItemSource.ElementAt(1); dropdown.Current.Value = dropdown.ItemSource.ElementAt(1);
}); });
AddStep("expand header", () => addExpandHeaderStep();
{
InputManager.MoveMouseTo(control.ChildrenOfType<CollectionFilterDropdown.CollectionDropdownHeader>().Single());
InputManager.Click(MouseButton.Left);
});
AddStep("change name", () => collectionManager.Collections[0].Name.Value = "First"); AddStep("change name", () => collectionManager.Collections[0].Name.Value = "First");
@ -124,30 +120,24 @@ namespace osu.Game.Tests.Visual.SongSelect
[Test] [Test]
public void TestAllBeatmapFilterDoesNotHaveAddButton() public void TestAllBeatmapFilterDoesNotHaveAddButton()
{ {
AddAssert("'All beatmaps' filter does not have add button", () => !getCollectionDropdownItems().First().ChildrenOfType<IconButton>().Single().IsPresent); addExpandHeaderStep();
AddStep("hover all beatmaps", () => InputManager.MoveMouseTo(getAddOrRemoveButton(0)));
AddAssert("'All beatmaps' filter does not have add button", () => !getAddOrRemoveButton(0).IsPresent);
} }
[Test] [Test]
public void TestCollectionFilterHasAddButton() public void TestCollectionFilterHasAddButton()
{ {
AddStep("expand header", () => addExpandHeaderStep();
{
InputManager.MoveMouseTo(control.ChildrenOfType<CollectionFilterDropdown.CollectionDropdownHeader>().Single());
InputManager.Click(MouseButton.Left);
});
AddStep("add collection", () => collectionManager.Collections.Add(new BeatmapCollection { Name = { Value = "1" } })); AddStep("add collection", () => collectionManager.Collections.Add(new BeatmapCollection { Name = { Value = "1" } }));
AddAssert("collection has add button", () => !getAddOrRemoveButton(0).IsPresent); AddStep("hover collection", () => InputManager.MoveMouseTo(getAddOrRemoveButton(1)));
AddAssert("collection has add button", () => getAddOrRemoveButton(1).IsPresent);
} }
[Test] [Test]
public void TestButtonDisabledAndEnabledWithBeatmapChanges() public void TestButtonDisabledAndEnabledWithBeatmapChanges()
{ {
AddStep("expand header", () => addExpandHeaderStep();
{
InputManager.MoveMouseTo(control.ChildrenOfType<CollectionFilterDropdown.CollectionDropdownHeader>().Single());
InputManager.Click(MouseButton.Left);
});
AddStep("add collection", () => collectionManager.Collections.Add(new BeatmapCollection { Name = { Value = "1" } })); AddStep("add collection", () => collectionManager.Collections.Add(new BeatmapCollection { Name = { Value = "1" } }));
@ -161,45 +151,37 @@ namespace osu.Game.Tests.Visual.SongSelect
[Test] [Test]
public void TestButtonChangesWhenAddedAndRemovedFromCollection() public void TestButtonChangesWhenAddedAndRemovedFromCollection()
{ {
AddStep("expand header", () => addExpandHeaderStep();
{
InputManager.MoveMouseTo(control.ChildrenOfType<CollectionFilterDropdown.CollectionDropdownHeader>().Single());
InputManager.Click(MouseButton.Left);
});
AddStep("select available beatmap", () => Beatmap.Value = beatmapManager.GetWorkingBeatmap(beatmapManager.GetAllUsableBeatmapSets().First().Beatmaps[0])); AddStep("select available beatmap", () => Beatmap.Value = beatmapManager.GetWorkingBeatmap(beatmapManager.GetAllUsableBeatmapSets().First().Beatmaps[0]));
AddStep("add collection", () => collectionManager.Collections.Add(new BeatmapCollection { Name = { Value = "1" } })); AddStep("add collection", () => collectionManager.Collections.Add(new BeatmapCollection { Name = { Value = "1" } }));
AddAssert("button is plus", () => getAddOrRemoveButton(1).Icon.Equals(FontAwesome.Solid.PlusCircle)); AddAssert("button is plus", () => getAddOrRemoveButton(1).Icon.Equals(FontAwesome.Solid.PlusSquare));
AddStep("add beatmap to collection", () => collectionManager.Collections[0].Beatmaps.Add(Beatmap.Value.BeatmapInfo)); AddStep("add beatmap to collection", () => collectionManager.Collections[0].Beatmaps.Add(Beatmap.Value.BeatmapInfo));
AddAssert("button is minus", () => getAddOrRemoveButton(1).Icon.Equals(FontAwesome.Solid.MinusCircle)); AddAssert("button is minus", () => getAddOrRemoveButton(1).Icon.Equals(FontAwesome.Solid.MinusSquare));
AddStep("remove beatmap from collection", () => collectionManager.Collections[0].Beatmaps.Clear()); AddStep("remove beatmap from collection", () => collectionManager.Collections[0].Beatmaps.Clear());
AddAssert("button is plus", () => getAddOrRemoveButton(1).Icon.Equals(FontAwesome.Solid.PlusCircle)); AddAssert("button is plus", () => getAddOrRemoveButton(1).Icon.Equals(FontAwesome.Solid.PlusSquare));
} }
[Test] [Test]
public void TestButtonAddsAndRemovesBeatmap() public void TestButtonAddsAndRemovesBeatmap()
{ {
AddStep("expand header", () => addExpandHeaderStep();
{
InputManager.MoveMouseTo(control.ChildrenOfType<CollectionFilterDropdown.CollectionDropdownHeader>().Single());
InputManager.Click(MouseButton.Left);
});
AddStep("select available beatmap", () => Beatmap.Value = beatmapManager.GetWorkingBeatmap(beatmapManager.GetAllUsableBeatmapSets().First().Beatmaps[0])); AddStep("select available beatmap", () => Beatmap.Value = beatmapManager.GetWorkingBeatmap(beatmapManager.GetAllUsableBeatmapSets().First().Beatmaps[0]));
AddStep("add collection", () => collectionManager.Collections.Add(new BeatmapCollection { Name = { Value = "1" } })); AddStep("add collection", () => collectionManager.Collections.Add(new BeatmapCollection { Name = { Value = "1" } }));
AddAssert("button is plus", () => getAddOrRemoveButton(1).Icon.Equals(FontAwesome.Solid.PlusCircle)); AddAssert("button is plus", () => getAddOrRemoveButton(1).Icon.Equals(FontAwesome.Solid.PlusSquare));
addClickAddOrRemoveButtonStep(1); addClickAddOrRemoveButtonStep(1);
AddAssert("collection contains beatmap", () => collectionManager.Collections[0].Beatmaps.Contains(Beatmap.Value.BeatmapInfo)); AddAssert("collection contains beatmap", () => collectionManager.Collections[0].Beatmaps.Contains(Beatmap.Value.BeatmapInfo));
AddAssert("button is minus", () => getAddOrRemoveButton(1).Icon.Equals(FontAwesome.Solid.MinusCircle)); AddAssert("button is minus", () => getAddOrRemoveButton(1).Icon.Equals(FontAwesome.Solid.MinusSquare));
addClickAddOrRemoveButtonStep(1); addClickAddOrRemoveButtonStep(1);
AddAssert("collection does not contain beatmap", () => !collectionManager.Collections[0].Beatmaps.Contains(Beatmap.Value.BeatmapInfo)); AddAssert("collection does not contain beatmap", () => !collectionManager.Collections[0].Beatmaps.Contains(Beatmap.Value.BeatmapInfo));
AddAssert("button is plus", () => getAddOrRemoveButton(1).Icon.Equals(FontAwesome.Solid.PlusCircle)); AddAssert("button is plus", () => getAddOrRemoveButton(1).Icon.Equals(FontAwesome.Solid.PlusSquare));
} }
private void assertCollectionHeaderDisplays(string collectionName, bool shouldDisplay = true) private void assertCollectionHeaderDisplays(string collectionName, bool shouldDisplay = true)
@ -214,14 +196,17 @@ namespace osu.Game.Tests.Visual.SongSelect
private IconButton getAddOrRemoveButton(int index) private IconButton getAddOrRemoveButton(int index)
=> getCollectionDropdownItems().ElementAt(index).ChildrenOfType<IconButton>().Single(); => getCollectionDropdownItems().ElementAt(index).ChildrenOfType<IconButton>().Single();
private void addClickAddOrRemoveButtonStep(int index) private void addExpandHeaderStep() => AddStep("expand header", () =>
{ {
AddStep("click add or remove button", () => InputManager.MoveMouseTo(control.ChildrenOfType<CollectionFilterDropdown.CollectionDropdownHeader>().Single());
{ InputManager.Click(MouseButton.Left);
InputManager.MoveMouseTo(getAddOrRemoveButton(index)); });
InputManager.Click(MouseButton.Left);
}); private void addClickAddOrRemoveButtonStep(int index) => AddStep("click add or remove button", () =>
} {
InputManager.MoveMouseTo(getAddOrRemoveButton(index));
InputManager.Click(MouseButton.Left);
});
private IEnumerable<Dropdown<CollectionFilter>.DropdownMenu.DrawableDropdownMenuItem> getCollectionDropdownItems() private IEnumerable<Dropdown<CollectionFilter>.DropdownMenu.DrawableDropdownMenuItem> getCollectionDropdownItems()
=> control.ChildrenOfType<CollectionFilterDropdown>().Single().ChildrenOfType<Dropdown<CollectionFilter>.DropdownMenu.DrawableDropdownMenuItem>(); => control.ChildrenOfType<CollectionFilterDropdown>().Single().ChildrenOfType<Dropdown<CollectionFilter>.DropdownMenu.DrawableDropdownMenuItem>();

View File

@ -184,9 +184,7 @@ namespace osu.Game.Screens.Select
Anchor = Anchor.CentreRight, Anchor = Anchor.CentreRight,
Origin = Anchor.CentreRight, Origin = Anchor.CentreRight,
X = -OsuScrollContainer.SCROLL_BAR_HEIGHT, X = -OsuScrollContainer.SCROLL_BAR_HEIGHT,
Scale = new Vector2(0.7f), Scale = new Vector2(0.65f),
AlwaysPresent = true,
Alpha = collectionBeatmaps == null ? 0 : 1,
Action = addOrRemove, Action = addOrRemove,
}); });
} }
@ -204,6 +202,8 @@ namespace osu.Game.Screens.Select
// Although the DrawableMenuItem binds to value changes of the item's text, the item is an internal implementation detail of Dropdown that has no knowledge // Although the DrawableMenuItem binds to value changes of the item's text, the item is an internal implementation detail of Dropdown that has no knowledge
// of the underlying CollectionFilter value and its accompanying name, so the real name has to be copied here. Without this, the collection name wouldn't update when changed. // of the underlying CollectionFilter value and its accompanying name, so the real name has to be copied here. Without this, the collection name wouldn't update when changed.
collectionName.BindValueChanged(name => content.Text = name.NewValue, true); collectionName.BindValueChanged(name => content.Text = name.NewValue, true);
updateButtonVisibility();
} }
protected override bool OnHover(HoverEvent e) protected override bool OnHover(HoverEvent e)
@ -237,7 +237,13 @@ namespace osu.Game.Screens.Select
updateButtonVisibility(); updateButtonVisibility();
} }
private void updateButtonVisibility() => addOrRemoveButton.Alpha = IsHovered || IsPreSelected || beatmapInCollection ? 1 : 0; private void updateButtonVisibility()
{
if (collectionBeatmaps == null)
addOrRemoveButton.Alpha = 0;
else
addOrRemoveButton.Alpha = IsHovered || IsPreSelected || beatmapInCollection ? 1 : 0;
}
private void addOrRemove() private void addOrRemove()
{ {