2019-01-24 16:43:03 +08:00
|
|
|
// 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
|
|
|
|
2022-06-17 15:37:17 +08:00
|
|
|
#nullable disable
|
|
|
|
|
2018-12-22 14:00:35 +08:00
|
|
|
using System;
|
2018-12-26 15:04:05 +08:00
|
|
|
using NUnit.Framework;
|
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;
|
2018-12-26 15:04:05 +08:00
|
|
|
using osu.Game.Graphics.UserInterface;
|
2020-12-25 12:38:11 +08:00
|
|
|
using osu.Game.Online.Rooms;
|
2020-12-25 23:50:00 +08:00
|
|
|
using osu.Game.Screens.OnlinePlay;
|
|
|
|
using osu.Game.Screens.OnlinePlay.Playlists;
|
2021-06-24 15:29:06 +08:00
|
|
|
using osu.Game.Tests.Visual.OnlinePlay;
|
2018-12-22 13:48:15 +08:00
|
|
|
|
2020-12-25 12:20:37 +08:00
|
|
|
namespace osu.Game.Tests.Visual.Playlists
|
2018-12-22 13:48:15 +08:00
|
|
|
{
|
2021-06-25 12:02:19 +08:00
|
|
|
public class TestScenePlaylistsMatchSettingsOverlay : OnlinePlayTestScene
|
2018-12-22 13:48:15 +08:00
|
|
|
{
|
2021-06-25 12:02:19 +08:00
|
|
|
protected new TestRoomManager RoomManager => (TestRoomManager)base.RoomManager;
|
2018-12-26 15:04:05 +08:00
|
|
|
|
|
|
|
private TestRoomSettings settings;
|
|
|
|
|
2021-06-25 19:11:38 +08:00
|
|
|
protected override OnlinePlayTestSceneDependencies CreateOnlinePlayDependencies() => new TestDependencies();
|
2021-06-25 12:02:19 +08:00
|
|
|
|
2022-07-29 14:27:39 +08:00
|
|
|
public override void SetUpSteps()
|
2018-12-22 13:48:15 +08:00
|
|
|
{
|
2022-07-29 14:27:39 +08:00
|
|
|
base.SetUpSteps();
|
2021-06-25 12:02:19 +08:00
|
|
|
|
2022-07-29 14:27:39 +08:00
|
|
|
AddStep("create overlay", () =>
|
2018-12-22 13:48:15 +08:00
|
|
|
{
|
2022-07-29 14:27:39 +08:00
|
|
|
SelectedRoom.Value = new Room();
|
|
|
|
|
|
|
|
Child = settings = new TestRoomSettings(SelectedRoom.Value)
|
|
|
|
{
|
|
|
|
RelativeSizeAxes = Axes.Both,
|
|
|
|
State = { Value = Visibility.Visible }
|
|
|
|
};
|
|
|
|
});
|
|
|
|
}
|
2018-12-26 15:04:05 +08:00
|
|
|
|
|
|
|
[Test]
|
|
|
|
public void TestButtonEnabledOnlyWithNameAndBeatmap()
|
|
|
|
{
|
|
|
|
AddStep("clear name and beatmap", () =>
|
|
|
|
{
|
2021-06-25 12:02:19 +08:00
|
|
|
SelectedRoom.Value.Name.Value = "";
|
|
|
|
SelectedRoom.Value.Playlist.Clear();
|
2018-12-26 15:04:05 +08:00
|
|
|
});
|
|
|
|
|
2019-02-21 17:56:34 +08:00
|
|
|
AddAssert("button disabled", () => !settings.ApplyButton.Enabled.Value);
|
2018-12-26 15:04:05 +08:00
|
|
|
|
2021-06-25 12:02:19 +08:00
|
|
|
AddStep("set name", () => SelectedRoom.Value.Name.Value = "Room name");
|
2019-02-21 17:56:34 +08:00
|
|
|
AddAssert("button disabled", () => !settings.ApplyButton.Enabled.Value);
|
2018-12-26 15:04:05 +08:00
|
|
|
|
2022-02-15 22:33:26 +08:00
|
|
|
AddStep("set beatmap", () => SelectedRoom.Value.Playlist.Add(new PlaylistItem(CreateBeatmap(Ruleset.Value).BeatmapInfo)));
|
2019-02-21 17:56:34 +08:00
|
|
|
AddAssert("button enabled", () => settings.ApplyButton.Enabled.Value);
|
2018-12-26 15:04:05 +08:00
|
|
|
|
2021-06-25 12:02:19 +08:00
|
|
|
AddStep("clear name", () => SelectedRoom.Value.Name.Value = "");
|
2019-02-21 17:56:34 +08:00
|
|
|
AddAssert("button disabled", () => !settings.ApplyButton.Enabled.Value);
|
2018-12-26 15:04:05 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
[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;
|
2022-02-15 22:33:26 +08:00
|
|
|
SelectedRoom.Value.Playlist.Add(new PlaylistItem(CreateBeatmap(Ruleset.Value).BeatmapInfo));
|
2018-12-26 15:04:05 +08:00
|
|
|
|
2021-06-25 12:02:19 +08:00
|
|
|
RoomManager.CreateRequested = r =>
|
2018-12-26 17:38:58 +08:00
|
|
|
{
|
|
|
|
createdRoom = r;
|
2021-11-16 16:08:21 +08:00
|
|
|
return string.Empty;
|
2018-12-26 17:38:58 +08:00
|
|
|
};
|
2018-12-26 15:04:05 +08:00
|
|
|
});
|
|
|
|
|
|
|
|
AddStep("create room", () => settings.ApplyButton.Action.Invoke());
|
|
|
|
AddAssert("has correct name", () => createdRoom.Name.Value == expected_name);
|
|
|
|
AddAssert("has correct duration", () => createdRoom.Duration.Value == expectedDuration);
|
|
|
|
}
|
|
|
|
|
2021-11-16 16:08:21 +08:00
|
|
|
[Test]
|
|
|
|
public void TestInvalidBeatmapError()
|
|
|
|
{
|
|
|
|
const string not_found_prefix = "beatmaps not found:";
|
|
|
|
|
2021-12-10 13:04:31 +08:00
|
|
|
string errorMessage = null;
|
2021-11-16 16:08:21 +08:00
|
|
|
|
|
|
|
AddStep("setup", () =>
|
|
|
|
{
|
|
|
|
var beatmap = CreateBeatmap(Ruleset.Value).BeatmapInfo;
|
|
|
|
|
|
|
|
SelectedRoom.Value.Name.Value = "Test Room";
|
2022-02-15 22:33:26 +08:00
|
|
|
SelectedRoom.Value.Playlist.Add(new PlaylistItem(beatmap));
|
2021-11-16 16:08:21 +08:00
|
|
|
|
2021-12-10 13:04:31 +08:00
|
|
|
errorMessage = $"{not_found_prefix} {beatmap.OnlineID}";
|
2021-11-16 16:08:21 +08:00
|
|
|
|
2021-12-10 13:04:31 +08:00
|
|
|
RoomManager.CreateRequested = _ => errorMessage;
|
2021-11-16 16:08:21 +08:00
|
|
|
});
|
|
|
|
|
|
|
|
AddAssert("error not displayed", () => !settings.ErrorText.IsPresent);
|
|
|
|
AddAssert("playlist item valid", () => SelectedRoom.Value.Playlist[0].Valid.Value);
|
|
|
|
|
|
|
|
AddStep("create room", () => settings.ApplyButton.Action.Invoke());
|
|
|
|
|
|
|
|
AddAssert("error displayed", () => settings.ErrorText.IsPresent);
|
2021-12-10 13:04:31 +08:00
|
|
|
AddAssert("error has custom text", () => settings.ErrorText.Text != errorMessage);
|
2021-11-16 16:08:21 +08:00
|
|
|
AddAssert("playlist item marked invalid", () => !SelectedRoom.Value.Playlist[0].Valid.Value);
|
|
|
|
}
|
|
|
|
|
2018-12-26 17:38:58 +08:00
|
|
|
[Test]
|
|
|
|
public void TestCreationFailureDisplaysError()
|
|
|
|
{
|
2021-11-16 16:08:21 +08:00
|
|
|
const string error_message = "failed";
|
|
|
|
|
|
|
|
string failText = error_message;
|
2018-12-26 17:38:58 +08:00
|
|
|
|
|
|
|
AddStep("setup", () =>
|
|
|
|
{
|
2021-06-25 12:02:19 +08:00
|
|
|
SelectedRoom.Value.Name.Value = "Test Room";
|
2022-02-15 22:33:26 +08:00
|
|
|
SelectedRoom.Value.Playlist.Add(new PlaylistItem(CreateBeatmap(Ruleset.Value).BeatmapInfo));
|
2020-05-19 12:16:46 +08:00
|
|
|
|
2021-11-16 16:08:21 +08:00
|
|
|
RoomManager.CreateRequested = _ => failText;
|
2018-12-26 17:38:58 +08:00
|
|
|
});
|
|
|
|
AddAssert("error not displayed", () => !settings.ErrorText.IsPresent);
|
|
|
|
|
|
|
|
AddStep("create room", () => settings.ApplyButton.Action.Invoke());
|
|
|
|
AddAssert("error displayed", () => settings.ErrorText.IsPresent);
|
2021-11-16 16:08:21 +08:00
|
|
|
AddAssert("error has correct text", () => settings.ErrorText.Text == error_message);
|
2018-12-26 17:38:58 +08:00
|
|
|
|
|
|
|
AddStep("create room no fail", () =>
|
|
|
|
{
|
2021-11-16 16:08:21 +08:00
|
|
|
failText = string.Empty;
|
2018-12-26 17:38:58 +08:00
|
|
|
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
|
|
|
}
|
|
|
|
|
2021-08-17 16:14:21 +08:00
|
|
|
private class TestRoomSettings : PlaylistsRoomSettingsOverlay
|
2018-12-26 15:04:05 +08:00
|
|
|
{
|
2020-12-22 14:51:24 +08:00
|
|
|
public TriangleButton ApplyButton => ((MatchSettings)Settings).ApplyButton;
|
2018-12-26 15:04:05 +08:00
|
|
|
|
2020-12-22 14:51:24 +08:00
|
|
|
public OsuTextBox NameField => ((MatchSettings)Settings).NameField;
|
|
|
|
public OsuDropdown<TimeSpan> DurationField => ((MatchSettings)Settings).DurationField;
|
2018-12-26 17:38:58 +08:00
|
|
|
|
2020-12-22 14:51:24 +08:00
|
|
|
public OsuSpriteText ErrorText => ((MatchSettings)Settings).ErrorText;
|
2021-08-19 15:40:27 +08:00
|
|
|
|
|
|
|
public TestRoomSettings(Room room)
|
|
|
|
: base(room)
|
|
|
|
{
|
|
|
|
}
|
2018-12-26 15:04:05 +08:00
|
|
|
}
|
|
|
|
|
2021-06-25 19:11:38 +08:00
|
|
|
private class TestDependencies : OnlinePlayTestSceneDependencies
|
2021-06-25 12:02:19 +08:00
|
|
|
{
|
|
|
|
protected override IRoomManager CreateRoomManager() => new TestRoomManager();
|
|
|
|
}
|
|
|
|
|
|
|
|
protected class TestRoomManager : IRoomManager
|
2018-12-26 15:04:05 +08:00
|
|
|
{
|
2021-11-16 16:08:21 +08:00
|
|
|
public Func<Room, string> CreateRequested;
|
2018-12-26 15:04:05 +08:00
|
|
|
|
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
|
|
|
|
2020-12-20 22:05:17 +08:00
|
|
|
public IBindable<bool> InitialRoomsReceived { get; } = new Bindable<bool>(true);
|
2020-06-05 19:52:27 +08:00
|
|
|
|
2020-11-02 03:51:23 +08:00
|
|
|
public IBindableList<Room> Rooms => null;
|
2018-12-26 15:04:05 +08:00
|
|
|
|
2021-08-16 11:44:12 +08:00
|
|
|
public void AddOrUpdateRoom(Room room) => throw new NotImplementedException();
|
2021-08-13 16:39:09 +08:00
|
|
|
|
2021-08-16 11:44:12 +08:00
|
|
|
public void RemoveRoom(Room room) => throw new NotImplementedException();
|
2021-08-13 16:39:09 +08:00
|
|
|
|
2021-08-16 11:44:12 +08:00
|
|
|
public void ClearRooms() => throw new NotImplementedException();
|
2021-08-13 16:39:09 +08:00
|
|
|
|
2018-12-26 20:10:31 +08:00
|
|
|
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;
|
|
|
|
|
2021-11-16 16:08:21 +08:00
|
|
|
string error = CreateRequested.Invoke(room);
|
|
|
|
|
|
|
|
if (!string.IsNullOrEmpty(error))
|
|
|
|
onError?.Invoke(error);
|
2018-12-26 19:45:56 +08:00
|
|
|
else
|
2018-12-26 20:10:31 +08:00
|
|
|
onSuccess?.Invoke(room);
|
2018-12-26 17:38:58 +08:00
|
|
|
}
|
2018-12-26 15:04:05 +08:00
|
|
|
|
2021-07-10 15:08:12 +08:00
|
|
|
public void JoinRoom(Room room, string password, Action<Room> onSuccess = null, Action<string> onError = null) => throw new NotImplementedException();
|
2018-12-26 15:04:05 +08:00
|
|
|
|
|
|
|
public void PartRoom() => throw new NotImplementedException();
|
2018-12-22 13:48:15 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|