2021-08-17 14:11:45 +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.
|
|
|
|
|
|
|
|
using System.Linq;
|
|
|
|
using Moq;
|
|
|
|
using NUnit.Framework;
|
|
|
|
using osu.Framework.Allocation;
|
|
|
|
using osu.Framework.Bindables;
|
|
|
|
using osu.Framework.Graphics;
|
|
|
|
using osu.Framework.Graphics.UserInterface;
|
|
|
|
using osu.Framework.Testing;
|
|
|
|
using osu.Game.Screens.OnlinePlay.Multiplayer;
|
|
|
|
using osu.Game.Screens.Play;
|
|
|
|
using osuTK.Input;
|
|
|
|
|
|
|
|
namespace osu.Game.Tests.Visual.Multiplayer
|
|
|
|
{
|
|
|
|
public class TestSceneGameplayChatDisplay : MultiplayerTestScene
|
|
|
|
{
|
|
|
|
private GameplayChatDisplay chatDisplay;
|
|
|
|
|
|
|
|
[Cached(typeof(ILocalUserPlayInfo))]
|
|
|
|
private ILocalUserPlayInfo localUserInfo;
|
|
|
|
|
|
|
|
private readonly Bindable<bool> localUserPlaying = new Bindable<bool>();
|
|
|
|
|
|
|
|
private TextBox textBox => chatDisplay.ChildrenOfType<TextBox>().First();
|
|
|
|
|
|
|
|
public TestSceneGameplayChatDisplay()
|
|
|
|
{
|
|
|
|
var mockLocalUserInfo = new Mock<ILocalUserPlayInfo>();
|
|
|
|
mockLocalUserInfo.SetupGet(i => i.IsPlaying).Returns(localUserPlaying);
|
|
|
|
|
|
|
|
localUserInfo = mockLocalUserInfo.Object;
|
|
|
|
}
|
|
|
|
|
|
|
|
[SetUpSteps]
|
|
|
|
public override void SetUpSteps()
|
|
|
|
{
|
|
|
|
base.SetUpSteps();
|
|
|
|
|
2021-08-24 12:22:06 +08:00
|
|
|
AddStep("load chat display", () => Child = chatDisplay = new GameplayChatDisplay(SelectedRoom.Value)
|
2021-08-17 14:11:45 +08:00
|
|
|
{
|
|
|
|
Anchor = Anchor.Centre,
|
|
|
|
Origin = Anchor.Centre,
|
|
|
|
Width = 0.5f,
|
|
|
|
});
|
|
|
|
|
|
|
|
AddStep("expand", () => chatDisplay.Expanded.Value = true);
|
|
|
|
}
|
|
|
|
|
2021-08-18 16:30:50 +08:00
|
|
|
[Test]
|
|
|
|
public void TestCantClickWhenPlaying()
|
|
|
|
{
|
|
|
|
setLocalUserPlaying(true);
|
|
|
|
|
|
|
|
AddStep("attempt focus chat", () =>
|
|
|
|
{
|
|
|
|
InputManager.MoveMouseTo(textBox);
|
|
|
|
InputManager.Click(MouseButton.Left);
|
|
|
|
});
|
|
|
|
|
|
|
|
assertChatFocused(false);
|
|
|
|
}
|
|
|
|
|
2021-08-17 14:11:45 +08:00
|
|
|
[Test]
|
|
|
|
public void TestFocusDroppedWhenPlaying()
|
|
|
|
{
|
|
|
|
assertChatFocused(false);
|
|
|
|
|
|
|
|
AddStep("focus chat", () =>
|
|
|
|
{
|
|
|
|
InputManager.MoveMouseTo(textBox);
|
|
|
|
InputManager.Click(MouseButton.Left);
|
|
|
|
});
|
|
|
|
|
|
|
|
setLocalUserPlaying(true);
|
|
|
|
assertChatFocused(false);
|
|
|
|
|
|
|
|
// should still stay non-focused even after entering a new break section.
|
|
|
|
setLocalUserPlaying(false);
|
|
|
|
assertChatFocused(false);
|
|
|
|
}
|
|
|
|
|
|
|
|
[Test]
|
2021-08-18 17:25:21 +08:00
|
|
|
public void TestFocusOnTabKeyWhenExpanded()
|
2021-08-17 14:11:45 +08:00
|
|
|
{
|
2021-08-19 13:14:47 +08:00
|
|
|
setLocalUserPlaying(true);
|
|
|
|
|
2021-08-17 14:11:45 +08:00
|
|
|
assertChatFocused(false);
|
|
|
|
AddStep("press tab", () => InputManager.Key(Key.Tab));
|
|
|
|
assertChatFocused(true);
|
|
|
|
}
|
|
|
|
|
2021-10-26 12:55:02 +08:00
|
|
|
[Test]
|
|
|
|
public void TestFocusLostOnBackKey()
|
|
|
|
{
|
|
|
|
setLocalUserPlaying(true);
|
|
|
|
|
|
|
|
assertChatFocused(false);
|
|
|
|
AddStep("press tab", () => InputManager.Key(Key.Tab));
|
|
|
|
assertChatFocused(true);
|
|
|
|
AddStep("press escape", () => InputManager.Key(Key.Escape));
|
|
|
|
assertChatFocused(false);
|
|
|
|
}
|
|
|
|
|
2021-08-18 17:25:21 +08:00
|
|
|
[Test]
|
|
|
|
public void TestFocusOnTabKeyWhenNotExpanded()
|
|
|
|
{
|
|
|
|
AddStep("set not expanded", () => chatDisplay.Expanded.Value = false);
|
|
|
|
AddUntilStep("is not visible", () => !chatDisplay.IsPresent);
|
|
|
|
|
|
|
|
AddStep("press tab", () => InputManager.Key(Key.Tab));
|
|
|
|
assertChatFocused(true);
|
|
|
|
AddUntilStep("is visible", () => chatDisplay.IsPresent);
|
|
|
|
|
|
|
|
AddStep("press enter", () => InputManager.Key(Key.Enter));
|
|
|
|
assertChatFocused(false);
|
|
|
|
AddUntilStep("is not visible", () => !chatDisplay.IsPresent);
|
|
|
|
}
|
|
|
|
|
2021-08-19 13:19:59 +08:00
|
|
|
[Test]
|
|
|
|
public void TestFocusToggleViaAction()
|
|
|
|
{
|
|
|
|
AddStep("set not expanded", () => chatDisplay.Expanded.Value = false);
|
|
|
|
AddUntilStep("is not visible", () => !chatDisplay.IsPresent);
|
|
|
|
|
|
|
|
AddStep("press tab", () => InputManager.Key(Key.Tab));
|
|
|
|
assertChatFocused(true);
|
|
|
|
AddUntilStep("is visible", () => chatDisplay.IsPresent);
|
|
|
|
|
|
|
|
AddStep("press tab", () => InputManager.Key(Key.Tab));
|
|
|
|
assertChatFocused(false);
|
|
|
|
AddUntilStep("is not visible", () => !chatDisplay.IsPresent);
|
|
|
|
}
|
|
|
|
|
2021-08-17 14:11:45 +08:00
|
|
|
private void assertChatFocused(bool isFocused) =>
|
|
|
|
AddAssert($"chat {(isFocused ? "focused" : "not focused")}", () => textBox.HasFocus == isFocused);
|
|
|
|
|
|
|
|
private void setLocalUserPlaying(bool playing) =>
|
|
|
|
AddStep($"local user {(playing ? "playing" : "not playing")}", () => localUserPlaying.Value = playing);
|
|
|
|
}
|
|
|
|
}
|