1
0
mirror of https://github.com/ppy/osu.git synced 2024-12-21 15:53:00 +08:00
osu-lazer/osu.Game.Tests/Visual/Online/TestSceneNowPlayingCommand.cs

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

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