mirror of
https://github.com/ppy/osu.git
synced 2024-11-11 12:57:36 +08:00
More test steps.
This commit is contained in:
parent
6aac4269e6
commit
662559d3c9
@ -1,23 +1,29 @@
|
||||
// Copyright (c) 2007-2018 ppy Pty Ltd <contact@ppy.sh>.
|
||||
// Licensed under the MIT Licence - https://raw.githubusercontent.com/ppy/osu/master/LICENCE
|
||||
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using NUnit.Framework;
|
||||
using osu.Framework.Allocation;
|
||||
using osu.Game.Beatmaps;
|
||||
using osu.Game.Online.Multiplayer;
|
||||
using osu.Game.Rulesets;
|
||||
using osu.Game.Screens.Multi.Components;
|
||||
using osu.Game.Screens.Multi.Screens.Lounge;
|
||||
using osu.Game.Users;
|
||||
using OpenTK.Input;
|
||||
|
||||
namespace osu.Game.Tests.Visual
|
||||
{
|
||||
[TestFixture]
|
||||
public class TestCaseLounge : OsuTestCase
|
||||
public class TestCaseLounge : ManualInputManagerTestCase
|
||||
{
|
||||
private TestLounge lounge;
|
||||
|
||||
[BackgroundDependencyLoader]
|
||||
private void load(RulesetStore rulesets)
|
||||
{
|
||||
Lounge lounge = new Lounge();
|
||||
lounge = new TestLounge();
|
||||
|
||||
Room[] rooms =
|
||||
{
|
||||
@ -26,6 +32,7 @@ namespace osu.Game.Tests.Visual
|
||||
Name = { Value = @"Just Another Room" },
|
||||
Host = { Value = new User { Username = @"DrabWeb", Id = 6946022, Country = new Country { FlagName = @"CA" } } },
|
||||
Status = { Value = new RoomStatusPlaying() },
|
||||
Availability = { Value = RoomAvailability.Public },
|
||||
Type = { Value = new GameTypeTagTeam() },
|
||||
Beatmap =
|
||||
{
|
||||
@ -70,6 +77,7 @@ namespace osu.Game.Tests.Visual
|
||||
Name = { Value = @"Not Just Any Room" },
|
||||
Host = { Value = new User { Username = @"Monstrata", Id = 2706438, Country = new Country { FlagName = @"CA" } } },
|
||||
Status = { Value = new RoomStatusOpen() },
|
||||
Availability = { Value = RoomAvailability.FriendsOnly },
|
||||
Type = { Value = new GameTypeTeamVersus() },
|
||||
Beatmap =
|
||||
{
|
||||
@ -110,6 +118,7 @@ namespace osu.Game.Tests.Visual
|
||||
Name = { Value = @"room THE FINAL" },
|
||||
Host = { Value = new User { Username = @"Delis", Id = 1603923, Country = new Country { FlagName = @"JP" } } },
|
||||
Status = { Value = new RoomStatusPlaying() },
|
||||
Availability = { Value = RoomAvailability.Public },
|
||||
Type = { Value = new GameTypeTagTeam() },
|
||||
Beatmap =
|
||||
{
|
||||
@ -150,9 +159,54 @@ namespace osu.Game.Tests.Visual
|
||||
|
||||
AddStep(@"show", () => Add(lounge));
|
||||
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(@"set rooms", () => lounge.Rooms = rooms);
|
||||
AddAssert(@"no matches after clear", () => lounge.MatchedCount == 0);
|
||||
filterAssert(string.Empty, LoungeTab.Public, 2);
|
||||
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;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -72,9 +72,7 @@ namespace osu.Game.Screens.Multi.Components
|
||||
get { return matchingFilter; }
|
||||
set
|
||||
{
|
||||
if (value == matchingFilter) return;
|
||||
matchingFilter = value;
|
||||
|
||||
this.FadeTo(MatchingFilter ? 1 : 0, 200);
|
||||
}
|
||||
}
|
||||
|
@ -18,16 +18,16 @@ namespace osu.Game.Screens.Multi.Screens.Lounge
|
||||
{
|
||||
public class Lounge : MultiplayerScreen
|
||||
{
|
||||
private readonly FilterControl filter;
|
||||
private readonly Container content;
|
||||
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 Name => "Lounge";
|
||||
protected override Container<Drawable> TransitionContent => content;
|
||||
|
||||
private IEnumerable<Room> rooms;
|
||||
public IEnumerable<Room> Rooms
|
||||
@ -40,13 +40,13 @@ namespace osu.Game.Screens.Multi.Screens.Lounge
|
||||
|
||||
var enumerable = rooms.ToList();
|
||||
|
||||
roomsFlow.Children = enumerable.Select(r => new DrawableRoom(r)
|
||||
RoomsContainer.Children = enumerable.Select(r => new DrawableRoom(r)
|
||||
{
|
||||
Action = didSelect,
|
||||
}).ToList();
|
||||
|
||||
if (!enumerable.Contains(roomInspector.Room))
|
||||
roomInspector.Room = null;
|
||||
if (!enumerable.Contains(Inspector.Room))
|
||||
Inspector.Room = null;
|
||||
|
||||
filterRooms();
|
||||
}
|
||||
@ -56,7 +56,7 @@ namespace osu.Game.Screens.Multi.Screens.Lounge
|
||||
{
|
||||
Children = new Drawable[]
|
||||
{
|
||||
filter = new FilterControl(),
|
||||
Filter = new FilterControl(),
|
||||
content = new Container
|
||||
{
|
||||
RelativeSizeAxes = Axes.Both,
|
||||
@ -75,7 +75,7 @@ namespace osu.Game.Screens.Multi.Screens.Lounge
|
||||
{
|
||||
RelativeSizeAxes = Axes.X,
|
||||
AutoSizeAxes = Axes.Y,
|
||||
Child = roomsFlow = new RoomsFilterContainer
|
||||
Child = RoomsContainer = new RoomsFilterContainer
|
||||
{
|
||||
RelativeSizeAxes = Axes.X,
|
||||
AutoSizeAxes = Axes.Y,
|
||||
@ -84,7 +84,7 @@ namespace osu.Game.Screens.Multi.Screens.Lounge
|
||||
},
|
||||
},
|
||||
},
|
||||
roomInspector = new RoomInspector
|
||||
Inspector = new RoomInspector
|
||||
{
|
||||
Anchor = Anchor.TopRight,
|
||||
Origin = Anchor.TopRight,
|
||||
@ -95,9 +95,9 @@ namespace osu.Game.Screens.Multi.Screens.Lounge
|
||||
},
|
||||
};
|
||||
|
||||
filter.Search.Current.ValueChanged += s => filterRooms();
|
||||
filter.Tabs.Current.ValueChanged += t => filterRooms();
|
||||
filter.Search.Exit += Exit;
|
||||
Filter.Search.Current.ValueChanged += s => filterRooms();
|
||||
Filter.Tabs.Current.ValueChanged += t => filterRooms();
|
||||
Filter.Search.Exit += Exit;
|
||||
}
|
||||
|
||||
protected override void UpdateAfterChildren()
|
||||
@ -106,7 +106,7 @@ namespace osu.Game.Screens.Multi.Screens.Lounge
|
||||
|
||||
content.Padding = new MarginPadding
|
||||
{
|
||||
Top = filter.DrawHeight,
|
||||
Top = Filter.DrawHeight,
|
||||
Left = SearchableListOverlay.WIDTH_PADDING - DrawableRoom.SELECTION_BORDER_WIDTH,
|
||||
Right = SearchableListOverlay.WIDTH_PADDING,
|
||||
};
|
||||
@ -114,53 +114,53 @@ namespace osu.Game.Screens.Multi.Screens.Lounge
|
||||
|
||||
protected override void OnFocus(InputState state)
|
||||
{
|
||||
GetContainingInputManager().ChangeFocus(filter.Search);
|
||||
GetContainingInputManager().ChangeFocus(Filter.Search);
|
||||
}
|
||||
|
||||
protected override void OnEntering(Screen last)
|
||||
{
|
||||
base.OnEntering(last);
|
||||
filter.Search.HoldFocus = true;
|
||||
Filter.Search.HoldFocus = true;
|
||||
}
|
||||
|
||||
protected override bool OnExiting(Screen next)
|
||||
{
|
||||
filter.Search.HoldFocus = false;
|
||||
Filter.Search.HoldFocus = false;
|
||||
return base.OnExiting(next);
|
||||
}
|
||||
|
||||
protected override void OnResuming(Screen last)
|
||||
{
|
||||
base.OnResuming(last);
|
||||
filter.Search.HoldFocus = true;
|
||||
Filter.Search.HoldFocus = true;
|
||||
}
|
||||
|
||||
protected override void OnSuspending(Screen next)
|
||||
{
|
||||
base.OnSuspending(next);
|
||||
filter.Search.HoldFocus = false;
|
||||
Filter.Search.HoldFocus = false;
|
||||
}
|
||||
|
||||
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.Room.Availability.Value == (RoomAvailability)filter.Tabs.Current.Value;
|
||||
r.Room.Availability.Value == (RoomAvailability)Filter.Tabs.Current.Value;
|
||||
}
|
||||
}
|
||||
|
||||
private void didSelect(DrawableRoom room)
|
||||
{
|
||||
roomsFlow.Children.ForEach(c =>
|
||||
RoomsContainer.Children.ForEach(c =>
|
||||
{
|
||||
if (c != room)
|
||||
c.State = SelectionState.NotSelected;
|
||||
});
|
||||
|
||||
roomInspector.Room = room.Room;
|
||||
Inspector.Room = room.Room;
|
||||
|
||||
// open the room if its selected and is clicked again
|
||||
if (room.State == SelectionState.Selected)
|
||||
|
Loading…
Reference in New Issue
Block a user