1
0
mirror of https://github.com/ppy/osu.git synced 2024-11-18 17:32:55 +08:00
osu-lazer/osu.Game.Tests/Visual/Multiplayer/TestSceneMultiplayerMatchSubScreen.cs

176 lines
6.6 KiB
C#
Raw Normal View History

// 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.Linq;
using NUnit.Framework;
2021-04-07 19:46:30 +08:00
using osu.Framework.Allocation;
using osu.Framework.Audio;
using osu.Framework.Extensions;
2021-04-07 19:46:30 +08:00
using osu.Framework.Platform;
using osu.Framework.Screens;
using osu.Framework.Testing;
2021-04-07 19:46:30 +08:00
using osu.Game.Beatmaps;
using osu.Game.Online.API;
using osu.Game.Online.API.Requests.Responses;
2021-04-07 19:46:30 +08:00
using osu.Game.Online.Multiplayer;
2020-12-25 12:38:11 +08:00
using osu.Game.Online.Rooms;
using osu.Game.Overlays.Mods;
2021-04-07 19:46:30 +08:00
using osu.Game.Rulesets;
using osu.Game.Rulesets.Osu;
using osu.Game.Rulesets.Osu.Mods;
using osu.Game.Rulesets.Taiko;
using osu.Game.Rulesets.Taiko.Mods;
using osu.Game.Rulesets.UI;
using osu.Game.Screens.OnlinePlay.Match;
using osu.Game.Screens.OnlinePlay.Multiplayer;
using osu.Game.Screens.OnlinePlay.Multiplayer.Match;
using osu.Game.Screens.OnlinePlay.Multiplayer.Participants;
using osu.Game.Tests.Beatmaps;
2021-04-07 19:46:30 +08:00
using osu.Game.Tests.Resources;
namespace osu.Game.Tests.Visual.Multiplayer
{
2020-12-25 12:38:11 +08:00
public class TestSceneMultiplayerMatchSubScreen : MultiplayerTestScene
{
2020-12-25 12:38:11 +08:00
private MultiplayerMatchSubScreen screen;
2021-04-07 19:46:30 +08:00
private BeatmapManager beatmaps;
private RulesetStore rulesets;
private BeatmapSetInfo importedSet;
2020-12-25 12:38:11 +08:00
public TestSceneMultiplayerMatchSubScreen()
: base(false)
{
}
2021-04-07 19:46:30 +08:00
[BackgroundDependencyLoader]
private void load(GameHost host, AudioManager audio)
{
Dependencies.Cache(rulesets = new RealmRulesetStore(Realm));
Dependencies.Cache(beatmaps = new BeatmapManager(LocalStorage, Realm, rulesets, null, audio, Resources, host, Beatmap.Default));
Dependencies.Cache(Realm);
beatmaps.Import(TestResources.GetQuickTestBeatmapForImport()).WaitSafely();
2021-04-07 19:46:30 +08:00
2021-12-17 17:26:12 +08:00
importedSet = beatmaps.GetAllUsableBeatmapSets().First();
2021-04-07 19:46:30 +08:00
}
[SetUp]
public new void Setup() => Schedule(() =>
{
SelectedRoom.Value = new Room { Name = { Value = "Test Room" } };
});
[SetUpSteps]
public void SetupSteps()
{
AddStep("load match", () => LoadScreen(screen = new MultiplayerMatchSubScreen(SelectedRoom.Value)));
AddUntilStep("wait for load", () => screen.IsCurrentScreen());
}
[Test]
2021-08-17 16:05:20 +08:00
public void TestCreatedRoom()
{
AddStep("add playlist item", () =>
{
SelectedRoom.Value.Playlist.Add(new PlaylistItem(new TestBeatmap(new OsuRuleset().RulesetInfo).BeatmapInfo)
{
RulesetID = new OsuRuleset().RulesetInfo.OnlineID
});
2021-08-17 16:05:20 +08:00
});
ClickButtonWhenEnabled<MultiplayerMatchSettingsOverlay.CreateOrUpdateButton>();
AddUntilStep("wait for join", () => RoomJoined);
}
[Test]
public void TestTaikoOnlyMod()
{
AddStep("add playlist item", () =>
{
SelectedRoom.Value.Playlist.Add(new PlaylistItem(new TestBeatmap(new TaikoRuleset().RulesetInfo).BeatmapInfo)
{
RulesetID = new TaikoRuleset().RulesetInfo.OnlineID,
AllowedMods = new[] { new APIMod(new TaikoModSwap()) }
});
});
ClickButtonWhenEnabled<MultiplayerMatchSettingsOverlay.CreateOrUpdateButton>();
AddUntilStep("wait for join", () => RoomJoined);
AddStep("select swap mod", () => MultiplayerClient.ChangeUserMods(API.LocalUser.Value.OnlineID, new[] { new TaikoModSwap() }));
AddUntilStep("participant panel has mod", () => this.ChildrenOfType<ParticipantPanel>().Any(p => p.ChildrenOfType<ModIcon>().Any(m => m.Mod is TaikoModSwap)));
}
[Test]
2021-08-17 16:05:20 +08:00
public void TestSettingValidity()
{
2021-08-17 16:05:20 +08:00
AddAssert("create button not enabled", () => !this.ChildrenOfType<MultiplayerMatchSettingsOverlay.CreateOrUpdateButton>().Single().Enabled.Value);
AddStep("set playlist", () =>
{
SelectedRoom.Value.Playlist.Add(new PlaylistItem(new TestBeatmap(new OsuRuleset().RulesetInfo).BeatmapInfo)
{
RulesetID = new OsuRuleset().RulesetInfo.OnlineID
});
});
2021-08-17 16:05:20 +08:00
AddAssert("create button enabled", () => this.ChildrenOfType<MultiplayerMatchSettingsOverlay.CreateOrUpdateButton>().Single().Enabled.Value);
}
2021-04-07 19:46:30 +08:00
[Test]
public void TestStartMatchWhileSpectating()
{
AddStep("set playlist", () =>
{
SelectedRoom.Value.Playlist.Add(new PlaylistItem(beatmaps.GetWorkingBeatmap(importedSet.Beatmaps.First()).BeatmapInfo)
2021-04-07 19:46:30 +08:00
{
RulesetID = new OsuRuleset().RulesetInfo.OnlineID
2021-04-07 19:46:30 +08:00
});
});
ClickButtonWhenEnabled<MultiplayerMatchSettingsOverlay.CreateOrUpdateButton>();
2021-04-07 19:46:30 +08:00
AddUntilStep("wait for room join", () => RoomJoined);
2021-04-08 20:38:58 +08:00
2021-04-07 19:46:30 +08:00
AddStep("join other user (ready)", () =>
{
MultiplayerClient.AddUser(new APIUser { Id = PLAYER_1_ID });
MultiplayerClient.ChangeUserState(PLAYER_1_ID, MultiplayerUserState.Ready);
2021-04-07 19:46:30 +08:00
});
ClickButtonWhenEnabled<MultiplayerSpectateButton>();
2021-04-07 19:46:30 +08:00
AddUntilStep("wait for spectating user state", () => MultiplayerClient.LocalUser?.State == MultiplayerUserState.Spectating);
2021-08-13 12:54:52 +08:00
ClickButtonWhenEnabled<MultiplayerReadyButton.ReadyButton>();
2021-04-07 19:46:30 +08:00
AddUntilStep("match started", () => MultiplayerClient.Room?.State == MultiplayerRoomState.WaitingForLoad);
2021-04-07 19:46:30 +08:00
}
[Test]
public void TestFreeModSelectionHasAllowedMods()
{
AddStep("add playlist item with allowed mod", () =>
{
SelectedRoom.Value.Playlist.Add(new PlaylistItem(new TestBeatmap(new OsuRuleset().RulesetInfo).BeatmapInfo)
{
RulesetID = new OsuRuleset().RulesetInfo.OnlineID,
AllowedMods = new[] { new APIMod(new OsuModDoubleTime()) }
});
});
ClickButtonWhenEnabled<MultiplayerMatchSettingsOverlay.CreateOrUpdateButton>();
AddUntilStep("wait for join", () => RoomJoined);
ClickButtonWhenEnabled<RoomSubScreen.UserModSelectButton>();
AddUntilStep("mod select contains only double time mod",
() => this.ChildrenOfType<UserModSelectOverlay>().SingleOrDefault()?.ChildrenOfType<ModButton>().SingleOrDefault()?.Mod is OsuModDoubleTime);
}
}
}