mirror of
https://github.com/osukey/osukey.git
synced 2025-08-04 15:16:38 +09:00
Merge branch 'master' into dashboard-overlay-new
This commit is contained in:
98
osu.Game.Tests/Visual/Gameplay/TestSceneKeyBindings.cs
Normal file
98
osu.Game.Tests/Visual/Gameplay/TestSceneKeyBindings.cs
Normal file
@ -0,0 +1,98 @@
|
||||
// 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 System.Collections.Generic;
|
||||
using NUnit.Framework;
|
||||
using osu.Framework.Graphics.Containers;
|
||||
using osu.Framework.Input.Bindings;
|
||||
using osu.Framework.Testing;
|
||||
using osu.Game.Beatmaps;
|
||||
using osu.Game.Input.Bindings;
|
||||
using osu.Game.Rulesets;
|
||||
using osu.Game.Rulesets.Difficulty;
|
||||
using osu.Game.Rulesets.Mods;
|
||||
using osu.Game.Rulesets.UI;
|
||||
using osuTK.Input;
|
||||
|
||||
namespace osu.Game.Tests.Visual.Gameplay
|
||||
{
|
||||
[HeadlessTest]
|
||||
public class TestSceneKeyBindings : OsuManualInputManagerTestScene
|
||||
{
|
||||
private readonly ActionReceiver receiver;
|
||||
|
||||
public TestSceneKeyBindings()
|
||||
{
|
||||
Add(new TestKeyBindingContainer
|
||||
{
|
||||
Child = receiver = new ActionReceiver()
|
||||
});
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void TestDefaultsWhenNotDatabased()
|
||||
{
|
||||
AddStep("fire key", () =>
|
||||
{
|
||||
InputManager.PressKey(Key.A);
|
||||
InputManager.ReleaseKey(Key.A);
|
||||
});
|
||||
|
||||
AddAssert("received key", () => receiver.ReceivedAction);
|
||||
}
|
||||
|
||||
private class TestRuleset : Ruleset
|
||||
{
|
||||
public override IEnumerable<Mod> GetModsFor(ModType type) =>
|
||||
throw new System.NotImplementedException();
|
||||
|
||||
public override DrawableRuleset CreateDrawableRulesetWith(IBeatmap beatmap, IReadOnlyList<Mod> mods = null) =>
|
||||
throw new System.NotImplementedException();
|
||||
|
||||
public override IBeatmapConverter CreateBeatmapConverter(IBeatmap beatmap) =>
|
||||
throw new System.NotImplementedException();
|
||||
|
||||
public override DifficultyCalculator CreateDifficultyCalculator(WorkingBeatmap beatmap) =>
|
||||
throw new System.NotImplementedException();
|
||||
|
||||
public override IEnumerable<KeyBinding> GetDefaultKeyBindings(int variant = 0)
|
||||
{
|
||||
return new[]
|
||||
{
|
||||
new KeyBinding(InputKey.A, TestAction.Down),
|
||||
};
|
||||
}
|
||||
|
||||
public override string Description => "test";
|
||||
public override string ShortName => "test";
|
||||
}
|
||||
|
||||
private enum TestAction
|
||||
{
|
||||
Down,
|
||||
}
|
||||
|
||||
private class TestKeyBindingContainer : DatabasedKeyBindingContainer<TestAction>
|
||||
{
|
||||
public TestKeyBindingContainer()
|
||||
: base(new TestRuleset().RulesetInfo, 0)
|
||||
{
|
||||
}
|
||||
}
|
||||
|
||||
private class ActionReceiver : CompositeDrawable, IKeyBindingHandler<TestAction>
|
||||
{
|
||||
public bool ReceivedAction;
|
||||
|
||||
public bool OnPressed(TestAction action)
|
||||
{
|
||||
ReceivedAction = action == TestAction.Down;
|
||||
return true;
|
||||
}
|
||||
|
||||
public void OnReleased(TestAction action)
|
||||
{
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
85
osu.Game.Tests/Visual/Online/TestSceneNowPlayingCommand.cs
Normal file
85
osu.Game.Tests/Visual/Online/TestSceneNowPlayingCommand.cs
Normal file
@ -0,0 +1,85 @@
|
||||
// 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]
|
||||
public class TestSceneNowPlayingCommand : OsuTestScene
|
||||
{
|
||||
[Cached(typeof(IChannelPostTarget))]
|
||||
private PostTarget postTarget { get; set; }
|
||||
|
||||
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; }
|
||||
}
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user