2020-04-19 14:12:36 +08: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 15:37:17 +08:00
|
|
|
#nullable disable
|
|
|
|
|
2020-04-19 14:12:36 +08:00
|
|
|
using NUnit.Framework;
|
|
|
|
using osu.Framework.Allocation;
|
|
|
|
using osu.Framework.Graphics;
|
|
|
|
using osu.Framework.Testing;
|
|
|
|
using osu.Game.Beatmaps;
|
2020-12-18 14:16:36 +08:00
|
|
|
using osu.Game.Online.API;
|
2020-04-19 14:12:36 +08:00
|
|
|
using osu.Game.Online.Chat;
|
|
|
|
using osu.Game.Rulesets;
|
2022-09-08 02:20:48 +08:00
|
|
|
using osu.Game.Rulesets.Mods;
|
2020-04-19 14:12:36 +08:00
|
|
|
using osu.Game.Users;
|
|
|
|
|
|
|
|
namespace osu.Game.Tests.Visual.Online
|
|
|
|
{
|
|
|
|
[HeadlessTest]
|
2022-11-24 13:32:20 +08:00
|
|
|
public partial class TestSceneNowPlayingCommand : OsuTestScene
|
2020-04-19 14:12:36 +08:00
|
|
|
{
|
|
|
|
[Cached(typeof(IChannelPostTarget))]
|
|
|
|
private PostTarget postTarget { get; set; }
|
|
|
|
|
2020-12-18 14:16:36 +08:00
|
|
|
private DummyAPIAccess api => (DummyAPIAccess)API;
|
|
|
|
|
2020-04-19 15:57:47 +08:00
|
|
|
public TestSceneNowPlayingCommand()
|
2020-04-19 14:12:36 +08:00
|
|
|
{
|
|
|
|
Add(postTarget = new PostTarget());
|
|
|
|
}
|
|
|
|
|
|
|
|
[Test]
|
|
|
|
public void TestGenericActivity()
|
|
|
|
{
|
2020-12-18 14:16:36 +08:00
|
|
|
AddStep("Set activity", () => api.Activity.Value = new UserActivity.InLobby(null));
|
2020-04-19 14:12:36 +08:00
|
|
|
|
2022-11-30 13:30:20 +08:00
|
|
|
AddStep("Run command", () => Add(new NowPlayingCommand(new Channel())));
|
2020-04-19 14:12:36 +08:00
|
|
|
|
|
|
|
AddAssert("Check correct response", () => postTarget.LastMessage.Contains("is listening"));
|
|
|
|
}
|
|
|
|
|
|
|
|
[Test]
|
|
|
|
public void TestEditActivity()
|
|
|
|
{
|
2023-02-13 04:32:17 +08:00
|
|
|
AddStep("Set activity", () => api.Activity.Value = new UserActivity.EditingBeatmap(new BeatmapInfo()));
|
2020-04-19 14:12:36 +08:00
|
|
|
|
2022-11-30 13:30:20 +08:00
|
|
|
AddStep("Run command", () => Add(new NowPlayingCommand(new Channel())));
|
2020-04-19 14:12:36 +08:00
|
|
|
|
|
|
|
AddAssert("Check correct response", () => postTarget.LastMessage.Contains("is editing"));
|
|
|
|
}
|
|
|
|
|
|
|
|
[Test]
|
|
|
|
public void TestPlayActivity()
|
|
|
|
{
|
2021-08-16 06:32:33 +08:00
|
|
|
AddStep("Set activity", () => api.Activity.Value = new UserActivity.InSoloGame(new BeatmapInfo(), new RulesetInfo()));
|
2020-04-19 14:12:36 +08:00
|
|
|
|
2022-11-30 13:30:20 +08:00
|
|
|
AddStep("Run command", () => Add(new NowPlayingCommand(new Channel())));
|
2020-04-19 14:12:36 +08:00
|
|
|
|
|
|
|
AddAssert("Check correct response", () => postTarget.LastMessage.Contains("is playing"));
|
|
|
|
}
|
|
|
|
|
|
|
|
[TestCase(true)]
|
|
|
|
[TestCase(false)]
|
|
|
|
public void TestLinkPresence(bool hasOnlineId)
|
|
|
|
{
|
2020-12-18 14:16:36 +08:00
|
|
|
AddStep("Set activity", () => api.Activity.Value = new UserActivity.InLobby(null));
|
2020-04-19 14:12:36 +08:00
|
|
|
|
2020-08-07 21:05:58 +08:00
|
|
|
AddStep("Set beatmap", () => Beatmap.Value = new DummyWorkingBeatmap(Audio, null)
|
2020-04-19 14:12:36 +08:00
|
|
|
{
|
2021-11-22 13:26:24 +08:00
|
|
|
BeatmapInfo = { OnlineID = hasOnlineId ? 1234 : -1 }
|
2020-04-19 14:12:36 +08:00
|
|
|
});
|
|
|
|
|
2022-11-30 13:30:20 +08:00
|
|
|
AddStep("Run command", () => Add(new NowPlayingCommand(new Channel())));
|
2020-04-19 14:12:36 +08:00
|
|
|
|
|
|
|
if (hasOnlineId)
|
2020-12-24 20:28:21 +08:00
|
|
|
AddAssert("Check link presence", () => postTarget.LastMessage.Contains("/b/1234"));
|
2020-04-19 14:12:36 +08:00
|
|
|
else
|
|
|
|
AddAssert("Check link not present", () => !postTarget.LastMessage.Contains("https://"));
|
|
|
|
}
|
|
|
|
|
2022-09-08 02:20:48 +08:00
|
|
|
[Test]
|
|
|
|
public void TestModPresence()
|
|
|
|
{
|
2022-11-27 09:44:06 +08:00
|
|
|
AddStep("Set activity", () => api.Activity.Value = new UserActivity.InSoloGame(new BeatmapInfo(), new RulesetInfo()));
|
|
|
|
|
2022-09-08 02:20:48 +08:00
|
|
|
AddStep("Add Hidden mod", () => SelectedMods.Value = new[] { Ruleset.Value.CreateInstance().CreateMod<ModHidden>() });
|
|
|
|
|
2022-11-30 13:30:20 +08:00
|
|
|
AddStep("Run command", () => Add(new NowPlayingCommand(new Channel())));
|
2022-09-08 02:20:48 +08:00
|
|
|
|
2022-11-27 09:44:06 +08:00
|
|
|
AddAssert("Check mod is present", () => postTarget.LastMessage.Contains("+HD"));
|
2022-09-08 02:20:48 +08:00
|
|
|
}
|
|
|
|
|
2022-11-24 13:32:20 +08:00
|
|
|
public partial class PostTarget : Component, IChannelPostTarget
|
2020-04-19 14:12:36 +08:00
|
|
|
{
|
|
|
|
public void PostMessage(string text, bool isAction = false, Channel target = null)
|
|
|
|
{
|
|
|
|
LastMessage = text;
|
|
|
|
}
|
|
|
|
|
|
|
|
public string LastMessage { get; private set; }
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|