2019-01-24 17:43:03 +09: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 14:48:15 +09:00
|
|
|
|
2018-12-22 15:00:35 +09:00
|
|
|
using System;
|
2018-12-26 16:04:05 +09:00
|
|
|
using NUnit.Framework;
|
2018-12-22 14:48:15 +09:00
|
|
|
using osu.Framework.Graphics;
|
|
|
|
using osu.Framework.Graphics.Containers;
|
2018-12-26 18:38:58 +09:00
|
|
|
using osu.Game.Graphics.Sprites;
|
2018-12-26 16:04:05 +09:00
|
|
|
using osu.Game.Graphics.UserInterface;
|
2022-11-24 16:26:57 +09:00
|
|
|
using osu.Game.Graphics.UserInterfaceV2;
|
2025-01-23 16:19:09 +09:00
|
|
|
using osu.Game.Online.API;
|
2020-12-25 13:38:11 +09:00
|
|
|
using osu.Game.Online.Rooms;
|
2020-12-25 16:50:00 +01:00
|
|
|
using osu.Game.Screens.OnlinePlay.Playlists;
|
2021-06-24 16:29:06 +09:00
|
|
|
using osu.Game.Tests.Visual.OnlinePlay;
|
2018-12-22 14:48:15 +09:00
|
|
|
|
2020-12-25 13:20:37 +09:00
|
|
|
namespace osu.Game.Tests.Visual.Playlists
|
2018-12-22 14:48:15 +09:00
|
|
|
{
|
2021-06-25 13:02:19 +09:00
|
|
|
public partial class TestScenePlaylistsMatchSettingsOverlay : OnlinePlayTestScene
|
2018-12-22 14:48:15 +09:00
|
|
|
{
|
2024-11-13 16:55:18 +09:00
|
|
|
private TestRoomSettings settings = null!;
|
2025-01-23 16:19:09 +09:00
|
|
|
private Func<Room, string?>? handleRequest;
|
2021-06-25 13:02:19 +09:00
|
|
|
|
2022-07-29 15:27:39 +09:00
|
|
|
public override void SetUpSteps()
|
2018-12-22 14:48:15 +09:00
|
|
|
{
|
2022-07-29 15:27:39 +09:00
|
|
|
base.SetUpSteps();
|
2021-06-25 13:02:19 +09:00
|
|
|
|
2025-01-23 16:19:09 +09:00
|
|
|
AddStep("setup api", () =>
|
|
|
|
{
|
|
|
|
handleRequest = null;
|
|
|
|
((DummyAPIAccess)API).HandleRequest = req =>
|
|
|
|
{
|
|
|
|
if (req is not CreateRoomRequest createReq || handleRequest == null)
|
|
|
|
return false;
|
|
|
|
|
|
|
|
if (handleRequest(createReq.Room) is string errorText)
|
|
|
|
createReq.TriggerFailure(new APIException(errorText, null));
|
|
|
|
else
|
|
|
|
{
|
|
|
|
var createdRoom = new APICreatedRoom();
|
|
|
|
createdRoom.CopyFrom(createReq.Room);
|
|
|
|
createReq.TriggerSuccess(createdRoom);
|
|
|
|
}
|
|
|
|
|
|
|
|
return true;
|
|
|
|
};
|
|
|
|
});
|
|
|
|
|
2022-07-29 15:27:39 +09:00
|
|
|
AddStep("create overlay", () =>
|
2018-12-22 14:48:15 +09:00
|
|
|
{
|
2022-07-29 15:27:39 +09:00
|
|
|
SelectedRoom.Value = new Room();
|
|
|
|
|
2024-11-21 20:26:44 +09:00
|
|
|
Child = settings = new TestRoomSettings(SelectedRoom.Value!)
|
2022-07-29 15:27:39 +09:00
|
|
|
{
|
|
|
|
RelativeSizeAxes = Axes.Both,
|
|
|
|
State = { Value = Visibility.Visible }
|
|
|
|
};
|
|
|
|
});
|
|
|
|
}
|
2018-12-26 16:04:05 +09:00
|
|
|
|
|
|
|
[Test]
|
|
|
|
public void TestButtonEnabledOnlyWithNameAndBeatmap()
|
|
|
|
{
|
|
|
|
AddStep("clear name and beatmap", () =>
|
|
|
|
{
|
2024-11-21 20:26:44 +09:00
|
|
|
SelectedRoom.Value!.Name = "";
|
|
|
|
SelectedRoom.Value!.Playlist = [];
|
2018-12-26 16:04:05 +09:00
|
|
|
});
|
|
|
|
|
2019-02-21 18:56:34 +09:00
|
|
|
AddAssert("button disabled", () => !settings.ApplyButton.Enabled.Value);
|
2018-12-26 16:04:05 +09:00
|
|
|
|
2024-11-21 20:26:44 +09:00
|
|
|
AddStep("set name", () => SelectedRoom.Value!.Name = "Room name");
|
2019-02-21 18:56:34 +09:00
|
|
|
AddAssert("button disabled", () => !settings.ApplyButton.Enabled.Value);
|
2018-12-26 16:04:05 +09:00
|
|
|
|
2024-11-21 20:26:44 +09:00
|
|
|
AddStep("set beatmap", () => SelectedRoom.Value!.Playlist = [new PlaylistItem(CreateBeatmap(Ruleset.Value).BeatmapInfo)]);
|
2019-02-21 18:56:34 +09:00
|
|
|
AddAssert("button enabled", () => settings.ApplyButton.Enabled.Value);
|
2018-12-26 16:04:05 +09:00
|
|
|
|
2024-11-21 20:26:44 +09:00
|
|
|
AddStep("clear name", () => SelectedRoom.Value!.Name = "");
|
2019-02-21 18:56:34 +09:00
|
|
|
AddAssert("button disabled", () => !settings.ApplyButton.Enabled.Value);
|
2018-12-26 16:04:05 +09:00
|
|
|
}
|
|
|
|
|
|
|
|
[Test]
|
|
|
|
public void TestCorrectSettingsApplied()
|
|
|
|
{
|
|
|
|
const string expected_name = "expected name";
|
|
|
|
TimeSpan expectedDuration = TimeSpan.FromMinutes(15);
|
|
|
|
|
2024-11-13 16:55:18 +09:00
|
|
|
Room createdRoom = null!;
|
2018-12-26 16:04:05 +09:00
|
|
|
|
|
|
|
AddStep("setup", () =>
|
|
|
|
{
|
|
|
|
settings.NameField.Current.Value = expected_name;
|
|
|
|
settings.DurationField.Current.Value = expectedDuration;
|
2024-11-21 20:26:44 +09:00
|
|
|
SelectedRoom.Value!.Playlist = [new PlaylistItem(CreateBeatmap(Ruleset.Value).BeatmapInfo)];
|
2018-12-26 16:04:05 +09:00
|
|
|
|
2025-01-23 16:19:09 +09:00
|
|
|
handleRequest = r =>
|
2018-12-26 18:38:58 +09:00
|
|
|
{
|
|
|
|
createdRoom = r;
|
2025-01-23 16:19:09 +09:00
|
|
|
return null;
|
2018-12-26 18:38:58 +09:00
|
|
|
};
|
2018-12-26 16:04:05 +09:00
|
|
|
});
|
|
|
|
|
|
|
|
AddStep("create room", () => settings.ApplyButton.Action.Invoke());
|
2024-11-13 16:55:18 +09:00
|
|
|
AddAssert("has correct name", () => createdRoom.Name == expected_name);
|
2024-11-13 20:20:14 +09:00
|
|
|
AddAssert("has correct duration", () => createdRoom.Duration == expectedDuration);
|
2018-12-26 16:04:05 +09:00
|
|
|
}
|
|
|
|
|
2021-11-16 17:08:21 +09:00
|
|
|
[Test]
|
|
|
|
public void TestInvalidBeatmapError()
|
|
|
|
{
|
|
|
|
const string not_found_prefix = "beatmaps not found:";
|
|
|
|
|
2024-11-13 16:55:18 +09:00
|
|
|
string errorMessage = null!;
|
2021-11-16 17:08:21 +09:00
|
|
|
|
|
|
|
AddStep("setup", () =>
|
|
|
|
{
|
|
|
|
var beatmap = CreateBeatmap(Ruleset.Value).BeatmapInfo;
|
|
|
|
|
2024-11-21 20:26:44 +09:00
|
|
|
SelectedRoom.Value!.Name = "Test Room";
|
|
|
|
SelectedRoom.Value!.Playlist = [new PlaylistItem(beatmap)];
|
2021-11-16 17:08:21 +09:00
|
|
|
|
2021-12-09 21:04:31 -08:00
|
|
|
errorMessage = $"{not_found_prefix} {beatmap.OnlineID}";
|
2021-11-16 17:08:21 +09:00
|
|
|
|
2025-01-23 16:19:09 +09:00
|
|
|
handleRequest = _ => errorMessage;
|
2021-11-16 17:08:21 +09:00
|
|
|
});
|
|
|
|
|
|
|
|
AddAssert("error not displayed", () => !settings.ErrorText.IsPresent);
|
2024-11-21 20:26:44 +09:00
|
|
|
AddAssert("playlist item valid", () => SelectedRoom.Value!.Playlist[0].Valid.Value);
|
2021-11-16 17:08:21 +09:00
|
|
|
|
|
|
|
AddStep("create room", () => settings.ApplyButton.Action.Invoke());
|
|
|
|
|
|
|
|
AddAssert("error displayed", () => settings.ErrorText.IsPresent);
|
2021-12-09 21:04:31 -08:00
|
|
|
AddAssert("error has custom text", () => settings.ErrorText.Text != errorMessage);
|
2024-11-21 20:26:44 +09:00
|
|
|
AddAssert("playlist item marked invalid", () => !SelectedRoom.Value!.Playlist[0].Valid.Value);
|
2021-11-16 17:08:21 +09:00
|
|
|
}
|
|
|
|
|
2018-12-26 18:38:58 +09:00
|
|
|
[Test]
|
|
|
|
public void TestCreationFailureDisplaysError()
|
|
|
|
{
|
2021-11-16 17:08:21 +09:00
|
|
|
const string error_message = "failed";
|
|
|
|
|
|
|
|
string failText = error_message;
|
2018-12-26 18:38:58 +09:00
|
|
|
|
|
|
|
AddStep("setup", () =>
|
|
|
|
{
|
2024-11-21 20:26:44 +09:00
|
|
|
SelectedRoom.Value!.Name = "Test Room";
|
|
|
|
SelectedRoom.Value!.Playlist = [new PlaylistItem(CreateBeatmap(Ruleset.Value).BeatmapInfo)];
|
2020-05-19 13:16:46 +09:00
|
|
|
|
2025-01-23 16:19:09 +09:00
|
|
|
handleRequest = _ => failText;
|
2018-12-26 18:38:58 +09:00
|
|
|
});
|
|
|
|
AddAssert("error not displayed", () => !settings.ErrorText.IsPresent);
|
|
|
|
|
|
|
|
AddStep("create room", () => settings.ApplyButton.Action.Invoke());
|
|
|
|
AddAssert("error displayed", () => settings.ErrorText.IsPresent);
|
2021-11-16 17:08:21 +09:00
|
|
|
AddAssert("error has correct text", () => settings.ErrorText.Text == error_message);
|
2018-12-26 18:38:58 +09:00
|
|
|
|
|
|
|
AddStep("create room no fail", () =>
|
|
|
|
{
|
2021-11-16 17:08:21 +09:00
|
|
|
failText = string.Empty;
|
2018-12-26 18:38:58 +09:00
|
|
|
settings.ApplyButton.Action.Invoke();
|
|
|
|
});
|
|
|
|
|
2019-03-19 17:24:26 +09:00
|
|
|
AddUntilStep("error not displayed", () => !settings.ErrorText.IsPresent);
|
2018-12-26 18:38:58 +09:00
|
|
|
}
|
|
|
|
|
2021-08-17 17:14:21 +09:00
|
|
|
private partial class TestRoomSettings : PlaylistsRoomSettingsOverlay
|
2018-12-26 16:04:05 +09:00
|
|
|
{
|
2022-11-24 16:26:57 +09:00
|
|
|
public RoundedButton ApplyButton => ((MatchSettings)Settings).ApplyButton;
|
2018-12-26 16:04:05 +09:00
|
|
|
|
2020-12-22 15:51:24 +09:00
|
|
|
public OsuTextBox NameField => ((MatchSettings)Settings).NameField;
|
|
|
|
public OsuDropdown<TimeSpan> DurationField => ((MatchSettings)Settings).DurationField;
|
2018-12-26 18:38:58 +09:00
|
|
|
|
2020-12-22 15:51:24 +09:00
|
|
|
public OsuSpriteText ErrorText => ((MatchSettings)Settings).ErrorText;
|
2021-08-19 16:40:27 +09:00
|
|
|
|
|
|
|
public TestRoomSettings(Room room)
|
|
|
|
: base(room)
|
|
|
|
{
|
|
|
|
}
|
2018-12-26 16:04:05 +09:00
|
|
|
}
|
2018-12-22 14:48:15 +09:00
|
|
|
}
|
|
|
|
}
|