1
0
mirror of https://github.com/ppy/osu.git synced 2024-12-14 16:52:54 +08:00

Test steps.

This commit is contained in:
DrabWeb 2018-06-06 23:30:17 -03:00
parent 4aff2ba2af
commit ed97d35ef7
2 changed files with 114 additions and 23 deletions

View File

@ -3,26 +3,115 @@
using NUnit.Framework;
using osu.Framework.Graphics;
using osu.Game.Graphics.UserInterface;
using osu.Game.Online.Multiplayer;
using osu.Game.Screens.Multi.Screens.Match;
using osu.Game.Screens.Multi.Screens.Match.Settings;
using OpenTK.Input;
namespace osu.Game.Tests.Visual
{
[TestFixture]
public class TestCaseRoomSettings : OsuTestCase
public class TestCaseRoomSettings : ManualInputManagerTestCase
{
private readonly Room room;
private readonly TestRoomSettingsOverlay overlay;
public TestCaseRoomSettings()
{
Room room = new Room();
room = new Room
{
Name = { Value = "One Testing Room" },
Availability = { Value = RoomAvailability.Public },
Type = { Value = new GameTypeTeamVersus() },
MaxParticipants = { Value = 10 },
};
RoomSettingsOverlay overlay;
Add(overlay = new RoomSettingsOverlay(room)
Add(overlay = new TestRoomSettingsOverlay(room)
{
RelativeSizeAxes = Axes.Both,
Height = 0.75f,
});
AddStep(@"toggle", overlay.ToggleVisibility);
AddStep(@"show", overlay.Show);
assertAll();
AddStep(@"set name", () => overlay.CurrentName = @"Two Testing Room");
AddStep(@"set max", () => overlay.CurrentMaxParticipants = null);
AddStep(@"set availability", () => overlay.CurrentAvailability = RoomAvailability.InviteOnly);
AddStep(@"set type", () => overlay.CurrentType = new GameTypeTagTeam());
apply();
assertAll();
AddStep(@"show", overlay.Show);
AddStep(@"set room name", () => room.Name.Value = @"Room Changed Name!");
AddStep(@"set room availability", () => room.Availability.Value = RoomAvailability.Public);
AddStep(@"set room type", () => room.Type.Value = new GameTypeTag());
AddStep(@"set room max", () => room.MaxParticipants.Value = 100);
assertAll();
AddStep(@"set name", () => overlay.CurrentName = @"Unsaved Testing Room");
AddStep(@"set max", () => overlay.CurrentMaxParticipants = 20);
AddStep(@"set availability", () => overlay.CurrentAvailability = RoomAvailability.FriendsOnly);
AddStep(@"set type", () => overlay.CurrentType = new GameTypeVersus());
AddStep(@"hide", overlay.Hide);
AddWaitStep(5);
AddStep(@"show", overlay.Show);
assertAll();
AddStep(@"hide", overlay.Hide);
}
private void apply()
{
AddStep(@"apply", () =>
{
InputManager.MoveMouseTo(overlay.ApplyButton);
InputManager.Click(MouseButton.Left);
});
}
private void assertAll()
{
AddAssert(@"name == room name", () => overlay.CurrentName == room.Name.Value);
AddAssert(@"max == room max", () => overlay.CurrentMaxParticipants == room.MaxParticipants.Value);
AddAssert(@"availability == room availability", () => overlay.CurrentAvailability == room.Availability.Value);
AddAssert(@"type == room type", () => Equals(overlay.CurrentType, room.Type.Value));
}
private class TestRoomSettingsOverlay : RoomSettingsOverlay
{
public string CurrentName
{
get => Name.Text;
set => Name.Text = value;
}
public int? CurrentMaxParticipants
{
get
{
int max;
if (int.TryParse(MaxParticipants.Text, out max))
return max;
return null;
}
set => MaxParticipants.Text = value?.ToString();
}
public RoomAvailability CurrentAvailability
{
get => Availability.Current.Value;
set => Availability.Current.Value = value;
}
public GameType CurrentType
{
get => Type.Current.Value;
set => Type.Current.Value = value;
}
public TriangleButton ApplyButton => Apply;
public TestRoomSettingsOverlay(Room room) : base(room)
{
}
}
}
}

View File

@ -16,7 +16,7 @@ using OpenTK.Graphics;
namespace osu.Game.Screens.Multi.Screens.Match.Settings
{
public class RoomSettingsOverlay : OverlayContainer
public class RoomSettingsOverlay : FocusedOverlayContainer
{
private const float transition_duration = 500;
private const float field_padding = 45;
@ -28,13 +28,15 @@ namespace osu.Game.Screens.Multi.Screens.Match.Settings
private readonly Container content;
protected readonly OsuTextBox Name, MaxParticipants;
protected readonly RoomAvailabilityPicker Availability;
protected readonly GameTypePicker Type;
protected readonly TriangleButton Apply;
public RoomSettingsOverlay(Room room)
{
Masking = true;
SettingsTextBox name, maxParticipants;
RoomAvailabilityPicker availability;
GameTypePicker type;
Child = content = new Container
{
RelativeSizeAxes = Axes.Both,
@ -59,15 +61,15 @@ namespace osu.Game.Screens.Multi.Screens.Match.Settings
{
new Section("ROOM NAME")
{
Child = name = new SettingsTextBox(),
Child = Name = new SettingsTextBox(),
},
new Section("ROOM VISIBILITY")
{
Child = availability = new RoomAvailabilityPicker(),
Child = Availability = new RoomAvailabilityPicker(),
},
new Section("GAME TYPE")
{
Child = type = new GameTypePicker(),
Child = Type = new GameTypePicker(),
},
},
},
@ -80,7 +82,7 @@ namespace osu.Game.Screens.Multi.Screens.Match.Settings
{
new Section("MAX PARTICIPANTS")
{
Child = maxParticipants = new SettingsTextBox(),
Child = MaxParticipants = new SettingsTextBox(),
},
new Section("PASSWORD (OPTIONAL)")
{
@ -90,7 +92,7 @@ namespace osu.Game.Screens.Multi.Screens.Match.Settings
},
},
},
new ApplyButton
Apply = new ApplyButton
{
Anchor = Anchor.BottomCentre,
Origin = Anchor.BottomCentre,
@ -100,12 +102,12 @@ namespace osu.Game.Screens.Multi.Screens.Match.Settings
{
if (room != null)
{
room.Name.Value = name.Text;
room.Availability.Value = availability.Current.Value;
room.Type.Value = type.Current.Value;
room.Name.Value = Name.Text;
room.Availability.Value = Availability.Current.Value;
room.Type.Value = Type.Current.Value;
int max;
if (int.TryParse(maxParticipants.Text, out max))
if (int.TryParse(MaxParticipants.Text, out max))
room.MaxParticipants.Value = max;
else
room.MaxParticipants.Value = null;
@ -117,10 +119,10 @@ namespace osu.Game.Screens.Multi.Screens.Match.Settings
},
};
nameBind.ValueChanged += n => name.Text = n;
availabilityBind.ValueChanged += a => availability.Current.Value = a;
typeBind.ValueChanged += t => type.Current.Value = t;
maxParticipantsBind.ValueChanged += m => maxParticipants.Text = m?.ToString();
nameBind.ValueChanged += n => Name.Text = n;
availabilityBind.ValueChanged += a => Availability.Current.Value = a;
typeBind.ValueChanged += t => Type.Current.Value = t;
maxParticipantsBind.ValueChanged += m => MaxParticipants.Text = m?.ToString();
nameBind.BindTo(room.Name);
availabilityBind.BindTo(room.Availability);