diff --git a/osu.Game.Tests/Visual/Collections/TestSceneManageCollectionsDialog.cs b/osu.Game.Tests/Visual/Collections/TestSceneManageCollectionsDialog.cs index fdaded6a5c..0c57c27911 100644 --- a/osu.Game.Tests/Visual/Collections/TestSceneManageCollectionsDialog.cs +++ b/osu.Game.Tests/Visual/Collections/TestSceneManageCollectionsDialog.cs @@ -7,11 +7,14 @@ using osu.Framework.Graphics; using osu.Framework.Graphics.Containers; using osu.Framework.Graphics.UserInterface; +using osu.Framework.Platform; using osu.Framework.Testing; +using osu.Game.Beatmaps; using osu.Game.Collections; -using osu.Game.Graphics.UserInterface; using osu.Game.Overlays; using osu.Game.Overlays.Dialog; +using osu.Game.Rulesets; +using osu.Game.Tests.Resources; using osuTK; using osuTK.Input; @@ -25,6 +28,9 @@ public class TestSceneManageCollectionsDialog : OsuManualInputManagerTestScene private readonly DialogOverlay dialogOverlay; private readonly BeatmapCollectionManager manager; + private RulesetStore rulesets; + private BeatmapManager beatmapManager; + private ManageCollectionsDialog dialog; public TestSceneManageCollectionsDialog() @@ -37,6 +43,15 @@ public TestSceneManageCollectionsDialog() }); } + [BackgroundDependencyLoader] + private void load(GameHost host) + { + Dependencies.Cache(rulesets = new RulesetStore(ContextFactory)); + Dependencies.Cache(beatmapManager = new BeatmapManager(LocalStorage, ContextFactory, rulesets, null, Audio, host, Beatmap.Default)); + + beatmapManager.Import(TestResources.GetTestBeatmapForImport()).Wait(); + } + protected override IReadOnlyDependencyContainer CreateChildDependencies(IReadOnlyDependencyContainer parent) { var dependencies = new DependencyContainer(base.CreateChildDependencies(parent)); @@ -65,6 +80,12 @@ public void TestHideDialog() AddStep("hide dialog", () => dialog.Hide()); } + [Test] + public void TestLastItemIsPlaceholder() + { + AddAssert("last item is placeholder", () => !manager.Collections.Contains(dialog.ChildrenOfType().Last().Model)); + } + [Test] public void TestAddCollectionExternal() { @@ -78,23 +99,34 @@ public void TestAddCollectionExternal() } [Test] - public void TestAddCollectionViaButton() + public void TestFocusPlaceholderDoesNotCreateCollection() { - AddStep("press new collection button", () => + AddStep("focus placeholder", () => { - InputManager.MoveMouseTo(dialog.ChildrenOfType().Single()); + InputManager.MoveMouseTo(dialog.ChildrenOfType().Last()); InputManager.Click(MouseButton.Left); }); + assertCollectionCount(0); + } + + [Test] + public void TestAddCollectionViaPlaceholder() + { + DrawableCollectionListItem placeholderItem = null; + + AddStep("focus placeholder", () => + { + InputManager.MoveMouseTo(placeholderItem = dialog.ChildrenOfType().Last()); + InputManager.Click(MouseButton.Left); + }); + + // Done directly via the collection since InputManager methods cannot add text to textbox... + AddStep("change collection name", () => placeholderItem.Model.Name.Value = "a"); assertCollectionCount(1); + AddAssert("collection now exists", () => manager.Collections.Contains(placeholderItem.Model)); - AddStep("press again", () => - { - InputManager.MoveMouseTo(dialog.ChildrenOfType().Single()); - InputManager.Click(MouseButton.Left); - }); - - assertCollectionCount(2); + AddAssert("last item is placeholder", () => !manager.Collections.Contains(dialog.ChildrenOfType().Last().Model)); } [Test] @@ -117,7 +149,7 @@ public void TestRemoveCollectionViaButton() AddStep("add two collections", () => manager.Collections.AddRange(new[] { new BeatmapCollection { Name = { Value = "1" } }, - new BeatmapCollection { Name = { Value = "2" } }, + new BeatmapCollection { Name = { Value = "2" }, Beatmaps = { beatmapManager.GetAllUsableBeatmapSets().First().Beatmaps[0] } }, })); assertCollectionCount(2); @@ -128,6 +160,16 @@ public void TestRemoveCollectionViaButton() InputManager.Click(MouseButton.Left); }); + AddAssert("dialog not displayed", () => dialogOverlay.CurrentDialog == null); + assertCollectionCount(1); + assertCollectionName(0, "2"); + + AddStep("click first delete button", () => + { + InputManager.MoveMouseTo(dialog.ChildrenOfType().First(), new Vector2(5, 0)); + InputManager.Click(MouseButton.Left); + }); + AddAssert("dialog displayed", () => dialogOverlay.CurrentDialog is DeleteCollectionDialog); AddStep("click confirmation", () => { @@ -135,8 +177,7 @@ public void TestRemoveCollectionViaButton() InputManager.Click(MouseButton.Left); }); - assertCollectionCount(1); - assertCollectionName(0, "2"); + assertCollectionCount(0); } [Test] @@ -144,11 +185,10 @@ public void TestCollectionNotRemovedWhenDialogCancelled() { AddStep("add two collections", () => manager.Collections.AddRange(new[] { - new BeatmapCollection { Name = { Value = "1" } }, - new BeatmapCollection { Name = { Value = "2" } }, + new BeatmapCollection { Name = { Value = "1" }, Beatmaps = { beatmapManager.GetAllUsableBeatmapSets().First().Beatmaps[0] } }, })); - assertCollectionCount(2); + assertCollectionCount(1); AddStep("click first delete button", () => { @@ -157,13 +197,13 @@ public void TestCollectionNotRemovedWhenDialogCancelled() }); AddAssert("dialog displayed", () => dialogOverlay.CurrentDialog is DeleteCollectionDialog); - AddStep("click confirmation", () => + AddStep("click cancellation", () => { InputManager.MoveMouseTo(dialogOverlay.CurrentDialog.ChildrenOfType().Last()); InputManager.Click(MouseButton.Left); }); - assertCollectionCount(2); + assertCollectionCount(1); } [Test] @@ -196,7 +236,7 @@ public void TestCollectionRenamedOnTextChange() } private void assertCollectionCount(int count) - => AddUntilStep($"{count} collections shown", () => dialog.ChildrenOfType().Count() == count); + => AddUntilStep($"{count} collections shown", () => dialog.ChildrenOfType().Count(i => i.IsCreated.Value) == count); private void assertCollectionName(int index, string name) => AddUntilStep($"item {index + 1} has correct name", () => dialog.ChildrenOfType().ElementAt(index).ChildrenOfType().First().Text == name); diff --git a/osu.Game.Tests/Visual/SongSelect/TestSceneFilterControl.cs b/osu.Game.Tests/Visual/SongSelect/TestSceneFilterControl.cs index 65b554b27b..4606c7b0c3 100644 --- a/osu.Game.Tests/Visual/SongSelect/TestSceneFilterControl.cs +++ b/osu.Game.Tests/Visual/SongSelect/TestSceneFilterControl.cs @@ -42,13 +42,6 @@ public TestSceneFilterControl() }); } - protected override IReadOnlyDependencyContainer CreateChildDependencies(IReadOnlyDependencyContainer parent) - { - var dependencies = new DependencyContainer(base.CreateChildDependencies(parent)); - dependencies.Cache(collectionManager); - return dependencies; - } - [BackgroundDependencyLoader] private void load(GameHost host) { @@ -58,6 +51,13 @@ private void load(GameHost host) beatmapManager.Import(TestResources.GetTestBeatmapForImport()).Wait(); } + protected override IReadOnlyDependencyContainer CreateChildDependencies(IReadOnlyDependencyContainer parent) + { + var dependencies = new DependencyContainer(base.CreateChildDependencies(parent)); + dependencies.Cache(collectionManager); + return dependencies; + } + [SetUp] public void SetUp() => Schedule(() => { diff --git a/osu.Game/Collections/DrawableCollectionListItem.cs b/osu.Game/Collections/DrawableCollectionListItem.cs index c67946977d..a7075c3179 100644 --- a/osu.Game/Collections/DrawableCollectionListItem.cs +++ b/osu.Game/Collections/DrawableCollectionListItem.cs @@ -27,6 +27,11 @@ public class DrawableCollectionListItem : OsuRearrangeableListItem + /// Whether the currently exists inside the . + /// + public IBindable IsCreated => isCreated; + private readonly Bindable isCreated = new Bindable(); ///