1
0
mirror of https://github.com/ppy/osu.git synced 2024-12-16 03:42:58 +08:00
osu-lazer/osu.Game.Tests/Visual/Multiplayer/TestSceneMatchSettingsOverlay.cs

157 lines
5.1 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-22 13:48:15 +08:00
2018-12-22 14:00:35 +08:00
using System;
using System.Collections.Generic;
using NUnit.Framework;
using osu.Framework.Allocation;
2019-02-21 18:04:31 +08:00
using osu.Framework.Bindables;
2018-12-22 13:48:15 +08:00
using osu.Framework.Graphics;
using osu.Framework.Graphics.Containers;
2018-12-26 17:38:58 +08:00
using osu.Game.Graphics.Sprites;
using osu.Game.Graphics.UserInterface;
2018-12-22 13:48:15 +08:00
using osu.Game.Online.Multiplayer;
using osu.Game.Screens.Multi;
2018-12-22 13:48:15 +08:00
using osu.Game.Screens.Multi.Match.Components;
2019-03-25 00:02:36 +08:00
namespace osu.Game.Tests.Visual.Multiplayer
2018-12-22 13:48:15 +08:00
{
public class TestSceneMatchSettingsOverlay : MultiplayerTestScene
2018-12-22 13:48:15 +08:00
{
2018-12-22 14:00:35 +08:00
public override IReadOnlyList<Type> RequiredTypes => new[]
{
typeof(MatchSettingsOverlay)
2018-12-22 14:00:35 +08:00
};
[Cached(Type = typeof(IRoomManager))]
private TestRoomManager roomManager = new TestRoomManager();
private TestRoomSettings settings;
[SetUp]
public void Setup() => Schedule(() =>
2018-12-22 13:48:15 +08:00
{
2019-02-05 18:00:01 +08:00
Room = new Room();
settings = new TestRoomSettings
2018-12-22 13:48:15 +08:00
{
RelativeSizeAxes = Axes.Both,
State = { Value = Visibility.Visible }
2018-12-22 13:48:15 +08:00
};
Child = settings;
});
[Test]
public void TestButtonEnabledOnlyWithNameAndBeatmap()
{
AddStep("clear name and beatmap", () =>
{
2019-02-05 18:00:01 +08:00
Room.Name.Value = "";
Room.Playlist.Clear();
});
2019-02-21 17:56:34 +08:00
AddAssert("button disabled", () => !settings.ApplyButton.Enabled.Value);
2019-02-05 18:00:01 +08:00
AddStep("set name", () => Room.Name.Value = "Room name");
2019-02-21 17:56:34 +08:00
AddAssert("button disabled", () => !settings.ApplyButton.Enabled.Value);
AddStep("set beatmap", () => Room.Playlist.Add(new PlaylistItem { Beatmap = CreateBeatmap(Ruleset.Value).BeatmapInfo }));
2019-02-21 17:56:34 +08:00
AddAssert("button enabled", () => settings.ApplyButton.Enabled.Value);
2019-02-05 18:00:01 +08:00
AddStep("clear name", () => Room.Name.Value = "");
2019-02-21 17:56:34 +08:00
AddAssert("button disabled", () => !settings.ApplyButton.Enabled.Value);
}
[Test]
public void TestCorrectSettingsApplied()
{
const string expected_name = "expected name";
TimeSpan expectedDuration = TimeSpan.FromMinutes(15);
Room createdRoom = null;
AddStep("setup", () =>
{
settings.NameField.Current.Value = expected_name;
settings.DurationField.Current.Value = expectedDuration;
2018-12-26 17:38:58 +08:00
roomManager.CreateRequested = r =>
{
createdRoom = r;
return true;
};
});
AddStep("create room", () => settings.ApplyButton.Action.Invoke());
AddAssert("has correct name", () => createdRoom.Name.Value == expected_name);
AddAssert("has correct duration", () => createdRoom.Duration.Value == expectedDuration);
}
2018-12-26 17:38:58 +08:00
[Test]
public void TestCreationFailureDisplaysError()
{
bool fail;
AddStep("setup", () =>
{
fail = true;
roomManager.CreateRequested = _ => !fail;
});
AddAssert("error not displayed", () => !settings.ErrorText.IsPresent);
AddStep("create room", () => settings.ApplyButton.Action.Invoke());
AddAssert("error displayed", () => settings.ErrorText.IsPresent);
AddAssert("error has correct text", () => settings.ErrorText.Text == TestRoomManager.FAILED_TEXT);
AddStep("create room no fail", () =>
{
fail = false;
settings.ApplyButton.Action.Invoke();
});
2019-03-19 16:24:26 +08:00
AddUntilStep("error not displayed", () => !settings.ErrorText.IsPresent);
2018-12-26 17:38:58 +08:00
}
2018-12-26 19:33:49 +08:00
private class TestRoomSettings : MatchSettingsOverlay
{
2019-02-05 18:00:01 +08:00
public TriangleButton ApplyButton => Settings.ApplyButton;
2019-02-05 18:00:01 +08:00
public OsuTextBox NameField => Settings.NameField;
public OsuDropdown<TimeSpan> DurationField => Settings.DurationField;
2018-12-26 17:38:58 +08:00
2019-02-05 18:00:01 +08:00
public OsuSpriteText ErrorText => Settings.ErrorText;
}
private class TestRoomManager : IRoomManager
{
2018-12-26 17:38:58 +08:00
public const string FAILED_TEXT = "failed";
public Func<Room, bool> CreateRequested;
2019-02-08 15:02:00 +08:00
public event Action RoomsUpdated
{
2019-02-08 15:02:14 +08:00
add { }
remove { }
2019-02-08 15:02:00 +08:00
}
2018-12-28 00:45:19 +08:00
2019-01-07 17:50:27 +08:00
public IBindableList<Room> Rooms { get; } = null;
public void CreateRoom(Room room, Action<Room> onSuccess = null, Action<string> onError = null)
2018-12-26 17:38:58 +08:00
{
if (CreateRequested == null)
return;
if (!CreateRequested.Invoke(room))
onError?.Invoke(FAILED_TEXT);
else
onSuccess?.Invoke(room);
2018-12-26 17:38:58 +08:00
}
public void JoinRoom(Room room, Action<Room> onSuccess = null, Action<string> onError = null) => throw new NotImplementedException();
public void PartRoom() => throw new NotImplementedException();
2018-12-22 13:48:15 +08:00
}
}
}