osu/osu.Game.Tests/Visual/Gameplay/TestSceneMedalOverlay.cs

Ignoring revisions in .git-blame-ignore-revs. Click here to bypass and see the normal blame view.

110 lines
4.2 KiB
C#
Raw Normal View History

// 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-04-13 09:19:50 +00:00
2024-02-20 17:42:01 +00:00
using System.Linq;
using Moq;
2024-02-20 11:53:46 +00:00
using Newtonsoft.Json.Linq;
2018-03-02 06:34:31 +00:00
using NUnit.Framework;
using osu.Framework.Bindables;
using osu.Framework.Graphics;
2024-02-20 11:53:46 +00:00
using osu.Framework.Graphics.Containers;
using osu.Framework.Testing;
using osu.Game.Online.API;
using osu.Game.Online.Notifications.WebSocket;
using osu.Game.Online.Notifications.WebSocket.Events;
2017-09-18 13:32:49 +00:00
using osu.Game.Overlays;
2024-02-20 11:53:46 +00:00
using osuTK.Input;
2018-04-13 09:19:50 +00:00
2019-03-24 16:02:36 +00:00
namespace osu.Game.Tests.Visual.Gameplay
2017-09-18 13:32:49 +00:00
{
2018-03-02 06:34:31 +00:00
[TestFixture]
2024-02-20 11:53:46 +00:00
public partial class TestSceneMedalOverlay : OsuManualInputManagerTestScene
2017-09-18 13:32:49 +00:00
{
private readonly Bindable<OverlayActivation> overlayActivationMode = new Bindable<OverlayActivation>(OverlayActivation.All);
2024-02-20 11:53:46 +00:00
private DummyAPIAccess dummyAPI => (DummyAPIAccess)API;
2024-02-20 11:53:46 +00:00
private MedalOverlay overlay = null!;
[SetUpSteps]
public void SetUpSteps()
{
var overlayManagerMock = new Mock<IOverlayManager>();
overlayManagerMock.Setup(mock => mock.OverlayActivationMode).Returns(overlayActivationMode);
AddStep("create overlay", () => Child = new DependencyProvidingContainer
{
Child = overlay = new MedalOverlay(),
RelativeSizeAxes = Axes.Both,
CachedDependencies =
[
(typeof(IOverlayManager), overlayManagerMock.Object)
]
});
2024-02-20 11:53:46 +00:00
}
[Test]
public void TestBasicAward()
2017-09-18 13:32:49 +00:00
{
awardMedal(new UserAchievementUnlock
2017-09-18 13:32:49 +00:00
{
Title = "Time And A Half",
Description = "Having a right ol' time. One and a half of them, almost.",
Slug = @"all-intro-doubletime"
});
2024-02-20 11:53:46 +00:00
AddUntilStep("overlay shown", () => overlay.State.Value, () => Is.EqualTo(Visibility.Visible));
2024-02-20 17:42:01 +00:00
AddUntilStep("wait for load", () => this.ChildrenOfType<MedalAnimation>().Any());
2024-02-20 11:53:46 +00:00
AddRepeatStep("dismiss", () => InputManager.Key(Key.Escape), 2);
AddUntilStep("overlay hidden", () => overlay.State.Value, () => Is.EqualTo(Visibility.Hidden));
2017-09-18 13:32:49 +00:00
}
[Test]
public void TestMultipleMedalsInQuickSuccession()
{
awardMedal(new UserAchievementUnlock
{
Title = "Time And A Half",
Description = "Having a right ol' time. One and a half of them, almost.",
Slug = @"all-intro-doubletime"
});
awardMedal(new UserAchievementUnlock
{
Title = "S-Ranker",
Description = "Accuracy is really underrated.",
Slug = @"all-secret-rank-s"
});
awardMedal(new UserAchievementUnlock
{
Title = "500 Combo",
Description = "500 big ones! You're moving up in the world!",
Slug = @"osu-combo-500"
});
}
[Test]
public void TestDelayMedalDisplayUntilActivationModeAllowsIt()
{
AddStep("disable overlay activation", () => overlayActivationMode.Value = OverlayActivation.Disabled);
awardMedal(new UserAchievementUnlock
{
Title = "Time And A Half",
Description = "Having a right ol' time. One and a half of them, almost.",
Slug = @"all-intro-doubletime"
});
AddUntilStep("overlay hidden", () => overlay.State.Value, () => Is.EqualTo(Visibility.Hidden));
AddStep("re-enable overlay activation", () => overlayActivationMode.Value = OverlayActivation.All);
AddUntilStep("overlay shown", () => overlay.State.Value, () => Is.EqualTo(Visibility.Visible));
}
private void awardMedal(UserAchievementUnlock unlock) => AddStep("award medal", () => dummyAPI.NotificationsClient.Receive(new SocketMessage
{
Event = @"new",
Data = JObject.FromObject(new NewPrivateNotificationEvent
{
Name = @"user_achievement_unlock",
Details = JObject.FromObject(unlock)
})
}));
2017-09-18 13:32:49 +00:00
}
}