mirror of
https://github.com/ppy/osu.git
synced 2024-11-11 13:37:25 +08:00
Add tests
This commit is contained in:
parent
c16b7c5c70
commit
a575566638
71
osu.Game.Tests/Visual/Ranking/TestSceneCollectionButton.cs
Normal file
71
osu.Game.Tests/Visual/Ranking/TestSceneCollectionButton.cs
Normal file
@ -0,0 +1,71 @@
|
||||
// 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.
|
||||
|
||||
#nullable disable
|
||||
|
||||
using System.Linq;
|
||||
using NUnit.Framework;
|
||||
using osu.Framework.Graphics;
|
||||
using osu.Framework.Graphics.Containers;
|
||||
using osu.Framework.Graphics.Cursor;
|
||||
using osu.Framework.Testing;
|
||||
using osu.Game.Beatmaps;
|
||||
using osu.Game.Screens.Ranking;
|
||||
using osuTK;
|
||||
using osuTK.Input;
|
||||
|
||||
namespace osu.Game.Tests.Visual.Ranking
|
||||
{
|
||||
public partial class TestSceneCollectionButton : OsuManualInputManagerTestScene
|
||||
{
|
||||
private CollectionButton collectionButton;
|
||||
private BeatmapInfo beatmapInfo = new BeatmapInfo { OnlineID = 88 };
|
||||
|
||||
[SetUpSteps]
|
||||
public void SetUpSteps()
|
||||
{
|
||||
AddStep("create button", () => Child = new PopoverContainer
|
||||
{
|
||||
Depth = -1,
|
||||
RelativeSizeAxes = Axes.Both,
|
||||
Anchor = Anchor.Centre,
|
||||
Origin = Anchor.Centre,
|
||||
Child = collectionButton = new CollectionButton(beatmapInfo)
|
||||
{
|
||||
RelativeSizeAxes = Axes.None,
|
||||
Size = new Vector2(50),
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void TestCollectionButton()
|
||||
{
|
||||
AddStep("click collection button", () =>
|
||||
{
|
||||
InputManager.MoveMouseTo(collectionButton);
|
||||
InputManager.Click(MouseButton.Left);
|
||||
});
|
||||
|
||||
AddAssert("collection popover is visible", () => this.ChildrenOfType<CollectionPopover>().Single().State.Value == Visibility.Visible);
|
||||
|
||||
AddStep("click outside popover", () =>
|
||||
{
|
||||
InputManager.MoveMouseTo(ScreenSpaceDrawQuad.TopLeft);
|
||||
InputManager.Click(MouseButton.Left);
|
||||
});
|
||||
|
||||
AddAssert("collection popover is hidden", () => this.ChildrenOfType<CollectionPopover>().Single().State.Value == Visibility.Hidden);
|
||||
|
||||
AddStep("click collection button", () =>
|
||||
{
|
||||
InputManager.MoveMouseTo(collectionButton);
|
||||
InputManager.Click(MouseButton.Left);
|
||||
});
|
||||
|
||||
AddStep("press escape", () => InputManager.Key(Key.Escape));
|
||||
|
||||
AddAssert("collection popover is hidden", () => this.ChildrenOfType<CollectionPopover>().Single().State.Value == Visibility.Hidden);
|
||||
}
|
||||
}
|
||||
}
|
90
osu.Game.Tests/Visual/Ranking/TestSceneFavouriteButton.cs
Normal file
90
osu.Game.Tests/Visual/Ranking/TestSceneFavouriteButton.cs
Normal file
@ -0,0 +1,90 @@
|
||||
// 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.
|
||||
|
||||
#nullable disable
|
||||
|
||||
using NUnit.Framework;
|
||||
using osu.Framework.Graphics;
|
||||
using osu.Framework.Testing;
|
||||
using osu.Game.Beatmaps;
|
||||
using osu.Game.Online.API;
|
||||
using osu.Game.Online.API.Requests;
|
||||
using osu.Game.Online.API.Requests.Responses;
|
||||
using osu.Game.Screens.Ranking;
|
||||
using osuTK;
|
||||
|
||||
namespace osu.Game.Tests.Visual.Ranking
|
||||
{
|
||||
public partial class TestSceneFavouriteButton : OsuTestScene
|
||||
{
|
||||
private FavouriteButton favourite;
|
||||
|
||||
private readonly BeatmapSetInfo beatmapSetInfo = new BeatmapSetInfo { OnlineID = 88 };
|
||||
private readonly BeatmapSetInfo invalidBeatmapSetInfo = new BeatmapSetInfo();
|
||||
|
||||
private DummyAPIAccess dummyAPI => (DummyAPIAccess)API;
|
||||
|
||||
|
||||
[SetUpSteps]
|
||||
public void SetUpSteps()
|
||||
{
|
||||
AddStep("create button", () => Child = favourite = new FavouriteButton(beatmapSetInfo)
|
||||
{
|
||||
RelativeSizeAxes = Axes.None,
|
||||
Size = new Vector2(50),
|
||||
Anchor = Anchor.Centre,
|
||||
Origin = Anchor.Centre,
|
||||
});
|
||||
|
||||
AddStep("register request handling", () => dummyAPI.HandleRequest = request =>
|
||||
{
|
||||
if (!(request is GetBeatmapSetRequest beatmapSetRequest)) return false;
|
||||
|
||||
beatmapSetRequest.TriggerSuccess(new APIBeatmapSet
|
||||
{
|
||||
OnlineID = beatmapSetRequest.ID,
|
||||
HasFavourited = false,
|
||||
FavouriteCount = 0,
|
||||
});
|
||||
|
||||
return true;
|
||||
});
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void TestLoggedOutIn()
|
||||
{
|
||||
AddStep("log out", () => API.Logout());
|
||||
checkEnabled(false);
|
||||
AddStep("log in", () =>
|
||||
{
|
||||
API.Login("test", "test");
|
||||
((DummyAPIAccess)API).AuthenticateSecondFactor("abcdefgh");
|
||||
});
|
||||
checkEnabled(true);
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void TestInvalidBeatmap()
|
||||
{
|
||||
AddStep("make beatmap invalid", () => Child = favourite = new FavouriteButton(invalidBeatmapSetInfo)
|
||||
{
|
||||
RelativeSizeAxes = Axes.None,
|
||||
Size = new Vector2(50),
|
||||
Anchor = Anchor.Centre,
|
||||
Origin = Anchor.Centre,
|
||||
});
|
||||
AddStep("log in", () =>
|
||||
{
|
||||
API.Login("test", "test");
|
||||
((DummyAPIAccess)API).AuthenticateSecondFactor("abcdefgh");
|
||||
});
|
||||
checkEnabled(false);
|
||||
}
|
||||
|
||||
private void checkEnabled(bool expected)
|
||||
{
|
||||
AddAssert("is " + (expected ? "enabled" : "disabled"), () => favourite.Enabled.Value == expected);
|
||||
}
|
||||
}
|
||||
}
|
@ -26,12 +26,12 @@ namespace osu.Game.Screens.Ranking
|
||||
private readonly Box background;
|
||||
private readonly SpriteIcon icon;
|
||||
|
||||
private readonly BeatmapSetInfo beatmapSetInfo;
|
||||
public readonly BeatmapSetInfo BeatmapSetInfo;
|
||||
private APIBeatmapSet beatmapSet;
|
||||
private Bindable<BeatmapSetFavouriteState> current;
|
||||
private readonly Bindable<BeatmapSetFavouriteState> current;
|
||||
|
||||
private PostBeatmapFavouriteRequest favouriteRequest;
|
||||
private LoadingLayer loading;
|
||||
private readonly LoadingLayer loading;
|
||||
|
||||
private readonly IBindable<APIUser> localUser = new Bindable<APIUser>();
|
||||
|
||||
@ -43,7 +43,8 @@ namespace osu.Game.Screens.Ranking
|
||||
|
||||
public FavouriteButton(BeatmapSetInfo beatmapSetInfo)
|
||||
{
|
||||
this.beatmapSetInfo = beatmapSetInfo;
|
||||
BeatmapSetInfo = beatmapSetInfo;
|
||||
current = new BindableWithCurrent<BeatmapSetFavouriteState>(new BeatmapSetFavouriteState(false, 0));
|
||||
|
||||
Size = new Vector2(50, 30);
|
||||
|
||||
@ -70,7 +71,6 @@ namespace osu.Game.Screens.Ranking
|
||||
[BackgroundDependencyLoader]
|
||||
private void load()
|
||||
{
|
||||
current = new BindableWithCurrent<BeatmapSetFavouriteState>(new BeatmapSetFavouriteState(false, 0));
|
||||
current.BindValueChanged(_ => updateState(), true);
|
||||
|
||||
localUser.BindTo(api.LocalUser);
|
||||
@ -80,7 +80,7 @@ namespace osu.Game.Screens.Ranking
|
||||
private void getBeatmapSet()
|
||||
{
|
||||
GetBeatmapSetRequest beatmapSetRequest;
|
||||
beatmapSetRequest = new GetBeatmapSetRequest(beatmapSetInfo.OnlineID);
|
||||
beatmapSetRequest = new GetBeatmapSetRequest(BeatmapSetInfo.OnlineID);
|
||||
|
||||
loading.Show();
|
||||
beatmapSetRequest.Success += beatmapSet =>
|
||||
@ -133,7 +133,7 @@ namespace osu.Game.Screens.Ranking
|
||||
|
||||
private void updateUser()
|
||||
{
|
||||
if (!(localUser.Value is GuestUser) && beatmapSetInfo.OnlineID > 0)
|
||||
if (!(localUser.Value is GuestUser) && BeatmapSetInfo.OnlineID > 0)
|
||||
getBeatmapSet();
|
||||
else
|
||||
{
|
||||
|
Loading…
Reference in New Issue
Block a user