1
0
mirror of https://github.com/ppy/osu.git synced 2025-01-28 12:23:21 +08:00

More test steps.

This commit is contained in:
DrabWeb 2018-05-22 01:22:23 -03:00
parent 6aac4269e6
commit 662559d3c9
3 changed files with 80 additions and 28 deletions

View File

@ -1,23 +1,29 @@
// Copyright (c) 2007-2018 ppy Pty Ltd <contact@ppy.sh>. // Copyright (c) 2007-2018 ppy Pty Ltd <contact@ppy.sh>.
// Licensed under the MIT Licence - https://raw.githubusercontent.com/ppy/osu/master/LICENCE // Licensed under the MIT Licence - https://raw.githubusercontent.com/ppy/osu/master/LICENCE
using System.Collections.Generic;
using System.Linq;
using NUnit.Framework; using NUnit.Framework;
using osu.Framework.Allocation; using osu.Framework.Allocation;
using osu.Game.Beatmaps; using osu.Game.Beatmaps;
using osu.Game.Online.Multiplayer; using osu.Game.Online.Multiplayer;
using osu.Game.Rulesets; using osu.Game.Rulesets;
using osu.Game.Screens.Multi.Components;
using osu.Game.Screens.Multi.Screens.Lounge; using osu.Game.Screens.Multi.Screens.Lounge;
using osu.Game.Users; using osu.Game.Users;
using OpenTK.Input;
namespace osu.Game.Tests.Visual namespace osu.Game.Tests.Visual
{ {
[TestFixture] [TestFixture]
public class TestCaseLounge : OsuTestCase public class TestCaseLounge : ManualInputManagerTestCase
{ {
private TestLounge lounge;
[BackgroundDependencyLoader] [BackgroundDependencyLoader]
private void load(RulesetStore rulesets) private void load(RulesetStore rulesets)
{ {
Lounge lounge = new Lounge(); lounge = new TestLounge();
Room[] rooms = Room[] rooms =
{ {
@ -26,6 +32,7 @@ namespace osu.Game.Tests.Visual
Name = { Value = @"Just Another Room" }, Name = { Value = @"Just Another Room" },
Host = { Value = new User { Username = @"DrabWeb", Id = 6946022, Country = new Country { FlagName = @"CA" } } }, Host = { Value = new User { Username = @"DrabWeb", Id = 6946022, Country = new Country { FlagName = @"CA" } } },
Status = { Value = new RoomStatusPlaying() }, Status = { Value = new RoomStatusPlaying() },
Availability = { Value = RoomAvailability.Public },
Type = { Value = new GameTypeTagTeam() }, Type = { Value = new GameTypeTagTeam() },
Beatmap = Beatmap =
{ {
@ -70,6 +77,7 @@ namespace osu.Game.Tests.Visual
Name = { Value = @"Not Just Any Room" }, Name = { Value = @"Not Just Any Room" },
Host = { Value = new User { Username = @"Monstrata", Id = 2706438, Country = new Country { FlagName = @"CA" } } }, Host = { Value = new User { Username = @"Monstrata", Id = 2706438, Country = new Country { FlagName = @"CA" } } },
Status = { Value = new RoomStatusOpen() }, Status = { Value = new RoomStatusOpen() },
Availability = { Value = RoomAvailability.FriendsOnly },
Type = { Value = new GameTypeTeamVersus() }, Type = { Value = new GameTypeTeamVersus() },
Beatmap = Beatmap =
{ {
@ -110,6 +118,7 @@ namespace osu.Game.Tests.Visual
Name = { Value = @"room THE FINAL" }, Name = { Value = @"room THE FINAL" },
Host = { Value = new User { Username = @"Delis", Id = 1603923, Country = new Country { FlagName = @"JP" } } }, Host = { Value = new User { Username = @"Delis", Id = 1603923, Country = new Country { FlagName = @"JP" } } },
Status = { Value = new RoomStatusPlaying() }, Status = { Value = new RoomStatusPlaying() },
Availability = { Value = RoomAvailability.Public },
Type = { Value = new GameTypeTagTeam() }, Type = { Value = new GameTypeTagTeam() },
Beatmap = Beatmap =
{ {
@ -150,9 +159,54 @@ namespace osu.Game.Tests.Visual
AddStep(@"show", () => Add(lounge)); AddStep(@"show", () => Add(lounge));
AddStep(@"set rooms", () => lounge.Rooms = rooms); AddStep(@"set rooms", () => lounge.Rooms = rooms);
selectAssert(0);
AddStep(@"clear rooms", () => lounge.Rooms = new Room[] {});
AddAssert(@"no room selected", () => lounge.SelectedRoom == null);
AddStep(@"set rooms", () => lounge.Rooms = rooms);
selectAssert(1);
AddStep(@"open room 1", () => clickRoom(1));
AddStep(@"make lounge current", lounge.MakeCurrent);
filterAssert(@"THE FINAL", LoungeTab.Public, 1);
filterAssert(string.Empty, LoungeTab.Public, 2);
filterAssert(string.Empty, LoungeTab.Private, 1);
filterAssert(string.Empty, LoungeTab.Public, 2);
filterAssert(@"no matches", LoungeTab.Public, 0);
AddStep(@"clear rooms", () => lounge.Rooms = new Room[] {}); AddStep(@"clear rooms", () => lounge.Rooms = new Room[] {});
AddStep(@"set rooms", () => lounge.Rooms = rooms); AddStep(@"set rooms", () => lounge.Rooms = rooms);
AddAssert(@"no matches after clear", () => lounge.MatchedCount == 0);
filterAssert(string.Empty, LoungeTab.Public, 2);
AddStep(@"exit", lounge.Exit); AddStep(@"exit", lounge.Exit);
} }
private void clickRoom(int n)
{
InputManager.MoveMouseTo(lounge.ChildRooms[n]);
InputManager.Click(MouseButton.Left);
}
private void selectAssert(int n)
{
AddStep($@"select room {n}", () => clickRoom(n));
AddAssert($@"room {n} selected", () => lounge.SelectedRoom == lounge.ChildRooms[n].Room);
}
private void filterAssert(string filter, LoungeTab tab, int endCount)
{
AddStep($@"filter '{filter}', {tab}", () => lounge.SetFilter(filter, tab));
AddAssert(@"filtered correctly", () => lounge.MatchedCount == endCount);
}
private class TestLounge : Lounge
{
public IReadOnlyList<DrawableRoom> ChildRooms => RoomsContainer.Children;
public Room SelectedRoom => Inspector.Room;
public int MatchedCount => ChildRooms.Count(r => r.MatchingFilter);
public void SetFilter(string filter, LoungeTab tab)
{
Filter.Search.Current.Value = filter;
Filter.Tabs.Current.Value = tab;
}
}
} }
} }

View File

@ -72,9 +72,7 @@ namespace osu.Game.Screens.Multi.Components
get { return matchingFilter; } get { return matchingFilter; }
set set
{ {
if (value == matchingFilter) return;
matchingFilter = value; matchingFilter = value;
this.FadeTo(MatchingFilter ? 1 : 0, 200); this.FadeTo(MatchingFilter ? 1 : 0, 200);
} }
} }

View File

@ -18,16 +18,16 @@ namespace osu.Game.Screens.Multi.Screens.Lounge
{ {
public class Lounge : MultiplayerScreen public class Lounge : MultiplayerScreen
{ {
private readonly FilterControl filter;
private readonly Container content; private readonly Container content;
private readonly SearchContainer search; private readonly SearchContainer search;
private readonly RoomsFilterContainer roomsFlow;
private readonly RoomInspector roomInspector;
protected override Container<Drawable> TransitionContent => content; protected readonly FilterControl Filter;
protected readonly FillFlowContainer<DrawableRoom> RoomsContainer;
protected readonly RoomInspector Inspector;
public override string Title => "lounge"; public override string Title => "lounge";
public override string Name => "Lounge"; public override string Name => "Lounge";
protected override Container<Drawable> TransitionContent => content;
private IEnumerable<Room> rooms; private IEnumerable<Room> rooms;
public IEnumerable<Room> Rooms public IEnumerable<Room> Rooms
@ -40,13 +40,13 @@ namespace osu.Game.Screens.Multi.Screens.Lounge
var enumerable = rooms.ToList(); var enumerable = rooms.ToList();
roomsFlow.Children = enumerable.Select(r => new DrawableRoom(r) RoomsContainer.Children = enumerable.Select(r => new DrawableRoom(r)
{ {
Action = didSelect, Action = didSelect,
}).ToList(); }).ToList();
if (!enumerable.Contains(roomInspector.Room)) if (!enumerable.Contains(Inspector.Room))
roomInspector.Room = null; Inspector.Room = null;
filterRooms(); filterRooms();
} }
@ -56,7 +56,7 @@ namespace osu.Game.Screens.Multi.Screens.Lounge
{ {
Children = new Drawable[] Children = new Drawable[]
{ {
filter = new FilterControl(), Filter = new FilterControl(),
content = new Container content = new Container
{ {
RelativeSizeAxes = Axes.Both, RelativeSizeAxes = Axes.Both,
@ -75,7 +75,7 @@ namespace osu.Game.Screens.Multi.Screens.Lounge
{ {
RelativeSizeAxes = Axes.X, RelativeSizeAxes = Axes.X,
AutoSizeAxes = Axes.Y, AutoSizeAxes = Axes.Y,
Child = roomsFlow = new RoomsFilterContainer Child = RoomsContainer = new RoomsFilterContainer
{ {
RelativeSizeAxes = Axes.X, RelativeSizeAxes = Axes.X,
AutoSizeAxes = Axes.Y, AutoSizeAxes = Axes.Y,
@ -84,7 +84,7 @@ namespace osu.Game.Screens.Multi.Screens.Lounge
}, },
}, },
}, },
roomInspector = new RoomInspector Inspector = new RoomInspector
{ {
Anchor = Anchor.TopRight, Anchor = Anchor.TopRight,
Origin = Anchor.TopRight, Origin = Anchor.TopRight,
@ -95,9 +95,9 @@ namespace osu.Game.Screens.Multi.Screens.Lounge
}, },
}; };
filter.Search.Current.ValueChanged += s => filterRooms(); Filter.Search.Current.ValueChanged += s => filterRooms();
filter.Tabs.Current.ValueChanged += t => filterRooms(); Filter.Tabs.Current.ValueChanged += t => filterRooms();
filter.Search.Exit += Exit; Filter.Search.Exit += Exit;
} }
protected override void UpdateAfterChildren() protected override void UpdateAfterChildren()
@ -106,7 +106,7 @@ namespace osu.Game.Screens.Multi.Screens.Lounge
content.Padding = new MarginPadding content.Padding = new MarginPadding
{ {
Top = filter.DrawHeight, Top = Filter.DrawHeight,
Left = SearchableListOverlay.WIDTH_PADDING - DrawableRoom.SELECTION_BORDER_WIDTH, Left = SearchableListOverlay.WIDTH_PADDING - DrawableRoom.SELECTION_BORDER_WIDTH,
Right = SearchableListOverlay.WIDTH_PADDING, Right = SearchableListOverlay.WIDTH_PADDING,
}; };
@ -114,53 +114,53 @@ namespace osu.Game.Screens.Multi.Screens.Lounge
protected override void OnFocus(InputState state) protected override void OnFocus(InputState state)
{ {
GetContainingInputManager().ChangeFocus(filter.Search); GetContainingInputManager().ChangeFocus(Filter.Search);
} }
protected override void OnEntering(Screen last) protected override void OnEntering(Screen last)
{ {
base.OnEntering(last); base.OnEntering(last);
filter.Search.HoldFocus = true; Filter.Search.HoldFocus = true;
} }
protected override bool OnExiting(Screen next) protected override bool OnExiting(Screen next)
{ {
filter.Search.HoldFocus = false; Filter.Search.HoldFocus = false;
return base.OnExiting(next); return base.OnExiting(next);
} }
protected override void OnResuming(Screen last) protected override void OnResuming(Screen last)
{ {
base.OnResuming(last); base.OnResuming(last);
filter.Search.HoldFocus = true; Filter.Search.HoldFocus = true;
} }
protected override void OnSuspending(Screen next) protected override void OnSuspending(Screen next)
{ {
base.OnSuspending(next); base.OnSuspending(next);
filter.Search.HoldFocus = false; Filter.Search.HoldFocus = false;
} }
private void filterRooms() private void filterRooms()
{ {
search.SearchTerm = filter.Search.Current.Value ?? string.Empty; search.SearchTerm = Filter.Search.Current.Value ?? string.Empty;
foreach (DrawableRoom r in roomsFlow.Children) foreach (DrawableRoom r in RoomsContainer.Children)
{ {
r.MatchingFilter = r.MatchingFilter && r.MatchingFilter = r.MatchingFilter &&
r.Room.Availability.Value == (RoomAvailability)filter.Tabs.Current.Value; r.Room.Availability.Value == (RoomAvailability)Filter.Tabs.Current.Value;
} }
} }
private void didSelect(DrawableRoom room) private void didSelect(DrawableRoom room)
{ {
roomsFlow.Children.ForEach(c => RoomsContainer.Children.ForEach(c =>
{ {
if (c != room) if (c != room)
c.State = SelectionState.NotSelected; c.State = SelectionState.NotSelected;
}); });
roomInspector.Room = room.Room; Inspector.Room = room.Room;
// open the room if its selected and is clicked again // open the room if its selected and is clicked again
if (room.State == SelectionState.Selected) if (room.State == SelectionState.Selected)