mirror of
https://github.com/ppy/osu.git
synced 2025-02-20 00:52:56 +08:00
Add test coverage for favourite button
This commit is contained in:
parent
0faa26fc13
commit
5cb533004d
@ -0,0 +1,86 @@
|
|||||||
|
// 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.
|
||||||
|
|
||||||
|
using System.Linq;
|
||||||
|
using NUnit.Framework;
|
||||||
|
using osu.Framework.Allocation;
|
||||||
|
using osu.Framework.Graphics.Sprites;
|
||||||
|
using osu.Framework.Testing;
|
||||||
|
using osu.Game.Beatmaps.Drawables.Cards.Buttons;
|
||||||
|
using osu.Game.Online.API;
|
||||||
|
using osu.Game.Online.API.Requests;
|
||||||
|
using osu.Game.Online.API.Requests.Responses;
|
||||||
|
using osu.Game.Overlays;
|
||||||
|
using osu.Game.Resources.Localisation.Web;
|
||||||
|
using osuTK;
|
||||||
|
using osuTK.Input;
|
||||||
|
|
||||||
|
namespace osu.Game.Tests.Visual.Beatmaps
|
||||||
|
{
|
||||||
|
public class TestSceneBeatmapCardFavouriteButton : OsuManualInputManagerTestScene
|
||||||
|
{
|
||||||
|
private DummyAPIAccess dummyAPI => (DummyAPIAccess)API;
|
||||||
|
|
||||||
|
[Cached]
|
||||||
|
private OverlayColourProvider colourProvider = new OverlayColourProvider(OverlayColourScheme.Blue);
|
||||||
|
|
||||||
|
[Test]
|
||||||
|
public void TestInitialState([Values] bool favourited)
|
||||||
|
{
|
||||||
|
APIBeatmapSet beatmapSetInfo = null;
|
||||||
|
FavouriteButton button = null;
|
||||||
|
|
||||||
|
AddStep("create beatmap set", () =>
|
||||||
|
{
|
||||||
|
beatmapSetInfo = CreateAPIBeatmapSet(Ruleset.Value);
|
||||||
|
beatmapSetInfo.HasFavourited = favourited;
|
||||||
|
});
|
||||||
|
AddStep("create button", () => Child = button = new FavouriteButton(beatmapSetInfo) { Scale = new Vector2(2) });
|
||||||
|
|
||||||
|
assertCorrectIcon(favourited);
|
||||||
|
AddAssert("correct tooltip text", () => button.TooltipText == (favourited ? BeatmapsetsStrings.ShowDetailsUnfavourite : BeatmapsetsStrings.ShowDetailsFavourite));
|
||||||
|
}
|
||||||
|
|
||||||
|
[Test]
|
||||||
|
public void TestRequestHandling()
|
||||||
|
{
|
||||||
|
APIBeatmapSet beatmapSetInfo = null;
|
||||||
|
FavouriteButton button = null;
|
||||||
|
BeatmapFavouriteAction? lastRequestAction = null;
|
||||||
|
|
||||||
|
AddStep("create beatmap set", () => beatmapSetInfo = CreateAPIBeatmapSet(Ruleset.Value));
|
||||||
|
AddStep("create button", () => Child = button = new FavouriteButton(beatmapSetInfo) { Scale = new Vector2(2) });
|
||||||
|
|
||||||
|
assertCorrectIcon(false);
|
||||||
|
|
||||||
|
AddStep("register request handling", () => dummyAPI.HandleRequest = request =>
|
||||||
|
{
|
||||||
|
if (!(request is PostBeatmapFavouriteRequest favouriteRequest))
|
||||||
|
return false;
|
||||||
|
|
||||||
|
lastRequestAction = favouriteRequest.Action;
|
||||||
|
request.TriggerSuccess();
|
||||||
|
return true;
|
||||||
|
});
|
||||||
|
|
||||||
|
AddStep("click icon", () =>
|
||||||
|
{
|
||||||
|
InputManager.MoveMouseTo(button);
|
||||||
|
InputManager.Click(MouseButton.Left);
|
||||||
|
});
|
||||||
|
AddUntilStep("favourite request sent", () => lastRequestAction == BeatmapFavouriteAction.Favourite);
|
||||||
|
assertCorrectIcon(true);
|
||||||
|
|
||||||
|
AddStep("click icon", () =>
|
||||||
|
{
|
||||||
|
InputManager.MoveMouseTo(button);
|
||||||
|
InputManager.Click(MouseButton.Left);
|
||||||
|
});
|
||||||
|
AddUntilStep("unfavourite request sent", () => lastRequestAction == BeatmapFavouriteAction.UnFavourite);
|
||||||
|
assertCorrectIcon(false);
|
||||||
|
}
|
||||||
|
|
||||||
|
private void assertCorrectIcon(bool favourited) => AddAssert("icon correct",
|
||||||
|
() => this.ChildrenOfType<SpriteIcon>().Single().Icon.Equals(favourited ? FontAwesome.Solid.Heart : FontAwesome.Regular.Heart));
|
||||||
|
}
|
||||||
|
}
|
@ -8,20 +8,21 @@ namespace osu.Game.Online.API.Requests
|
|||||||
{
|
{
|
||||||
public class PostBeatmapFavouriteRequest : APIRequest
|
public class PostBeatmapFavouriteRequest : APIRequest
|
||||||
{
|
{
|
||||||
|
public readonly BeatmapFavouriteAction Action;
|
||||||
|
|
||||||
private readonly int id;
|
private readonly int id;
|
||||||
private readonly BeatmapFavouriteAction action;
|
|
||||||
|
|
||||||
public PostBeatmapFavouriteRequest(int id, BeatmapFavouriteAction action)
|
public PostBeatmapFavouriteRequest(int id, BeatmapFavouriteAction action)
|
||||||
{
|
{
|
||||||
this.id = id;
|
this.id = id;
|
||||||
this.action = action;
|
Action = action;
|
||||||
}
|
}
|
||||||
|
|
||||||
protected override WebRequest CreateWebRequest()
|
protected override WebRequest CreateWebRequest()
|
||||||
{
|
{
|
||||||
var req = base.CreateWebRequest();
|
var req = base.CreateWebRequest();
|
||||||
req.Method = HttpMethod.Post;
|
req.Method = HttpMethod.Post;
|
||||||
req.AddParameter(@"action", action.ToString().ToLowerInvariant());
|
req.AddParameter(@"action", Action.ToString().ToLowerInvariant());
|
||||||
return req;
|
return req;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user