mirror of
https://github.com/ppy/osu.git
synced 2025-03-11 07:17:18 +08:00
169 lines
7.7 KiB
C#
169 lines
7.7 KiB
C#
// 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;
|
|
using osu.Framework.Graphics.Containers;
|
|
using osu.Framework.Graphics.UserInterface;
|
|
using osu.Framework.Screens;
|
|
using osu.Framework.Testing;
|
|
using osu.Game.Graphics.UserInterface;
|
|
using osu.Game.Screens.OnlinePlay.Lounge;
|
|
using osu.Game.Screens.OnlinePlay.Lounge.Components;
|
|
using osu.Game.Screens.OnlinePlay.Multiplayer;
|
|
using osu.Game.Tests.Visual.OnlinePlay;
|
|
using osuTK.Input;
|
|
|
|
namespace osu.Game.Tests.Visual.Multiplayer
|
|
{
|
|
public partial class TestSceneMultiplayerLoungeSubScreen : MultiplayerTestScene
|
|
{
|
|
protected new TestRoomManager RoomManager => (TestRoomManager)base.RoomManager;
|
|
|
|
private LoungeSubScreen loungeScreen = null!;
|
|
|
|
private RoomsContainer roomsContainer => loungeScreen.ChildrenOfType<RoomsContainer>().First();
|
|
|
|
public TestSceneMultiplayerLoungeSubScreen()
|
|
: base(false)
|
|
{
|
|
}
|
|
|
|
public override void SetUpSteps()
|
|
{
|
|
base.SetUpSteps();
|
|
|
|
AddStep("push screen", () => LoadScreen(loungeScreen = new MultiplayerLoungeSubScreen()));
|
|
AddUntilStep("wait for present", () => loungeScreen.IsCurrentScreen());
|
|
}
|
|
|
|
[Test]
|
|
public void TestJoinRoomWithoutPassword()
|
|
{
|
|
addRoom(false);
|
|
AddStep("select room", () => InputManager.Key(Key.Down));
|
|
AddStep("join room", () => InputManager.Key(Key.Enter));
|
|
|
|
AddAssert("room joined", () => MultiplayerClient.RoomJoined);
|
|
}
|
|
|
|
[Test]
|
|
public void TestPopoverHidesOnBackButton()
|
|
{
|
|
addRoom(true);
|
|
AddStep("select room", () => InputManager.Key(Key.Down));
|
|
AddStep("attempt join room", () => InputManager.Key(Key.Enter));
|
|
|
|
AddUntilStep("password prompt appeared", () => InputManager.ChildrenOfType<DrawableLoungeRoom.PasswordEntryPopover>().Any());
|
|
|
|
AddAssert("textbox has focus", () => InputManager.FocusedDrawable is OsuPasswordTextBox);
|
|
|
|
AddStep("hit escape", () => InputManager.Key(Key.Escape));
|
|
AddAssert("textbox lost focus", () => InputManager.FocusedDrawable is SearchTextBox);
|
|
|
|
AddStep("hit escape", () => InputManager.Key(Key.Escape));
|
|
AddUntilStep("password prompt hidden", () => !InputManager.ChildrenOfType<DrawableLoungeRoom.PasswordEntryPopover>().Any());
|
|
|
|
AddAssert("room not joined", () => !MultiplayerClient.RoomJoined);
|
|
}
|
|
|
|
[Test]
|
|
public void TestPopoverHidesOnLeavingScreen()
|
|
{
|
|
addRoom(true);
|
|
AddStep("select room", () => InputManager.Key(Key.Down));
|
|
AddStep("attempt join room", () => InputManager.Key(Key.Enter));
|
|
|
|
AddUntilStep("password prompt appeared", () => InputManager.ChildrenOfType<DrawableLoungeRoom.PasswordEntryPopover>().Any());
|
|
AddStep("exit screen", () => Stack.Exit());
|
|
AddUntilStep("password prompt hidden", () => !InputManager.ChildrenOfType<DrawableLoungeRoom.PasswordEntryPopover>().Any());
|
|
|
|
AddAssert("room not joined", () => !MultiplayerClient.RoomJoined);
|
|
}
|
|
|
|
[Test]
|
|
public void TestJoinRoomWithIncorrectPasswordViaButton()
|
|
{
|
|
DrawableLoungeRoom.PasswordEntryPopover? passwordEntryPopover = null;
|
|
|
|
addRoom(true);
|
|
AddStep("select room", () => InputManager.Key(Key.Down));
|
|
AddStep("attempt join room", () => InputManager.Key(Key.Enter));
|
|
AddUntilStep("password prompt appeared", () => (passwordEntryPopover = InputManager.ChildrenOfType<DrawableLoungeRoom.PasswordEntryPopover>().FirstOrDefault()) != null);
|
|
AddStep("enter password in text box", () => passwordEntryPopover.ChildrenOfType<TextBox>().First().Text = "wrong");
|
|
AddStep("press join room button", () => passwordEntryPopover.ChildrenOfType<OsuButton>().First().TriggerClick());
|
|
|
|
AddAssert("still at lounge", () => loungeScreen.IsCurrentScreen());
|
|
AddUntilStep("password prompt still visible", () => passwordEntryPopover!.State.Value == Visibility.Visible);
|
|
AddAssert("textbox still focused", () => InputManager.FocusedDrawable is OsuPasswordTextBox);
|
|
|
|
AddAssert("room not joined", () => !MultiplayerClient.RoomJoined);
|
|
}
|
|
|
|
[Test]
|
|
public void TestJoinRoomWithIncorrectPasswordViaEnter()
|
|
{
|
|
DrawableLoungeRoom.PasswordEntryPopover? passwordEntryPopover = null;
|
|
|
|
addRoom(true);
|
|
AddStep("select room", () => InputManager.Key(Key.Down));
|
|
AddStep("attempt join room", () => InputManager.Key(Key.Enter));
|
|
AddUntilStep("password prompt appeared", () => (passwordEntryPopover = InputManager.ChildrenOfType<DrawableLoungeRoom.PasswordEntryPopover>().FirstOrDefault()) != null);
|
|
AddStep("enter password in text box", () => passwordEntryPopover.ChildrenOfType<TextBox>().First().Text = "wrong");
|
|
AddStep("press enter", () => InputManager.Key(Key.Enter));
|
|
|
|
AddAssert("still at lounge", () => loungeScreen.IsCurrentScreen());
|
|
AddUntilStep("password prompt still visible", () => passwordEntryPopover!.State.Value == Visibility.Visible);
|
|
AddAssert("textbox still focused", () => InputManager.FocusedDrawable is OsuPasswordTextBox);
|
|
|
|
AddAssert("room not joined", () => !MultiplayerClient.RoomJoined);
|
|
}
|
|
|
|
[Test]
|
|
public void TestJoinRoomWithCorrectPassword()
|
|
{
|
|
DrawableLoungeRoom.PasswordEntryPopover? passwordEntryPopover = null;
|
|
|
|
addRoom(true);
|
|
AddStep("select room", () => InputManager.Key(Key.Down));
|
|
AddStep("attempt join room", () => InputManager.Key(Key.Enter));
|
|
AddUntilStep("password prompt appeared", () => (passwordEntryPopover = InputManager.ChildrenOfType<DrawableLoungeRoom.PasswordEntryPopover>().FirstOrDefault()) != null);
|
|
AddStep("enter password in text box", () => passwordEntryPopover.ChildrenOfType<TextBox>().First().Text = "password");
|
|
AddStep("press join room button", () => passwordEntryPopover.ChildrenOfType<OsuButton>().First().TriggerClick());
|
|
|
|
AddUntilStep("room joined", () => MultiplayerClient.RoomJoined);
|
|
}
|
|
|
|
[Test]
|
|
public void TestJoinRoomWithPasswordViaKeyboardOnly()
|
|
{
|
|
DrawableLoungeRoom.PasswordEntryPopover? passwordEntryPopover = null;
|
|
|
|
addRoom(true);
|
|
AddStep("select room", () => InputManager.Key(Key.Down));
|
|
AddStep("attempt join room", () => InputManager.Key(Key.Enter));
|
|
AddUntilStep("password prompt appeared", () => (passwordEntryPopover = InputManager.ChildrenOfType<DrawableLoungeRoom.PasswordEntryPopover>().FirstOrDefault()) != null);
|
|
AddStep("enter password in text box", () => passwordEntryPopover.ChildrenOfType<TextBox>().First().Text = "password");
|
|
AddStep("press enter", () => InputManager.Key(Key.Enter));
|
|
|
|
AddAssert("room joined", () => MultiplayerClient.RoomJoined);
|
|
}
|
|
|
|
private void addRoom(bool withPassword)
|
|
{
|
|
int initialRoomCount = 0;
|
|
|
|
AddStep("add room", () =>
|
|
{
|
|
initialRoomCount = roomsContainer.Rooms.Count;
|
|
RoomManager.AddRooms(1, withPassword: withPassword);
|
|
loungeScreen.RefreshRooms();
|
|
});
|
|
|
|
AddUntilStep("wait for room to appear", () => roomsContainer.Rooms.Count == initialRoomCount + 1);
|
|
}
|
|
|
|
protected override OnlinePlayTestSceneDependencies CreateOnlinePlayDependencies() => new MultiplayerTestSceneDependencies();
|
|
}
|
|
}
|