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

Add tests and disable selection on invalid items

This commit is contained in:
Dean Herbert 2021-11-16 17:08:21 +09:00
parent 6f82e6351f
commit 2d125893fc
3 changed files with 55 additions and 12 deletions

View File

@ -67,6 +67,19 @@ namespace osu.Game.Tests.Visual.Multiplayer
AddAssert("no item selected", () => playlist.SelectedItem.Value == null);
}
[Test]
public void TestMarkInvalid()
{
createPlaylist(true, true);
AddStep("mark item 0 as invalid", () => playlist.Items[0].MarkInvalid());
moveToItem(0);
AddStep("click", () => InputManager.Click(MouseButton.Left));
AddAssert("no item selected", () => playlist.SelectedItem.Value == null);
}
[Test]
public void TestSelectable()
{

View File

@ -73,7 +73,7 @@ namespace osu.Game.Tests.Visual.Playlists
RoomManager.CreateRequested = r =>
{
createdRoom = r;
return true;
return string.Empty;
};
});
@ -82,28 +82,58 @@ namespace osu.Game.Tests.Visual.Playlists
AddAssert("has correct duration", () => createdRoom.Duration.Value == expectedDuration);
}
[Test]
public void TestInvalidBeatmapError()
{
const string not_found_prefix = "beatmaps not found:";
string errorMesage = null;
AddStep("setup", () =>
{
var beatmap = CreateBeatmap(Ruleset.Value).BeatmapInfo;
SelectedRoom.Value.Name.Value = "Test Room";
SelectedRoom.Value.Playlist.Add(new PlaylistItem { Beatmap = { Value = beatmap } });
errorMesage = $"{not_found_prefix} {beatmap.OnlineID}";
RoomManager.CreateRequested = _ => errorMesage;
});
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);
AddAssert("error has custom text", () => settings.ErrorText.Text != errorMesage);
AddAssert("playlist item marked invalid", () => !SelectedRoom.Value.Playlist[0].Valid.Value);
}
[Test]
public void TestCreationFailureDisplaysError()
{
bool fail;
const string error_message = "failed";
string failText = error_message;
AddStep("setup", () =>
{
SelectedRoom.Value.Name.Value = "Test Room";
SelectedRoom.Value.Playlist.Add(new PlaylistItem { Beatmap = { Value = CreateBeatmap(Ruleset.Value).BeatmapInfo } });
fail = true;
RoomManager.CreateRequested = _ => !fail;
RoomManager.CreateRequested = _ => failText;
});
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);
AddAssert("error has correct text", () => settings.ErrorText.Text == error_message);
AddStep("create room no fail", () =>
{
fail = false;
failText = string.Empty;
settings.ApplyButton.Action.Invoke();
});
@ -132,9 +162,7 @@ namespace osu.Game.Tests.Visual.Playlists
protected class TestRoomManager : IRoomManager
{
public const string FAILED_TEXT = "failed";
public Func<Room, bool> CreateRequested;
public Func<Room, string> CreateRequested;
public event Action RoomsUpdated
{
@ -157,8 +185,10 @@ namespace osu.Game.Tests.Visual.Playlists
if (CreateRequested == null)
return;
if (!CreateRequested.Invoke(room))
onError?.Invoke(FAILED_TEXT);
string error = CreateRequested.Invoke(room);
if (!string.IsNullOrEmpty(error))
onError?.Invoke(error);
else
onSuccess?.Invoke(room);
}

View File

@ -281,7 +281,7 @@ namespace osu.Game.Screens.OnlinePlay
protected override bool OnClick(ClickEvent e)
{
if (allowSelection)
if (allowSelection && valid.Value)
SelectedItem.Value = Model;
return true;
}