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

165 lines
6.0 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.
2018-12-25 10:59:08 +08:00
using System.Linq;
2020-02-06 11:17:05 +08:00
using NUnit.Framework;
using osu.Framework.Graphics;
using osu.Framework.Graphics.Containers;
using osu.Framework.Graphics.Cursor;
using osu.Framework.Testing;
2020-12-25 12:38:11 +08:00
using osu.Game.Online.Rooms;
2020-02-06 12:03:15 +08:00
using osu.Game.Rulesets.Catch;
using osu.Game.Rulesets.Osu;
using osu.Game.Screens.OnlinePlay.Lounge;
using osu.Game.Screens.OnlinePlay.Lounge.Components;
using osu.Game.Tests.Visual.OnlinePlay;
2020-07-09 17:55:18 +08:00
using osuTK.Input;
2019-03-25 00:02:36 +08:00
namespace osu.Game.Tests.Visual.Multiplayer
{
public class TestSceneLoungeRoomsContainer : OnlinePlayTestScene
{
2021-10-27 15:10:22 +08:00
protected new TestRoomManager RoomManager => (TestRoomManager)base.RoomManager;
2021-06-24 18:13:50 +08:00
2020-02-06 11:17:05 +08:00
private RoomsContainer container;
[SetUp]
public new void Setup() => Schedule(() =>
{
Child = new PopoverContainer
{
RelativeSizeAxes = Axes.X,
AutoSizeAxes = Axes.Y,
Anchor = Anchor.Centre,
Origin = Anchor.Centre,
Width = 0.5f,
Child = container = new RoomsContainer
{
SelectedRoom = { BindTarget = SelectedRoom }
}
};
});
2020-02-06 11:17:05 +08:00
[Test]
public void TestBasicListChanges()
2020-02-06 11:26:08 +08:00
{
AddStep("add rooms", () => RoomManager.AddRooms(3));
2020-02-06 11:26:08 +08:00
AddAssert("has 3 rooms", () => container.Rooms.Count == 3);
AddStep("remove first room", () => RoomManager.RemoveRoom(RoomManager.Rooms.FirstOrDefault()));
2020-02-06 11:26:08 +08:00
AddAssert("has 2 rooms", () => container.Rooms.Count == 2);
AddAssert("first room removed", () => container.Rooms.All(r => r.Room.RoomID.Value != 0));
2021-08-04 16:27:44 +08:00
AddStep("select first room", () => container.Rooms.First().TriggerClick());
2020-07-09 17:55:18 +08:00
AddAssert("first room selected", () => checkRoomSelected(RoomManager.Rooms.First()));
2020-02-06 11:26:08 +08:00
}
2020-07-09 17:55:18 +08:00
[Test]
public void TestKeyboardNavigation()
{
AddStep("add rooms", () => RoomManager.AddRooms(3));
2020-07-09 17:55:18 +08:00
AddAssert("no selection", () => checkRoomSelected(null));
press(Key.Down);
AddAssert("first room selected", () => checkRoomSelected(RoomManager.Rooms.First()));
press(Key.Up);
AddAssert("first room selected", () => checkRoomSelected(RoomManager.Rooms.First()));
press(Key.Down);
press(Key.Down);
AddAssert("last room selected", () => checkRoomSelected(RoomManager.Rooms.Last()));
}
[Test]
public void TestKeyboardNavigationAfterOrderChange()
{
AddStep("add rooms", () => RoomManager.AddRooms(3));
AddStep("reorder rooms", () =>
{
var room = RoomManager.Rooms[1];
RoomManager.RemoveRoom(room);
RoomManager.AddOrUpdateRoom(room);
});
AddAssert("no selection", () => checkRoomSelected(null));
press(Key.Down);
AddAssert("first room selected", () => checkRoomSelected(getRoomInFlow(0)));
press(Key.Down);
AddAssert("second room selected", () => checkRoomSelected(getRoomInFlow(1)));
press(Key.Down);
AddAssert("third room selected", () => checkRoomSelected(getRoomInFlow(2)));
}
[Test]
public void TestClickDeselection()
{
AddStep("add room", () => RoomManager.AddRooms(1));
AddAssert("no selection", () => checkRoomSelected(null));
press(Key.Down);
AddAssert("first room selected", () => checkRoomSelected(RoomManager.Rooms.First()));
AddStep("click away", () => InputManager.Click(MouseButton.Left));
AddAssert("no selection", () => checkRoomSelected(null));
}
2020-07-09 17:55:18 +08:00
private void press(Key down)
{
2020-11-05 22:41:56 +08:00
AddStep($"press {down}", () => InputManager.Key(down));
2020-07-09 17:55:18 +08:00
}
2020-02-06 11:26:08 +08:00
[Test]
public void TestStringFiltering()
{
AddStep("add rooms", () => RoomManager.AddRooms(4));
2020-02-06 11:26:08 +08:00
AddUntilStep("4 rooms visible", () => container.Rooms.Count(r => r.IsPresent) == 4);
2021-08-17 08:36:43 +08:00
AddStep("filter one room", () => container.Filter.Value = new FilterCriteria { SearchString = "1" });
2020-02-06 11:26:08 +08:00
AddUntilStep("1 rooms visible", () => container.Rooms.Count(r => r.IsPresent) == 1);
2021-08-17 08:36:43 +08:00
AddStep("remove filter", () => container.Filter.Value = null);
2020-02-06 11:26:08 +08:00
AddUntilStep("4 rooms visible", () => container.Rooms.Count(r => r.IsPresent) == 4);
}
2020-02-06 12:03:15 +08:00
[Test]
public void TestRulesetFiltering()
{
AddStep("add rooms", () => RoomManager.AddRooms(2, new OsuRuleset().RulesetInfo));
AddStep("add rooms", () => RoomManager.AddRooms(3, new CatchRuleset().RulesetInfo));
2020-02-06 12:03:15 +08:00
// Todo: What even is this case...?
2021-08-17 08:36:43 +08:00
AddStep("set empty filter criteria", () => container.Filter.Value = null);
2020-02-06 12:03:15 +08:00
AddUntilStep("5 rooms visible", () => container.Rooms.Count(r => r.IsPresent) == 5);
2021-08-17 08:36:43 +08:00
AddStep("filter osu! rooms", () => container.Filter.Value = new FilterCriteria { Ruleset = new OsuRuleset().RulesetInfo });
2020-02-06 12:03:15 +08:00
AddUntilStep("2 rooms visible", () => container.Rooms.Count(r => r.IsPresent) == 2);
2021-08-17 08:36:43 +08:00
AddStep("filter catch rooms", () => container.Filter.Value = new FilterCriteria { Ruleset = new CatchRuleset().RulesetInfo });
2020-02-06 12:03:15 +08:00
AddUntilStep("3 rooms visible", () => container.Rooms.Count(r => r.IsPresent) == 3);
}
[Test]
public void TestPasswordProtectedRooms()
{
AddStep("add rooms", () => RoomManager.AddRooms(3, withPassword: true));
}
private bool checkRoomSelected(Room room) => SelectedRoom.Value == room;
private Room getRoomInFlow(int index) =>
(container.ChildrenOfType<FillFlowContainer<DrawableLoungeRoom>>().First().FlowingChildren.ElementAt(index) as DrawableRoom)?.Room;
}
}