2021-10-23 16:05:30 +00:00
|
|
|
// 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.
|
|
|
|
|
2022-06-17 07:37:17 +00:00
|
|
|
#nullable disable
|
|
|
|
|
2021-10-23 16:41:31 +00:00
|
|
|
using System.Linq;
|
2021-10-23 16:05:30 +00:00
|
|
|
using NUnit.Framework;
|
|
|
|
using osu.Framework.Allocation;
|
|
|
|
using osu.Framework.Graphics;
|
2021-10-23 16:41:31 +00:00
|
|
|
using osu.Framework.Graphics.Sprites;
|
|
|
|
using osu.Framework.Testing;
|
2021-10-23 16:05:30 +00:00
|
|
|
using osu.Game.Beatmaps.Drawables.Cards;
|
2021-10-23 16:41:31 +00:00
|
|
|
using osu.Game.Beatmaps.Drawables.Cards.Buttons;
|
2021-10-23 16:05:30 +00:00
|
|
|
using osu.Game.Overlays;
|
|
|
|
using osuTK;
|
2021-10-23 16:41:31 +00:00
|
|
|
using osuTK.Input;
|
2021-10-23 16:05:30 +00:00
|
|
|
|
|
|
|
namespace osu.Game.Tests.Visual.Beatmaps
|
|
|
|
{
|
2021-10-23 16:41:31 +00:00
|
|
|
public partial class TestSceneBeatmapCardThumbnail : OsuManualInputManagerTestScene
|
2021-10-23 16:05:30 +00:00
|
|
|
{
|
2021-10-23 16:41:31 +00:00
|
|
|
private PlayButton playButton => this.ChildrenOfType<PlayButton>().Single();
|
|
|
|
|
2021-10-23 16:05:30 +00:00
|
|
|
[Cached]
|
|
|
|
private OverlayColourProvider colourProvider = new OverlayColourProvider(OverlayColourScheme.Blue);
|
|
|
|
|
|
|
|
[Test]
|
|
|
|
public void TestThumbnailPreview()
|
|
|
|
{
|
|
|
|
BeatmapCardThumbnail thumbnail = null;
|
|
|
|
|
2021-11-24 19:34:33 +00:00
|
|
|
AddStep("create thumbnail", () =>
|
2021-10-23 16:05:30 +00:00
|
|
|
{
|
2021-11-24 19:34:33 +00:00
|
|
|
var beatmapSet = CreateAPIBeatmapSet(Ruleset.Value);
|
|
|
|
beatmapSet.OnlineID = 241526; // ID hardcoded to ensure that the preview track exists online.
|
|
|
|
|
|
|
|
Child = thumbnail = new BeatmapCardThumbnail(beatmapSet)
|
|
|
|
{
|
|
|
|
Anchor = Anchor.Centre,
|
|
|
|
Origin = Anchor.Centre,
|
|
|
|
Size = new Vector2(200)
|
|
|
|
};
|
2021-10-23 16:05:30 +00:00
|
|
|
});
|
2021-10-23 16:41:31 +00:00
|
|
|
AddStep("enable dim", () => thumbnail.Dimmed.Value = true);
|
2022-09-09 09:10:10 +00:00
|
|
|
AddUntilStep("button visible", () => playButton.Alpha == 1);
|
2021-10-23 16:41:31 +00:00
|
|
|
|
|
|
|
AddStep("click button", () =>
|
|
|
|
{
|
|
|
|
InputManager.MoveMouseTo(playButton);
|
|
|
|
InputManager.Click(MouseButton.Left);
|
|
|
|
});
|
2021-10-23 17:27:07 +00:00
|
|
|
AddUntilStep("wait for start", () => playButton.Playing.Value && playButton.Enabled.Value);
|
2021-10-23 16:41:31 +00:00
|
|
|
iconIs(FontAwesome.Solid.Stop);
|
|
|
|
|
|
|
|
AddStep("click again", () =>
|
|
|
|
{
|
|
|
|
InputManager.MoveMouseTo(playButton);
|
|
|
|
InputManager.Click(MouseButton.Left);
|
|
|
|
});
|
2021-10-23 17:27:07 +00:00
|
|
|
AddUntilStep("wait for stop", () => !playButton.Playing.Value && playButton.Enabled.Value);
|
2021-10-23 16:41:31 +00:00
|
|
|
iconIs(FontAwesome.Solid.Play);
|
|
|
|
|
|
|
|
AddStep("click again", () =>
|
|
|
|
{
|
|
|
|
InputManager.MoveMouseTo(playButton);
|
|
|
|
InputManager.Click(MouseButton.Left);
|
|
|
|
});
|
2021-10-23 17:27:07 +00:00
|
|
|
AddUntilStep("wait for start", () => playButton.Playing.Value && playButton.Enabled.Value);
|
2021-10-23 16:41:31 +00:00
|
|
|
iconIs(FontAwesome.Solid.Stop);
|
|
|
|
|
|
|
|
AddStep("disable dim", () => thumbnail.Dimmed.Value = false);
|
|
|
|
AddWaitStep("wait some", 3);
|
2022-09-09 09:10:10 +00:00
|
|
|
AddAssert("button still visible", () => playButton.Alpha == 1);
|
2021-10-23 16:41:31 +00:00
|
|
|
|
2021-11-25 13:05:39 +00:00
|
|
|
// The track plays in real-time, so we need to check for progress in increments to avoid timeout.
|
|
|
|
AddUntilStep("progress > 0.25", () => thumbnail.ChildrenOfType<PlayButton>().Single().Progress.Value > 0.25);
|
|
|
|
AddUntilStep("progress > 0.5", () => thumbnail.ChildrenOfType<PlayButton>().Single().Progress.Value > 0.5);
|
|
|
|
AddUntilStep("progress > 0.75", () => thumbnail.ChildrenOfType<PlayButton>().Single().Progress.Value > 0.75);
|
|
|
|
|
2021-10-23 17:27:07 +00:00
|
|
|
AddUntilStep("wait for track to end", () => !playButton.Playing.Value);
|
2022-09-09 09:10:10 +00:00
|
|
|
AddUntilStep("button hidden", () => playButton.Alpha == 0);
|
2021-10-23 16:05:30 +00:00
|
|
|
}
|
2021-10-23 16:41:31 +00:00
|
|
|
|
2021-10-23 17:27:07 +00:00
|
|
|
private void iconIs(IconUsage usage) => AddUntilStep("icon is correct", () => playButton.ChildrenOfType<SpriteIcon>().Any(icon => icon.Icon.Equals(usage)));
|
2021-10-23 16:05:30 +00:00
|
|
|
}
|
|
|
|
}
|