1
0
mirror of https://github.com/ppy/osu.git synced 2024-11-11 15:07:44 +08:00

Add test coverage for collection items

This commit is contained in:
Salman Ahmed 2022-07-14 03:12:48 +03:00
parent 9ec4fbb86d
commit cb2f0b8c67

View File

@ -17,6 +17,7 @@ using osu.Framework.Platform;
using osu.Framework.Testing;
using osu.Game.Beatmaps;
using osu.Game.Beatmaps.Drawables;
using osu.Game.Collections;
using osu.Game.Database;
using osu.Game.Graphics.Containers;
using osu.Game.Graphics.Cursor;
@ -42,6 +43,10 @@ namespace osu.Game.Tests.Visual.Multiplayer
private BeatmapManager manager;
private RulesetStore rulesets;
private CollectionManager collections;
private BeatmapSetOverlay beatmapOverlay;
private ManageCollectionsDialog manageCollectionsDialog;
[BackgroundDependencyLoader]
private void load(GameHost host, AudioManager audio)
@ -199,12 +204,15 @@ namespace osu.Game.Tests.Visual.Multiplayer
[Test]
public void TestDownloadButtonHiddenWhenBeatmapExists()
{
var beatmap = new TestBeatmap(new OsuRuleset().RulesetInfo).BeatmapInfo;
Live<BeatmapSetInfo> imported = null;
Debug.Assert(beatmap.BeatmapSet != null);
AddStep("import beatmap", () =>
{
var beatmap = new TestBeatmap(new OsuRuleset().RulesetInfo).BeatmapInfo;
AddStep("import beatmap", () => imported = manager.Import(beatmap.BeatmapSet));
Debug.Assert(beatmap.BeatmapSet != null);
imported = manager.Import(beatmap.BeatmapSet);
});
createPlaylistWithBeatmaps(() => imported.PerformRead(s => s.Beatmaps.Detach()));
@ -310,6 +318,8 @@ namespace osu.Game.Tests.Visual.Multiplayer
createPlaylist();
AddAssert("beatmap overlay hidden", () => beatmapOverlay.State.Value == Visibility.Hidden);
moveToItem(0);
AddStep("right click", () => InputManager.Click(MouseButton.Right));
AddAssert("context menu open", () => (contextMenu = this.ChildrenOfType<OsuContextMenu>().SingleOrDefault())?.State == MenuState.Open);
@ -319,7 +329,91 @@ namespace osu.Game.Tests.Visual.Multiplayer
InputManager.MoveMouseTo(contextMenu.ChildrenOfType<DrawableOsuMenuItem>().First());
InputManager.Click(MouseButton.Left);
});
AddAssert("beatmap overlay visible", () => this.ChildrenOfType<BeatmapSetOverlay>().Single().State.Value == Visibility.Visible);
AddAssert("beatmap overlay visible", () => beatmapOverlay.State.Value == Visibility.Visible);
}
[Test]
public void TestContextMenuCollection()
{
OsuContextMenu contextMenu = null;
BeatmapInfo beatmap = null;
Live<BeatmapSetInfo> imported = null;
AddStep("import beatmap", () =>
{
beatmap = new TestBeatmap(new OsuRuleset().RulesetInfo).BeatmapInfo;
Debug.Assert(beatmap.BeatmapSet != null);
imported = manager.Import(beatmap.BeatmapSet);
});
createPlaylistWithBeatmaps(() => imported.PerformRead(s => s.Beatmaps.Detach()));
AddStep("add two collections", () =>
{
collections.Collections.Clear();
collections.Collections.AddRange(new[]
{
new BeatmapCollection { Name = { Value = "Collection #1" }, BeatmapHashes = { beatmap.MD5Hash } },
new BeatmapCollection { Name = { Value = "Collection #2" } },
});
});
moveToItem(0);
AddStep("right click", () => InputManager.Click(MouseButton.Right));
AddAssert("context menu open", () => (contextMenu = this.ChildrenOfType<OsuContextMenu>().SingleOrDefault())?.State == MenuState.Open);
AddStep("select collections", () => InputManager.MoveMouseTo(contextMenu.ChildrenOfType<DrawableOsuMenuItem>().ElementAt(1)));
AddAssert("collection 1 present and beatmap added", () =>
{
var item = (ToggleMenuItem)contextMenu.Items[1].Items[0];
return item.Text.Value == "Collection #1" && item.State.Value;
});
AddAssert("collection 2 present", () =>
{
var item = (ToggleMenuItem)contextMenu.Items[1].Items[1];
return item.Text.Value == "Collection #2" && !item.State.Value;
});
AddStep("select second collection", () =>
{
InputManager.MoveMouseTo(contextMenu.ChildrenOfType<DrawableStatefulMenuItem>().ElementAt(1));
InputManager.Click(MouseButton.Left);
});
AddAssert("beatmap added to second collection", () => collections.Collections[1].BeatmapHashes.Contains(beatmap.MD5Hash));
AddAssert("item state updated", () => ((ToggleMenuItem)contextMenu.Items[1].Items[1]).State.Value);
}
[Test]
public void TestContextMenuManageCollections()
{
OsuContextMenu contextMenu = null;
Live<BeatmapSetInfo> imported = null;
AddStep("import beatmap", () =>
{
var beatmap = new TestBeatmap(new OsuRuleset().RulesetInfo).BeatmapInfo;
Debug.Assert(beatmap.BeatmapSet != null);
imported = manager.Import(beatmap.BeatmapSet);
});
createPlaylistWithBeatmaps(() => imported.PerformRead(s => s.Beatmaps.Detach()));
AddStep("clear collections", () => collections.Collections.Clear());
AddAssert("manage collections dialog hidden", () => manageCollectionsDialog.State.Value == Visibility.Hidden);
moveToItem(0);
AddStep("right click", () => InputManager.Click(MouseButton.Right));
AddAssert("context menu open", () => (contextMenu = this.ChildrenOfType<OsuContextMenu>().SingleOrDefault())?.State == MenuState.Open);
AddStep("select collections", () => InputManager.MoveMouseTo(contextMenu.ChildrenOfType<DrawableOsuMenuItem>().ElementAt(1)));
AddStep("click manage", () =>
{
InputManager.MoveMouseTo(contextMenu.ChildrenOfType<OsuContextMenu>().ElementAt(1).ChildrenOfType<DrawableOsuMenuItem>().Single());
InputManager.Click(MouseButton.Left);
});
AddAssert("manage collections dialog open", () => manageCollectionsDialog.State.Value == Visibility.Visible);
}
private void moveToItem(int index, Vector2? offset = null)
@ -366,17 +460,18 @@ namespace osu.Game.Tests.Visual.Multiplayer
{
AddStep("create playlist", () =>
{
BeatmapSetOverlay beatmapOverlay;
Child = new DependencyProvidingContainer
{
RelativeSizeAxes = Axes.Both,
CachedDependencies = new (Type, object)[]
{
(typeof(BeatmapSetOverlay), beatmapOverlay = new BeatmapSetOverlay()),
(typeof(CollectionManager), collections = new CollectionManager(LocalStorage)),
(typeof(ManageCollectionsDialog), manageCollectionsDialog = new ManageCollectionsDialog()),
},
Children = new Drawable[]
{
collections,
new OsuContextMenuContainer
{
RelativeSizeAxes = Axes.Both,
@ -388,6 +483,7 @@ namespace osu.Game.Tests.Visual.Multiplayer
},
},
beatmapOverlay,
manageCollectionsDialog,
},
};