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

86 lines
2.8 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.
using NUnit.Framework;
using osu.Framework.Allocation;
using osu.Framework.Graphics;
using osu.Framework.Testing;
using osu.Game.Beatmaps;
using osu.Game.Online.Chat;
using osu.Game.Rulesets;
using osu.Game.Users;
namespace osu.Game.Tests.Visual.Online
{
[HeadlessTest]
2020-04-19 15:57:47 +08:00
public class TestSceneNowPlayingCommand : OsuTestScene
{
[Cached(typeof(IChannelPostTarget))]
private PostTarget postTarget { get; set; }
2020-04-19 15:57:47 +08:00
public TestSceneNowPlayingCommand()
{
Add(postTarget = new PostTarget());
}
[Test]
public void TestGenericActivity()
{
AddStep("Set activity", () => API.Activity.Value = new UserActivity.InLobby());
AddStep("Run command", () => Add(new NowPlayingCommand()));
AddAssert("Check correct response", () => postTarget.LastMessage.Contains("is listening"));
}
[Test]
public void TestEditActivity()
{
AddStep("Set activity", () => API.Activity.Value = new UserActivity.Editing(new BeatmapInfo()));
AddStep("Run command", () => Add(new NowPlayingCommand()));
AddAssert("Check correct response", () => postTarget.LastMessage.Contains("is editing"));
}
[Test]
public void TestPlayActivity()
{
AddStep("Set activity", () => API.Activity.Value = new UserActivity.SoloGame(new BeatmapInfo(), new RulesetInfo()));
AddStep("Run command", () => Add(new NowPlayingCommand()));
AddAssert("Check correct response", () => postTarget.LastMessage.Contains("is playing"));
}
[TestCase(true)]
[TestCase(false)]
public void TestLinkPresence(bool hasOnlineId)
{
AddStep("Set activity", () => API.Activity.Value = new UserActivity.InLobby());
AddStep("Set beatmap", () => Beatmap.Value = new DummyWorkingBeatmap(null, null)
{
BeatmapInfo = { OnlineBeatmapID = hasOnlineId ? 1234 : (int?)null }
});
AddStep("Run command", () => Add(new NowPlayingCommand()));
if (hasOnlineId)
AddAssert("Check link presence", () => postTarget.LastMessage.Contains("https://osu.ppy.sh/b/1234"));
else
AddAssert("Check link not present", () => !postTarget.LastMessage.Contains("https://"));
}
public class PostTarget : Component, IChannelPostTarget
{
public void PostMessage(string text, bool isAction = false, Channel target = null)
{
LastMessage = text;
}
public string LastMessage { get; private set; }
}
}
}