mirror of
https://github.com/ppy/osu.git
synced 2024-12-14 10:52:53 +08:00
Add tests and disable selection on invalid items
This commit is contained in:
parent
6f82e6351f
commit
2d125893fc
@ -67,6 +67,19 @@ namespace osu.Game.Tests.Visual.Multiplayer
|
|||||||
AddAssert("no item selected", () => playlist.SelectedItem.Value == null);
|
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]
|
[Test]
|
||||||
public void TestSelectable()
|
public void TestSelectable()
|
||||||
{
|
{
|
||||||
|
@ -73,7 +73,7 @@ namespace osu.Game.Tests.Visual.Playlists
|
|||||||
RoomManager.CreateRequested = r =>
|
RoomManager.CreateRequested = r =>
|
||||||
{
|
{
|
||||||
createdRoom = 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);
|
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]
|
[Test]
|
||||||
public void TestCreationFailureDisplaysError()
|
public void TestCreationFailureDisplaysError()
|
||||||
{
|
{
|
||||||
bool fail;
|
const string error_message = "failed";
|
||||||
|
|
||||||
|
string failText = error_message;
|
||||||
|
|
||||||
AddStep("setup", () =>
|
AddStep("setup", () =>
|
||||||
{
|
{
|
||||||
SelectedRoom.Value.Name.Value = "Test Room";
|
SelectedRoom.Value.Name.Value = "Test Room";
|
||||||
SelectedRoom.Value.Playlist.Add(new PlaylistItem { Beatmap = { Value = CreateBeatmap(Ruleset.Value).BeatmapInfo } });
|
SelectedRoom.Value.Playlist.Add(new PlaylistItem { Beatmap = { Value = CreateBeatmap(Ruleset.Value).BeatmapInfo } });
|
||||||
|
|
||||||
fail = true;
|
RoomManager.CreateRequested = _ => failText;
|
||||||
RoomManager.CreateRequested = _ => !fail;
|
|
||||||
});
|
});
|
||||||
AddAssert("error not displayed", () => !settings.ErrorText.IsPresent);
|
AddAssert("error not displayed", () => !settings.ErrorText.IsPresent);
|
||||||
|
|
||||||
AddStep("create room", () => settings.ApplyButton.Action.Invoke());
|
AddStep("create room", () => settings.ApplyButton.Action.Invoke());
|
||||||
AddAssert("error displayed", () => settings.ErrorText.IsPresent);
|
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", () =>
|
AddStep("create room no fail", () =>
|
||||||
{
|
{
|
||||||
fail = false;
|
failText = string.Empty;
|
||||||
settings.ApplyButton.Action.Invoke();
|
settings.ApplyButton.Action.Invoke();
|
||||||
});
|
});
|
||||||
|
|
||||||
@ -132,9 +162,7 @@ namespace osu.Game.Tests.Visual.Playlists
|
|||||||
|
|
||||||
protected class TestRoomManager : IRoomManager
|
protected class TestRoomManager : IRoomManager
|
||||||
{
|
{
|
||||||
public const string FAILED_TEXT = "failed";
|
public Func<Room, string> CreateRequested;
|
||||||
|
|
||||||
public Func<Room, bool> CreateRequested;
|
|
||||||
|
|
||||||
public event Action RoomsUpdated
|
public event Action RoomsUpdated
|
||||||
{
|
{
|
||||||
@ -157,8 +185,10 @@ namespace osu.Game.Tests.Visual.Playlists
|
|||||||
if (CreateRequested == null)
|
if (CreateRequested == null)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
if (!CreateRequested.Invoke(room))
|
string error = CreateRequested.Invoke(room);
|
||||||
onError?.Invoke(FAILED_TEXT);
|
|
||||||
|
if (!string.IsNullOrEmpty(error))
|
||||||
|
onError?.Invoke(error);
|
||||||
else
|
else
|
||||||
onSuccess?.Invoke(room);
|
onSuccess?.Invoke(room);
|
||||||
}
|
}
|
||||||
|
@ -281,7 +281,7 @@ namespace osu.Game.Screens.OnlinePlay
|
|||||||
|
|
||||||
protected override bool OnClick(ClickEvent e)
|
protected override bool OnClick(ClickEvent e)
|
||||||
{
|
{
|
||||||
if (allowSelection)
|
if (allowSelection && valid.Value)
|
||||||
SelectedItem.Value = Model;
|
SelectedItem.Value = Model;
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user