2019-01-24 08:43:03 +00: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 05:48:15 +00:00
|
|
|
|
2018-12-22 06:00:35 +00:00
|
|
|
using System;
|
2018-12-26 07:04:05 +00:00
|
|
|
using NUnit.Framework;
|
|
|
|
using osu.Framework.Allocation;
|
2019-02-21 10:04:31 +00:00
|
|
|
using osu.Framework.Bindables;
|
2018-12-22 05:48:15 +00:00
|
|
|
using osu.Framework.Graphics;
|
|
|
|
using osu.Framework.Graphics.Containers;
|
2018-12-26 09:38:58 +00:00
|
|
|
using osu.Game.Graphics.Sprites;
|
2018-12-26 07:04:05 +00:00
|
|
|
using osu.Game.Graphics.UserInterface;
|
2020-12-25 04:38:11 +00:00
|
|
|
using osu.Game.Online.Rooms;
|
2020-12-25 15:50:00 +00:00
|
|
|
using osu.Game.Screens.OnlinePlay;
|
|
|
|
using osu.Game.Screens.OnlinePlay.Playlists;
|
2018-12-22 05:48:15 +00:00
|
|
|
|
2020-12-25 04:20:37 +00:00
|
|
|
namespace osu.Game.Tests.Visual.Playlists
|
2018-12-22 05:48:15 +00:00
|
|
|
{
|
2021-06-23 15:28:39 +00:00
|
|
|
public class TestScenePlaylistsMatchSettingsOverlay : OsuTestScene
|
2018-12-22 05:48:15 +00:00
|
|
|
{
|
2018-12-26 07:04:05 +00:00
|
|
|
[Cached(Type = typeof(IRoomManager))]
|
|
|
|
private TestRoomManager roomManager = new TestRoomManager();
|
|
|
|
|
2021-06-23 15:28:39 +00:00
|
|
|
private TestRoomContainer roomContainer;
|
2018-12-26 07:04:05 +00:00
|
|
|
private TestRoomSettings settings;
|
|
|
|
|
|
|
|
[SetUp]
|
2021-06-23 15:28:39 +00:00
|
|
|
public void Setup() => Schedule(() =>
|
2018-12-22 05:48:15 +00:00
|
|
|
{
|
2021-06-23 15:28:39 +00:00
|
|
|
Child = roomContainer = new TestRoomContainer
|
2018-12-22 05:48:15 +00:00
|
|
|
{
|
2021-06-23 15:28:39 +00:00
|
|
|
Child = settings = new TestRoomSettings
|
|
|
|
{
|
|
|
|
RelativeSizeAxes = Axes.Both,
|
|
|
|
State = { Value = Visibility.Visible }
|
|
|
|
}
|
2018-12-22 05:48:15 +00:00
|
|
|
};
|
2018-12-26 07:04:05 +00:00
|
|
|
});
|
|
|
|
|
|
|
|
[Test]
|
|
|
|
public void TestButtonEnabledOnlyWithNameAndBeatmap()
|
|
|
|
{
|
|
|
|
AddStep("clear name and beatmap", () =>
|
|
|
|
{
|
2021-06-23 15:28:39 +00:00
|
|
|
roomContainer.Room.Name.Value = "";
|
|
|
|
roomContainer.Room.Playlist.Clear();
|
2018-12-26 07:04:05 +00:00
|
|
|
});
|
|
|
|
|
2019-02-21 09:56:34 +00:00
|
|
|
AddAssert("button disabled", () => !settings.ApplyButton.Enabled.Value);
|
2018-12-26 07:04:05 +00:00
|
|
|
|
2021-06-23 15:28:39 +00:00
|
|
|
AddStep("set name", () => roomContainer.Room.Name.Value = "Room name");
|
2019-02-21 09:56:34 +00:00
|
|
|
AddAssert("button disabled", () => !settings.ApplyButton.Enabled.Value);
|
2018-12-26 07:04:05 +00:00
|
|
|
|
2021-06-23 15:28:39 +00:00
|
|
|
AddStep("set beatmap", () => roomContainer.Room.Playlist.Add(new PlaylistItem { Beatmap = { Value = CreateBeatmap(Ruleset.Value).BeatmapInfo } }));
|
2019-02-21 09:56:34 +00:00
|
|
|
AddAssert("button enabled", () => settings.ApplyButton.Enabled.Value);
|
2018-12-26 07:04:05 +00:00
|
|
|
|
2021-06-23 15:28:39 +00:00
|
|
|
AddStep("clear name", () => roomContainer.Room.Name.Value = "");
|
2019-02-21 09:56:34 +00:00
|
|
|
AddAssert("button disabled", () => !settings.ApplyButton.Enabled.Value);
|
2018-12-26 07:04:05 +00: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;
|
2021-06-23 15:28:39 +00:00
|
|
|
roomContainer.Room.Playlist.Add(new PlaylistItem { Beatmap = { Value = CreateBeatmap(Ruleset.Value).BeatmapInfo } });
|
2018-12-26 07:04:05 +00:00
|
|
|
|
2018-12-26 09:38:58 +00:00
|
|
|
roomManager.CreateRequested = r =>
|
|
|
|
{
|
|
|
|
createdRoom = r;
|
|
|
|
return true;
|
|
|
|
};
|
2018-12-26 07:04:05 +00: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);
|
|
|
|
}
|
|
|
|
|
2018-12-26 09:38:58 +00:00
|
|
|
[Test]
|
|
|
|
public void TestCreationFailureDisplaysError()
|
|
|
|
{
|
|
|
|
bool fail;
|
|
|
|
|
|
|
|
AddStep("setup", () =>
|
|
|
|
{
|
2021-06-23 15:28:39 +00:00
|
|
|
roomContainer.Room.Name.Value = "Test Room";
|
|
|
|
roomContainer.Room.Playlist.Add(new PlaylistItem { Beatmap = { Value = CreateBeatmap(Ruleset.Value).BeatmapInfo } });
|
2020-05-19 04:16:46 +00:00
|
|
|
|
2018-12-26 09:38:58 +00:00
|
|
|
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 08:24:26 +00:00
|
|
|
AddUntilStep("error not displayed", () => !settings.ErrorText.IsPresent);
|
2018-12-26 09:38:58 +00:00
|
|
|
}
|
|
|
|
|
2020-12-25 04:11:21 +00:00
|
|
|
private class TestRoomSettings : PlaylistsMatchSettingsOverlay
|
2018-12-26 07:04:05 +00:00
|
|
|
{
|
2020-12-22 06:51:24 +00:00
|
|
|
public TriangleButton ApplyButton => ((MatchSettings)Settings).ApplyButton;
|
2018-12-26 07:04:05 +00:00
|
|
|
|
2020-12-22 06:51:24 +00:00
|
|
|
public OsuTextBox NameField => ((MatchSettings)Settings).NameField;
|
|
|
|
public OsuDropdown<TimeSpan> DurationField => ((MatchSettings)Settings).DurationField;
|
2018-12-26 09:38:58 +00:00
|
|
|
|
2020-12-22 06:51:24 +00:00
|
|
|
public OsuSpriteText ErrorText => ((MatchSettings)Settings).ErrorText;
|
2018-12-26 07:04:05 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
private class TestRoomManager : IRoomManager
|
|
|
|
{
|
2018-12-26 09:38:58 +00:00
|
|
|
public const string FAILED_TEXT = "failed";
|
|
|
|
|
|
|
|
public Func<Room, bool> CreateRequested;
|
2018-12-26 07:04:05 +00:00
|
|
|
|
2019-02-08 07:02:00 +00:00
|
|
|
public event Action RoomsUpdated
|
|
|
|
{
|
2019-02-08 07:02:14 +00:00
|
|
|
add { }
|
|
|
|
remove { }
|
2019-02-08 07:02:00 +00:00
|
|
|
}
|
2018-12-27 16:45:19 +00:00
|
|
|
|
2020-12-20 14:05:17 +00:00
|
|
|
public IBindable<bool> InitialRoomsReceived { get; } = new Bindable<bool>(true);
|
2020-06-05 11:52:27 +00:00
|
|
|
|
2020-11-01 19:51:23 +00:00
|
|
|
public IBindableList<Room> Rooms => null;
|
2018-12-26 07:04:05 +00:00
|
|
|
|
2018-12-26 12:10:31 +00:00
|
|
|
public void CreateRoom(Room room, Action<Room> onSuccess = null, Action<string> onError = null)
|
2018-12-26 09:38:58 +00:00
|
|
|
{
|
|
|
|
if (CreateRequested == null)
|
|
|
|
return;
|
|
|
|
|
|
|
|
if (!CreateRequested.Invoke(room))
|
|
|
|
onError?.Invoke(FAILED_TEXT);
|
2018-12-26 11:45:56 +00:00
|
|
|
else
|
2018-12-26 12:10:31 +00:00
|
|
|
onSuccess?.Invoke(room);
|
2018-12-26 09:38:58 +00:00
|
|
|
}
|
2018-12-26 07:04:05 +00:00
|
|
|
|
2018-12-26 12:10:31 +00:00
|
|
|
public void JoinRoom(Room room, Action<Room> onSuccess = null, Action<string> onError = null) => throw new NotImplementedException();
|
2018-12-26 07:04:05 +00:00
|
|
|
|
|
|
|
public void PartRoom() => throw new NotImplementedException();
|
2018-12-22 05:48:15 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|