2019-06-21 14:32:06 +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;
|
|
|
|
|
using System.Collections.Generic;
|
2020-01-30 13:35:03 +08:00
|
|
|
|
using System.Linq;
|
2019-07-01 18:35:04 +08:00
|
|
|
|
using NUnit.Framework;
|
2019-06-21 14:32:06 +08:00
|
|
|
|
using osu.Framework.Allocation;
|
2019-07-01 18:35:04 +08:00
|
|
|
|
using osu.Framework.Bindables;
|
2019-06-21 14:32:06 +08:00
|
|
|
|
using osu.Framework.Graphics;
|
|
|
|
|
using osu.Framework.Graphics.Containers;
|
2019-07-01 18:35:04 +08:00
|
|
|
|
using osu.Framework.Graphics.UserInterface;
|
2020-01-30 13:35:03 +08:00
|
|
|
|
using osu.Framework.Testing;
|
|
|
|
|
using osu.Game.Graphics.UserInterface;
|
2019-06-21 14:32:06 +08:00
|
|
|
|
using osu.Game.Online.Chat;
|
|
|
|
|
using osu.Game.Overlays;
|
|
|
|
|
using osu.Game.Overlays.Chat;
|
2019-07-01 18:35:04 +08:00
|
|
|
|
using osu.Game.Overlays.Chat.Selection;
|
2019-06-21 14:32:06 +08:00
|
|
|
|
using osu.Game.Overlays.Chat.Tabs;
|
2019-07-01 18:35:04 +08:00
|
|
|
|
using osu.Game.Users;
|
|
|
|
|
using osuTK.Input;
|
2019-06-21 14:32:06 +08:00
|
|
|
|
|
|
|
|
|
namespace osu.Game.Tests.Visual.Online
|
|
|
|
|
{
|
2019-07-01 18:35:04 +08:00
|
|
|
|
public class TestSceneChatOverlay : ManualInputManagerTestScene
|
2019-06-21 14:32:06 +08:00
|
|
|
|
{
|
|
|
|
|
public override IReadOnlyList<Type> RequiredTypes => new[]
|
|
|
|
|
{
|
|
|
|
|
typeof(ChatLine),
|
|
|
|
|
typeof(DrawableChannel),
|
|
|
|
|
typeof(ChannelSelectorTabItem),
|
|
|
|
|
typeof(ChannelTabControl),
|
|
|
|
|
typeof(ChannelTabItem),
|
|
|
|
|
typeof(PrivateChannelTabItem),
|
|
|
|
|
typeof(TabCloseButton)
|
|
|
|
|
};
|
|
|
|
|
|
2019-07-01 18:35:04 +08:00
|
|
|
|
private TestChatOverlay chatOverlay;
|
|
|
|
|
private ChannelManager channelManager;
|
2019-06-21 14:32:06 +08:00
|
|
|
|
|
2020-01-30 13:35:03 +08:00
|
|
|
|
private readonly Channel channel1 = new Channel(new User()) { Name = "test really long username", Topic = "Topic for channel 1" };
|
|
|
|
|
private readonly Channel channel2 = new Channel(new User()) { Name = "test2", Topic = "Topic for channel 2" };
|
|
|
|
|
private readonly Channel channel3 = new Channel(new User()) { Name = "channel with no topic" };
|
2019-07-01 18:35:04 +08:00
|
|
|
|
|
|
|
|
|
[SetUp]
|
|
|
|
|
public void Setup()
|
|
|
|
|
{
|
|
|
|
|
Schedule(() =>
|
|
|
|
|
{
|
|
|
|
|
ChannelManagerContainer container;
|
|
|
|
|
|
2020-01-30 13:35:03 +08:00
|
|
|
|
Child = container = new ChannelManagerContainer(new List<Channel> { channel1, channel2, channel3 })
|
2019-07-01 18:35:04 +08:00
|
|
|
|
{
|
|
|
|
|
RelativeSizeAxes = Axes.Both,
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
chatOverlay = container.ChatOverlay;
|
|
|
|
|
channelManager = container.ChannelManager;
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
[Test]
|
|
|
|
|
public void TestHideOverlay()
|
|
|
|
|
{
|
|
|
|
|
AddAssert("Chat overlay is visible", () => chatOverlay.State.Value == Visibility.Visible);
|
|
|
|
|
AddAssert("Selector is visible", () => chatOverlay.SelectionOverlayState == Visibility.Visible);
|
|
|
|
|
|
|
|
|
|
AddStep("Close chat overlay", () => chatOverlay.Hide());
|
|
|
|
|
|
|
|
|
|
AddAssert("Chat overlay was hidden", () => chatOverlay.State.Value == Visibility.Hidden);
|
|
|
|
|
AddAssert("Channel selection overlay was hidden", () => chatOverlay.SelectionOverlayState == Visibility.Hidden);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
[Test]
|
|
|
|
|
public void TestSelectingChannelClosesSelector()
|
|
|
|
|
{
|
|
|
|
|
AddAssert("Selector is visible", () => chatOverlay.SelectionOverlayState == Visibility.Visible);
|
|
|
|
|
|
|
|
|
|
AddStep("Join channel 1", () => channelManager.JoinChannel(channel1));
|
|
|
|
|
AddStep("Switch to channel 1", () => clickDrawable(chatOverlay.TabMap[channel1]));
|
|
|
|
|
|
|
|
|
|
AddAssert("Current channel is channel 1", () => channelManager.CurrentChannel.Value == channel1);
|
|
|
|
|
AddAssert("Channel selector was closed", () => chatOverlay.SelectionOverlayState == Visibility.Hidden);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
[Test]
|
|
|
|
|
public void TestCloseChannelWhileSelectorClosed()
|
|
|
|
|
{
|
|
|
|
|
AddStep("Join channel 1", () => channelManager.JoinChannel(channel1));
|
|
|
|
|
AddStep("Join channel 2", () => channelManager.JoinChannel(channel2));
|
|
|
|
|
|
|
|
|
|
AddStep("Switch to channel 2", () => clickDrawable(chatOverlay.TabMap[channel2]));
|
|
|
|
|
AddStep("Close channel 2", () => clickDrawable(((TestChannelTabItem)chatOverlay.TabMap[channel2]).CloseButton.Child));
|
|
|
|
|
|
|
|
|
|
AddAssert("Selector remained closed", () => chatOverlay.SelectionOverlayState == Visibility.Hidden);
|
|
|
|
|
AddAssert("Current channel is channel 1", () => channelManager.CurrentChannel.Value == channel1);
|
|
|
|
|
|
|
|
|
|
AddStep("Close channel 1", () => clickDrawable(((TestChannelTabItem)chatOverlay.TabMap[channel1]).CloseButton.Child));
|
|
|
|
|
|
|
|
|
|
AddAssert("Selector is visible", () => chatOverlay.SelectionOverlayState == Visibility.Visible);
|
|
|
|
|
}
|
|
|
|
|
|
2020-01-30 13:35:03 +08:00
|
|
|
|
[Test]
|
|
|
|
|
public void TestSearchInSelector()
|
|
|
|
|
{
|
|
|
|
|
AddStep("search for 'test2'", () => chatOverlay.ChildrenOfType<SearchTextBox>().First().Text = "test2");
|
2020-01-30 14:00:39 +08:00
|
|
|
|
AddUntilStep("only channel 2 visible", () => chatOverlay.ChildrenOfType<ChannelListItem>().Single(c => c.IsPresent).Channel == channel2);
|
2020-01-30 13:35:03 +08:00
|
|
|
|
}
|
|
|
|
|
|
2019-07-01 18:35:04 +08:00
|
|
|
|
private void clickDrawable(Drawable d)
|
2019-06-21 14:32:06 +08:00
|
|
|
|
{
|
2019-07-01 18:35:04 +08:00
|
|
|
|
InputManager.MoveMouseTo(d);
|
|
|
|
|
InputManager.Click(MouseButton.Left);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private class ChannelManagerContainer : Container
|
|
|
|
|
{
|
|
|
|
|
public TestChatOverlay ChatOverlay { get; private set; }
|
|
|
|
|
|
|
|
|
|
[Cached]
|
|
|
|
|
public ChannelManager ChannelManager { get; } = new ChannelManager();
|
|
|
|
|
|
|
|
|
|
private readonly List<Channel> channels;
|
|
|
|
|
|
|
|
|
|
public ChannelManagerContainer(List<Channel> channels)
|
|
|
|
|
{
|
|
|
|
|
this.channels = channels;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
[BackgroundDependencyLoader]
|
|
|
|
|
private void load()
|
|
|
|
|
{
|
|
|
|
|
((BindableList<Channel>)ChannelManager.AvailableChannels).AddRange(channels);
|
|
|
|
|
|
|
|
|
|
Child = ChatOverlay = new TestChatOverlay { RelativeSizeAxes = Axes.Both, };
|
|
|
|
|
ChatOverlay.Show();
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private class TestChatOverlay : ChatOverlay
|
|
|
|
|
{
|
|
|
|
|
public Visibility SelectionOverlayState => ChannelSelectionOverlay.State.Value;
|
|
|
|
|
|
|
|
|
|
public new ChannelSelectionOverlay ChannelSelectionOverlay => base.ChannelSelectionOverlay;
|
|
|
|
|
|
|
|
|
|
protected override ChannelTabControl CreateChannelTabControl() => new TestTabControl();
|
|
|
|
|
|
|
|
|
|
public IReadOnlyDictionary<Channel, TabItem<Channel>> TabMap => ((TestTabControl)ChannelTabControl).TabMap;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private class TestTabControl : ChannelTabControl
|
|
|
|
|
{
|
|
|
|
|
protected override TabItem<Channel> CreateTabItem(Channel value) => new TestChannelTabItem(value);
|
|
|
|
|
|
|
|
|
|
public new IReadOnlyDictionary<Channel, TabItem<Channel>> TabMap => base.TabMap;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private class TestChannelTabItem : PrivateChannelTabItem
|
|
|
|
|
{
|
|
|
|
|
public TestChannelTabItem(Channel channel)
|
|
|
|
|
: base(channel)
|
2019-06-21 14:32:06 +08:00
|
|
|
|
{
|
2019-07-01 18:35:04 +08:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public new ClickableContainer CloseButton => base.CloseButton;
|
2019-06-21 14:32:06 +08:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|