mirror of
https://github.com/ppy/osu.git
synced 2026-05-29 23:51:01 +08:00
Fix tests
This commit is contained in:
+18
-26
@@ -9,9 +9,7 @@ using osu.Framework.Audio;
|
||||
using osu.Framework.Bindables;
|
||||
using osu.Framework.Extensions.ObjectExtensions;
|
||||
using osu.Framework.Graphics.Containers;
|
||||
using osu.Framework.Graphics.Sprites;
|
||||
using osu.Framework.Platform;
|
||||
using osu.Framework.Screens;
|
||||
using osu.Framework.Testing;
|
||||
using osu.Framework.Utils;
|
||||
using osu.Game.Beatmaps;
|
||||
@@ -22,7 +20,6 @@ using osu.Game.Rulesets.Mods;
|
||||
using osu.Game.Rulesets.Osu;
|
||||
using osu.Game.Rulesets.Osu.Mods;
|
||||
using osu.Game.Screens.OnlinePlay;
|
||||
using osu.Game.Screens.OnlinePlay.Components;
|
||||
using osu.Game.Screens.OnlinePlay.Playlists;
|
||||
using osu.Game.Tests.Resources;
|
||||
using osu.Game.Tests.Visual.OnlinePlay;
|
||||
@@ -30,7 +27,7 @@ using osuTK.Input;
|
||||
|
||||
namespace osu.Game.Tests.Visual.Multiplayer
|
||||
{
|
||||
public partial class TestScenePlaylistsSongSelect : OnlinePlayTestScene
|
||||
public partial class TestScenePlaylistsSongSelectV2 : OnlinePlayTestScene
|
||||
{
|
||||
private RulesetStore rulesets = null!;
|
||||
private BeatmapManager manager = null!;
|
||||
@@ -69,47 +66,47 @@ namespace osu.Game.Tests.Visual.Multiplayer
|
||||
});
|
||||
|
||||
AddStep("create song select", () => LoadScreen(songSelect = new TestPlaylistsSongSelect(room)));
|
||||
AddUntilStep("wait for present", () => songSelect.IsCurrentScreen() && songSelect.BeatmapSetsLoaded);
|
||||
AddUntilStep("wait for song select", () => songSelect.IsLoaded && !songSelect.IsFiltering);
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void TestItemAddedIfEmptyOnStart()
|
||||
{
|
||||
AddStep("finalise selection", () => songSelect.FinaliseSelection());
|
||||
AddStep("finalise selection", () => InputManager.Key(Key.Enter));
|
||||
AddAssert("playlist has 1 item", () => room.Playlist.Count == 1);
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void TestItemAddedWhenCreateNewItemClicked()
|
||||
{
|
||||
AddStep("create new item", () => songSelect.BeatmapDetails.CreateNewItem!());
|
||||
AddStep("create new item", () => songSelect.AddNewItem());
|
||||
AddAssert("playlist has 1 item", () => room.Playlist.Count == 1);
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void TestItemNotAddedIfExistingOnStart()
|
||||
{
|
||||
AddStep("create new item", () => songSelect.BeatmapDetails.CreateNewItem!());
|
||||
AddStep("finalise selection", () => songSelect.FinaliseSelection());
|
||||
AddStep("create new item", () => songSelect.AddNewItem());
|
||||
AddStep("finalise selection", () => InputManager.Key(Key.Enter));
|
||||
AddAssert("playlist has 1 item", () => room.Playlist.Count == 1);
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void TestAddSameItemMultipleTimes()
|
||||
{
|
||||
AddStep("create new item", () => songSelect.BeatmapDetails.CreateNewItem!());
|
||||
AddStep("create new item", () => songSelect.BeatmapDetails.CreateNewItem!());
|
||||
AddStep("create new item", () => songSelect.AddNewItem());
|
||||
AddStep("create new item", () => songSelect.AddNewItem());
|
||||
AddAssert("playlist has 2 items", () => room.Playlist.Count == 2);
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void TestAddItemAfterRearrangement()
|
||||
{
|
||||
AddStep("create new item", () => songSelect.BeatmapDetails.CreateNewItem!());
|
||||
AddStep("create new item", () => songSelect.BeatmapDetails.CreateNewItem!());
|
||||
AddStep("create new item", () => songSelect.AddNewItem());
|
||||
AddStep("create new item", () => songSelect.AddNewItem());
|
||||
AddStep("rearrange", () => room.Playlist = room.Playlist.Skip(1).Append(room.Playlist[0]).ToArray());
|
||||
|
||||
AddStep("create new item", () => songSelect.BeatmapDetails.CreateNewItem!());
|
||||
AddStep("create new item", () => songSelect.AddNewItem());
|
||||
AddAssert("new item has id 2", () => room.Playlist.Last().ID == 2);
|
||||
}
|
||||
|
||||
@@ -120,9 +117,9 @@ namespace osu.Game.Tests.Visual.Multiplayer
|
||||
public void TestNewItemHasNewModInstances()
|
||||
{
|
||||
AddStep("set dt mod", () => SelectedMods.Value = new[] { new OsuModDoubleTime() });
|
||||
AddStep("create item", () => songSelect.BeatmapDetails.CreateNewItem!());
|
||||
AddStep("create item", () => songSelect.AddNewItem());
|
||||
AddStep("change mod rate", () => ((OsuModDoubleTime)SelectedMods.Value[0]).SpeedChange.Value = 2);
|
||||
AddStep("create item", () => songSelect.BeatmapDetails.CreateNewItem!());
|
||||
AddStep("create item", () => songSelect.AddNewItem());
|
||||
|
||||
AddAssert("item 1 has rate 1.5", () =>
|
||||
{
|
||||
@@ -153,7 +150,7 @@ namespace osu.Game.Tests.Visual.Multiplayer
|
||||
mod = (OsuModDoubleTime)SelectedMods.Value[0];
|
||||
});
|
||||
|
||||
AddStep("create item", () => songSelect.BeatmapDetails.CreateNewItem!());
|
||||
AddStep("create item", () => songSelect.AddNewItem());
|
||||
|
||||
AddStep("change stored mod rate", () => mod.SpeedChange.Value = 2);
|
||||
AddAssert("item has rate 1.5", () =>
|
||||
@@ -166,26 +163,23 @@ namespace osu.Game.Tests.Visual.Multiplayer
|
||||
[Test]
|
||||
public void TestFreeModSelectionDisable()
|
||||
{
|
||||
FooterButtonFreeMods freeMods = null!;
|
||||
|
||||
AddAssert("freestyle enabled", () => songSelect.Freestyle.Value, () => Is.True);
|
||||
AddStep("click icon in free mods button", () =>
|
||||
{
|
||||
freeMods = this.ChildrenOfType<FooterButtonFreeMods>().Single();
|
||||
InputManager.MoveMouseTo(freeMods.ChildrenOfType<SpriteIcon>().Single());
|
||||
InputManager.MoveMouseTo(this.ChildrenOfType<FooterButtonFreeModsV2>().Single());
|
||||
InputManager.Click(MouseButton.Left);
|
||||
});
|
||||
AddAssert("mod select not visible", () => this.ChildrenOfType<FreeModSelectOverlay>().Single().State.Value, () => Is.EqualTo(Visibility.Hidden));
|
||||
|
||||
AddStep("toggle freestyle off", () =>
|
||||
{
|
||||
InputManager.MoveMouseTo(this.ChildrenOfType<FooterButtonFreestyle>().Single());
|
||||
InputManager.MoveMouseTo(this.ChildrenOfType<FooterButtonFreestyleV2>().Single());
|
||||
InputManager.Click(MouseButton.Left);
|
||||
});
|
||||
AddAssert("freestyle disabled", () => songSelect.Freestyle.Value, () => Is.False);
|
||||
AddStep("click icon in free mods button", () =>
|
||||
{
|
||||
InputManager.MoveMouseTo(freeMods.ChildrenOfType<SpriteIcon>().Single());
|
||||
InputManager.MoveMouseTo(this.ChildrenOfType<FooterButtonFreeModsV2>().Single());
|
||||
InputManager.Click(MouseButton.Left);
|
||||
});
|
||||
AddAssert("mod select visible", () => this.ChildrenOfType<FreeModSelectOverlay>().Single().State.Value, () => Is.EqualTo(Visibility.Visible));
|
||||
@@ -199,10 +193,8 @@ namespace osu.Game.Tests.Visual.Multiplayer
|
||||
rulesets.Dispose();
|
||||
}
|
||||
|
||||
private partial class TestPlaylistsSongSelect : PlaylistsSongSelect
|
||||
private partial class TestPlaylistsSongSelect : PlaylistsSongSelectV2
|
||||
{
|
||||
public new MatchBeatmapDetailArea BeatmapDetails => (MatchBeatmapDetailArea)base.BeatmapDetails;
|
||||
|
||||
public new IBindable<bool> Freestyle => base.Freestyle;
|
||||
|
||||
public TestPlaylistsSongSelect(Room room)
|
||||
@@ -92,7 +92,7 @@ namespace osu.Game.Tests.Visual.Navigation
|
||||
|
||||
AddStep("edit playlist", () => InputManager.Key(Key.Enter));
|
||||
|
||||
AddUntilStep("wait for song select", () => (playlistScreen.CurrentSubScreen as PlaylistsSongSelect)?.BeatmapSetsLoaded == true);
|
||||
AddUntilStep("wait for song select", () => playlistScreen.CurrentSubScreen is PlaylistsSongSelectV2 songSelect && songSelect.IsLoaded && !songSelect.IsFiltering);
|
||||
|
||||
AddUntilStep("wait for selection", () => !Game.Beatmap.IsDefault);
|
||||
|
||||
@@ -106,7 +106,7 @@ namespace osu.Game.Tests.Visual.Navigation
|
||||
InputManager.Click(MouseButton.Left);
|
||||
});
|
||||
|
||||
AddUntilStep("wait for song select", () => (playlistScreen.CurrentSubScreen as PlaylistsSongSelect)?.BeatmapSetsLoaded == true);
|
||||
AddUntilStep("wait for song select", () => playlistScreen.CurrentSubScreen is PlaylistsSongSelectV2 songSelect && songSelect.IsLoaded && !songSelect.IsFiltering);
|
||||
|
||||
AddStep("press home button", () =>
|
||||
{
|
||||
|
||||
@@ -1,90 +0,0 @@
|
||||
// Copyright (c) ppy Pty Ltd <contact@ppy.sh>. Licensed under the MIT Licence.
|
||||
// See the LICENCE file in the repository root for full licence text.
|
||||
|
||||
using System;
|
||||
using System.Linq;
|
||||
using osu.Framework.Allocation;
|
||||
using osu.Framework.Audio;
|
||||
using osu.Framework.Extensions.ObjectExtensions;
|
||||
using osu.Framework.Platform;
|
||||
using osu.Framework.Testing;
|
||||
using osu.Game.Beatmaps;
|
||||
using osu.Game.Configuration;
|
||||
using osu.Game.Database;
|
||||
using osu.Game.Online.Rooms;
|
||||
using osu.Game.Rulesets;
|
||||
using osu.Game.Scoring;
|
||||
using osu.Game.Screens.OnlinePlay.Playlists;
|
||||
using osu.Game.Screens.SelectV2;
|
||||
using osu.Game.Tests.Resources;
|
||||
using osu.Game.Tests.Visual.OnlinePlay;
|
||||
|
||||
namespace osu.Game.Tests.Visual.Playlists
|
||||
{
|
||||
public class TestScenePlaylistsSongSelectV2 : OnlinePlayTestScene
|
||||
{
|
||||
private BeatmapManager beatmaps = null!;
|
||||
private RealmRulesetStore rulesets = null!;
|
||||
private OsuConfigManager config = null!;
|
||||
private ScoreManager scoreManager = null!;
|
||||
private RealmDetachedBeatmapStore beatmapStore = null!;
|
||||
|
||||
private PlaylistsSongSelectV2 songSelect = null!;
|
||||
|
||||
private BeatmapCarousel Carousel => songSelect.ChildrenOfType<BeatmapCarousel>().Single();
|
||||
|
||||
protected override IReadOnlyDependencyContainer CreateChildDependencies(IReadOnlyDependencyContainer parent)
|
||||
{
|
||||
var dependencies = new DependencyContainer(base.CreateChildDependencies(parent));
|
||||
|
||||
// These DI caches are required to ensure for interactive runs this test scene doesn't nuke all user beatmaps in the local install.
|
||||
// At a point we have isolated interactive test runs enough, this can likely be removed.
|
||||
dependencies.Cache(rulesets = new RealmRulesetStore(Realm));
|
||||
dependencies.Cache(Realm);
|
||||
dependencies.Cache(beatmaps = new BeatmapManager(LocalStorage, Realm, null, Dependencies.Get<AudioManager>(), Resources, Dependencies.Get<GameHost>(), Beatmap.Default));
|
||||
dependencies.Cache(config = new OsuConfigManager(LocalStorage));
|
||||
dependencies.Cache(scoreManager = new ScoreManager(rulesets, () => beatmaps, LocalStorage, Realm, API, config));
|
||||
|
||||
dependencies.CacheAs<BeatmapStore>(beatmapStore = new RealmDetachedBeatmapStore());
|
||||
|
||||
return dependencies;
|
||||
}
|
||||
|
||||
[BackgroundDependencyLoader]
|
||||
private void load()
|
||||
{
|
||||
Add(beatmapStore);
|
||||
}
|
||||
|
||||
public override void SetUpSteps()
|
||||
{
|
||||
base.SetUpSteps();
|
||||
|
||||
ImportBeatmapForRuleset(0);
|
||||
|
||||
AddStep("load screen", () => LoadScreen(songSelect = new PlaylistsSongSelectV2(new Room())));
|
||||
AddUntilStep("wait for load", () => Stack.CurrentScreen == songSelect && songSelect.IsLoaded);
|
||||
AddUntilStep("wait for filtering", () => !Carousel.IsFiltering);
|
||||
}
|
||||
|
||||
protected void ImportBeatmapForRuleset(params int[] rulesetIds) => ImportBeatmapForRuleset(_ => { }, 3, rulesetIds);
|
||||
|
||||
protected void ImportBeatmapForRuleset(Action<BeatmapSetInfo> applyToBeatmap, int difficultyCount, params int[] rulesetIds)
|
||||
{
|
||||
int beatmapsCount = 0;
|
||||
|
||||
AddStep($"import test map for ruleset {rulesetIds}", () =>
|
||||
{
|
||||
beatmapsCount = songSelect.IsNull() ? 0 : Carousel.Filters.OfType<BeatmapCarouselFilterGrouping>().Single().SetItems.Count;
|
||||
|
||||
var beatmapSet = TestResources.CreateTestBeatmapSetInfo(difficultyCount, rulesets.AvailableRulesets.Where(r => rulesetIds.Contains(r.OnlineID)).ToArray());
|
||||
applyToBeatmap(beatmapSet);
|
||||
beatmaps.Import(beatmapSet);
|
||||
});
|
||||
|
||||
// This is specifically for cases where the add is happening post song select load.
|
||||
// For cases where song select is null, the assertions are provided by the load checks.
|
||||
AddUntilStep("wait for imported to arrive in carousel", () => songSelect.IsNull() || Carousel.Filters.OfType<BeatmapCarouselFilterGrouping>().Single().SetItems.Count > beatmapsCount);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -21,8 +21,8 @@ namespace osu.Game.Screens.OnlinePlay.Playlists
|
||||
{
|
||||
public class PlaylistsSongSelectV2 : SongSelect
|
||||
{
|
||||
protected readonly Bindable<bool> Freestyle = new Bindable<bool>(true);
|
||||
private readonly Bindable<IReadOnlyList<Mod>> freeMods = new Bindable<IReadOnlyList<Mod>>([]);
|
||||
private readonly Bindable<bool> freestyle = new Bindable<bool>(true);
|
||||
|
||||
private readonly Room room;
|
||||
private ModSelectOverlay modSelect = null!;
|
||||
@@ -49,11 +49,16 @@ namespace osu.Game.Screens.OnlinePlay.Playlists
|
||||
|
||||
Mods.BindValueChanged(onGlobalModsChanged);
|
||||
Ruleset.BindValueChanged(onRulesetChanged);
|
||||
freestyle.BindValueChanged(onFreestyleChanged);
|
||||
Freestyle.BindValueChanged(onFreestyleChanged);
|
||||
|
||||
updateValidMods();
|
||||
}
|
||||
|
||||
public void AddNewItem()
|
||||
{
|
||||
room.Playlist = room.Playlist.Append(createItem()).ToArray();
|
||||
}
|
||||
|
||||
private void onGlobalModsChanged(ValueChangedEvent<IReadOnlyList<Mod>> mods)
|
||||
{
|
||||
updateValidMods();
|
||||
@@ -106,7 +111,7 @@ namespace osu.Game.Screens.OnlinePlay.Playlists
|
||||
|
||||
protected override void OnStart()
|
||||
{
|
||||
room.Playlist = [createNewItem()];
|
||||
room.Playlist = [createItem()];
|
||||
this.Exit();
|
||||
}
|
||||
|
||||
@@ -118,7 +123,7 @@ namespace osu.Game.Screens.OnlinePlay.Playlists
|
||||
|
||||
buttons.Insert(0, new FooterButtonPlaylistV2(room)
|
||||
{
|
||||
CreateNewItem = () => room.Playlist = room.Playlist.Append(createNewItem()).ToArray()
|
||||
CreateNewItem = AddNewItem
|
||||
});
|
||||
|
||||
buttons.InsertRange(buttons.FindIndex(b => b is FooterButtonMods) + 1,
|
||||
@@ -126,11 +131,11 @@ namespace osu.Game.Screens.OnlinePlay.Playlists
|
||||
new FooterButtonFreeModsV2(freeModSelect)
|
||||
{
|
||||
FreeMods = { BindTarget = freeMods },
|
||||
Freestyle = { BindTarget = freestyle }
|
||||
Freestyle = { BindTarget = Freestyle }
|
||||
},
|
||||
new FooterButtonFreestyleV2
|
||||
{
|
||||
Freestyle = { BindTarget = freestyle }
|
||||
Freestyle = { BindTarget = Freestyle }
|
||||
}
|
||||
]);
|
||||
|
||||
@@ -142,26 +147,26 @@ namespace osu.Game.Screens.OnlinePlay.Playlists
|
||||
IsValidMod = isValidRequiredMod
|
||||
};
|
||||
|
||||
private PlaylistItem createNewItem() => new PlaylistItem(Beatmap.Value.BeatmapInfo)
|
||||
private PlaylistItem createItem() => new PlaylistItem(Beatmap.Value.BeatmapInfo)
|
||||
{
|
||||
ID = room.Playlist.Count == 0 ? 0 : room.Playlist.Max(p => p.ID) + 1,
|
||||
RulesetID = Ruleset.Value.OnlineID,
|
||||
RequiredMods = Mods.Value.Select(m => new APIMod(m)).ToArray(),
|
||||
AllowedMods = freeMods.Value.Select(m => new APIMod(m)).ToArray(),
|
||||
Freestyle = freestyle.Value
|
||||
Freestyle = Freestyle.Value
|
||||
};
|
||||
|
||||
/// <summary>
|
||||
/// Checks whether a given <see cref="Mod"/> is valid to be selected as a required mod.
|
||||
/// </summary>
|
||||
/// <param name="mod">The <see cref="Mod"/> to check.</param>
|
||||
private bool isValidRequiredMod(Mod mod) => ModUtils.IsValidModForMatch(mod, true, room.Type, freestyle.Value);
|
||||
private bool isValidRequiredMod(Mod mod) => ModUtils.IsValidModForMatch(mod, true, room.Type, Freestyle.Value);
|
||||
|
||||
/// <summary>
|
||||
/// Checks whether a given <see cref="Mod"/> is valid to be selected as an allowed mod.
|
||||
/// </summary>
|
||||
/// <param name="mod">The <see cref="Mod"/> to check.</param>
|
||||
private bool isValidAllowedMod(Mod mod) => ModUtils.IsValidModForMatch(mod, false, room.Type, freestyle.Value)
|
||||
private bool isValidAllowedMod(Mod mod) => ModUtils.IsValidModForMatch(mod, false, room.Type, Freestyle.Value)
|
||||
// Mod must not be contained in the required mods.
|
||||
&& Mods.Value.All(m => m.Acronym != mod.Acronym)
|
||||
// Mod must be compatible with all the required mods.
|
||||
|
||||
Reference in New Issue
Block a user