2020-03-13 20:29:10 +00:00
|
|
|
|
// Copyright (c) ppy Pty Ltd <contact@ppy.sh>. Licensed under the MIT Licence.
|
2019-06-21 06:32:06 +00:00
|
|
|
|
// See the LICENCE file in the repository root for full licence text.
|
|
|
|
|
|
2021-09-11 15:22:35 +00:00
|
|
|
|
using System;
|
2019-06-21 06:32:06 +00:00
|
|
|
|
using System.Collections.Generic;
|
2020-01-30 05:35:03 +00:00
|
|
|
|
using System.Linq;
|
2021-10-24 15:41:55 +00:00
|
|
|
|
using System.Net;
|
2021-10-05 18:52:40 +00:00
|
|
|
|
using JetBrains.Annotations;
|
2019-07-01 10:35:04 +00:00
|
|
|
|
using NUnit.Framework;
|
2019-06-21 06:32:06 +00:00
|
|
|
|
using osu.Framework.Allocation;
|
2019-07-01 10:35:04 +00:00
|
|
|
|
using osu.Framework.Bindables;
|
2019-06-21 06:32:06 +00:00
|
|
|
|
using osu.Framework.Graphics;
|
|
|
|
|
using osu.Framework.Graphics.Containers;
|
2019-07-01 10:35:04 +00:00
|
|
|
|
using osu.Framework.Graphics.UserInterface;
|
2021-06-03 06:34:06 +00:00
|
|
|
|
using osu.Framework.Input;
|
|
|
|
|
using osu.Framework.Platform;
|
2020-01-30 05:35:03 +00:00
|
|
|
|
using osu.Framework.Testing;
|
|
|
|
|
using osu.Game.Graphics.UserInterface;
|
2021-03-23 09:08:32 +00:00
|
|
|
|
using osu.Game.Online.API;
|
|
|
|
|
using osu.Game.Online.API.Requests;
|
2019-06-21 06:32:06 +00:00
|
|
|
|
using osu.Game.Online.Chat;
|
|
|
|
|
using osu.Game.Overlays;
|
2021-10-05 18:52:40 +00:00
|
|
|
|
using osu.Game.Overlays.Chat;
|
2019-07-01 10:35:04 +00:00
|
|
|
|
using osu.Game.Overlays.Chat.Selection;
|
2019-06-21 06:32:06 +00:00
|
|
|
|
using osu.Game.Overlays.Chat.Tabs;
|
2019-07-01 10:35:04 +00:00
|
|
|
|
using osu.Game.Users;
|
|
|
|
|
using osuTK.Input;
|
2019-06-21 06:32:06 +00:00
|
|
|
|
|
|
|
|
|
namespace osu.Game.Tests.Visual.Online
|
|
|
|
|
{
|
2020-03-23 01:01:33 +00:00
|
|
|
|
public class TestSceneChatOverlay : OsuManualInputManagerTestScene
|
2019-06-21 06:32:06 +00:00
|
|
|
|
{
|
2019-07-01 10:35:04 +00:00
|
|
|
|
private TestChatOverlay chatOverlay;
|
|
|
|
|
private ChannelManager channelManager;
|
2019-06-21 06:32:06 +00:00
|
|
|
|
|
2020-03-13 17:34:22 +00:00
|
|
|
|
private IEnumerable<Channel> visibleChannels => chatOverlay.ChannelTabControl.VisibleItems.Where(channel => channel.Name != "+");
|
|
|
|
|
private IEnumerable<Channel> joinedChannels => chatOverlay.ChannelTabControl.Items.Where(channel => channel.Name != "+");
|
2020-01-30 20:17:46 +00:00
|
|
|
|
private readonly List<Channel> channels;
|
|
|
|
|
|
2020-03-13 17:34:22 +00:00
|
|
|
|
private Channel currentChannel => channelManager.CurrentChannel.Value;
|
|
|
|
|
private Channel nextChannel => joinedChannels.ElementAt(joinedChannels.ToList().IndexOf(currentChannel) + 1);
|
|
|
|
|
private Channel previousChannel => joinedChannels.ElementAt(joinedChannels.ToList().IndexOf(currentChannel) - 1);
|
2020-01-30 20:17:46 +00:00
|
|
|
|
private Channel channel1 => channels[0];
|
|
|
|
|
private Channel channel2 => channels[1];
|
2020-12-20 19:18:00 +00:00
|
|
|
|
private Channel channel3 => channels[2];
|
2020-01-30 20:17:46 +00:00
|
|
|
|
|
2021-10-05 18:52:40 +00:00
|
|
|
|
[CanBeNull]
|
|
|
|
|
private Func<Channel, List<Message>> onGetMessages;
|
|
|
|
|
|
2021-06-03 06:34:06 +00:00
|
|
|
|
[Resolved]
|
|
|
|
|
private GameHost host { get; set; }
|
|
|
|
|
|
2020-01-30 20:17:46 +00:00
|
|
|
|
public TestSceneChatOverlay()
|
|
|
|
|
{
|
|
|
|
|
channels = Enumerable.Range(1, 10)
|
2020-03-16 18:44:03 +00:00
|
|
|
|
.Select(index => new Channel(new User())
|
2020-01-30 20:17:46 +00:00
|
|
|
|
{
|
|
|
|
|
Name = $"Channel no. {index}",
|
2020-03-16 18:10:42 +00:00
|
|
|
|
Topic = index == 3 ? null : $"We talk about the number {index} here",
|
2020-12-20 19:18:00 +00:00
|
|
|
|
Type = index % 2 == 0 ? ChannelType.PM : ChannelType.Temporary,
|
|
|
|
|
Id = index
|
2020-01-30 20:17:46 +00:00
|
|
|
|
})
|
|
|
|
|
.ToList();
|
|
|
|
|
}
|
2019-07-01 10:35:04 +00:00
|
|
|
|
|
|
|
|
|
[SetUp]
|
|
|
|
|
public void Setup()
|
|
|
|
|
{
|
|
|
|
|
Schedule(() =>
|
|
|
|
|
{
|
|
|
|
|
ChannelManagerContainer container;
|
|
|
|
|
|
2020-01-30 20:17:46 +00:00
|
|
|
|
Child = container = new ChannelManagerContainer(channels)
|
2019-07-01 10:35:04 +00:00
|
|
|
|
{
|
|
|
|
|
RelativeSizeAxes = Axes.Both,
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
chatOverlay = container.ChatOverlay;
|
|
|
|
|
channelManager = container.ChannelManager;
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
|
2021-03-23 09:08:32 +00:00
|
|
|
|
[SetUpSteps]
|
|
|
|
|
public void SetUpSteps()
|
|
|
|
|
{
|
|
|
|
|
AddStep("register request handling", () =>
|
|
|
|
|
{
|
2021-10-05 18:52:40 +00:00
|
|
|
|
onGetMessages = null;
|
|
|
|
|
|
2021-03-23 09:08:32 +00:00
|
|
|
|
((DummyAPIAccess)API).HandleRequest = req =>
|
|
|
|
|
{
|
|
|
|
|
switch (req)
|
|
|
|
|
{
|
2021-06-29 11:13:39 +00:00
|
|
|
|
case JoinChannelRequest joinChannel:
|
|
|
|
|
joinChannel.TriggerSuccess();
|
2021-03-23 09:08:32 +00:00
|
|
|
|
return true;
|
2021-09-11 15:22:35 +00:00
|
|
|
|
|
|
|
|
|
case GetUserRequest getUser:
|
|
|
|
|
if (getUser.Lookup.Equals("some body", StringComparison.OrdinalIgnoreCase))
|
|
|
|
|
{
|
2021-09-11 15:47:20 +00:00
|
|
|
|
getUser.TriggerSuccess(new User
|
2021-09-11 15:22:35 +00:00
|
|
|
|
{
|
|
|
|
|
Username = "some body",
|
|
|
|
|
Id = 1,
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
2021-10-24 15:41:55 +00:00
|
|
|
|
getUser.TriggerFailure(new WebException());
|
2021-09-11 15:22:35 +00:00
|
|
|
|
}
|
2021-09-11 15:47:20 +00:00
|
|
|
|
|
2021-09-11 15:22:35 +00:00
|
|
|
|
return true;
|
2021-10-05 18:52:40 +00:00
|
|
|
|
|
|
|
|
|
case GetMessagesRequest getMessages:
|
|
|
|
|
var messages = onGetMessages?.Invoke(getMessages.Channel);
|
|
|
|
|
if (messages != null)
|
|
|
|
|
getMessages.TriggerSuccess(messages);
|
|
|
|
|
return true;
|
2021-03-23 09:08:32 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return false;
|
|
|
|
|
};
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
|
2019-07-01 10:35:04 +00:00
|
|
|
|
[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]
|
2021-10-05 18:52:40 +00:00
|
|
|
|
public void TestChannelSelection()
|
2019-07-01 10:35:04 +00:00
|
|
|
|
{
|
|
|
|
|
AddAssert("Selector is visible", () => chatOverlay.SelectionOverlayState == Visibility.Visible);
|
2021-10-05 18:52:40 +00:00
|
|
|
|
AddStep("Setup get message response", () => onGetMessages = channel =>
|
|
|
|
|
{
|
|
|
|
|
if (channel == channel1)
|
|
|
|
|
{
|
|
|
|
|
return new List<Message>
|
|
|
|
|
{
|
|
|
|
|
new Message(1)
|
|
|
|
|
{
|
|
|
|
|
ChannelId = channel1.Id,
|
|
|
|
|
Content = "hello from channel 1!",
|
|
|
|
|
Sender = new User
|
|
|
|
|
{
|
|
|
|
|
Id = 2,
|
|
|
|
|
Username = "test_user"
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
};
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return null;
|
|
|
|
|
});
|
2019-07-01 10:35:04 +00:00
|
|
|
|
|
|
|
|
|
AddStep("Join channel 1", () => channelManager.JoinChannel(channel1));
|
|
|
|
|
AddStep("Switch to channel 1", () => clickDrawable(chatOverlay.TabMap[channel1]));
|
|
|
|
|
|
2020-03-13 17:34:22 +00:00
|
|
|
|
AddAssert("Current channel is channel 1", () => currentChannel == channel1);
|
2021-10-05 18:52:40 +00:00
|
|
|
|
AddUntilStep("Loading spinner hidden", () => chatOverlay.ChildrenOfType<LoadingSpinner>().All(spinner => !spinner.IsPresent));
|
|
|
|
|
AddAssert("Channel message shown", () => chatOverlay.ChildrenOfType<ChatLine>().Count() == 1);
|
2019-07-01 10:35:04 +00:00
|
|
|
|
AddAssert("Channel selector was closed", () => chatOverlay.SelectionOverlayState == Visibility.Hidden);
|
|
|
|
|
}
|
|
|
|
|
|
2020-01-30 05:35:03 +00:00
|
|
|
|
[Test]
|
|
|
|
|
public void TestSearchInSelector()
|
|
|
|
|
{
|
2020-03-16 18:10:42 +00:00
|
|
|
|
AddStep("Search for 'no. 2'", () => chatOverlay.ChildrenOfType<SearchTextBox>().First().Text = "no. 2");
|
|
|
|
|
AddUntilStep("Only channel 2 visible", () =>
|
2020-01-30 15:33:24 +00:00
|
|
|
|
{
|
|
|
|
|
var listItems = chatOverlay.ChildrenOfType<ChannelListItem>().Where(c => c.IsPresent);
|
|
|
|
|
return listItems.Count() == 1 && listItems.Single().Channel == channel2;
|
|
|
|
|
});
|
2020-01-30 05:35:03 +00:00
|
|
|
|
}
|
|
|
|
|
|
2020-01-30 20:17:46 +00:00
|
|
|
|
[Test]
|
|
|
|
|
public void TestChannelShortcutKeys()
|
|
|
|
|
{
|
2020-03-16 18:10:42 +00:00
|
|
|
|
AddStep("Join channels", () => channels.ForEach(channel => channelManager.JoinChannel(channel)));
|
2020-11-05 14:41:56 +00:00
|
|
|
|
AddStep("Close channel selector", () => InputManager.Key(Key.Escape));
|
2020-03-16 18:10:42 +00:00
|
|
|
|
AddUntilStep("Wait for close", () => chatOverlay.SelectionOverlayState == Visibility.Hidden);
|
2020-01-30 20:17:46 +00:00
|
|
|
|
|
|
|
|
|
for (int zeroBasedIndex = 0; zeroBasedIndex < 10; ++zeroBasedIndex)
|
|
|
|
|
{
|
2021-10-27 04:04:41 +00:00
|
|
|
|
int oneBasedIndex = zeroBasedIndex + 1;
|
|
|
|
|
int targetNumberKey = oneBasedIndex % 10;
|
2020-01-30 20:17:46 +00:00
|
|
|
|
var targetChannel = channels[zeroBasedIndex];
|
2020-03-16 18:10:42 +00:00
|
|
|
|
AddStep($"Press Alt+{targetNumberKey}", () => pressChannelHotkey(targetNumberKey));
|
|
|
|
|
AddAssert($"Channel #{oneBasedIndex} is selected", () => currentChannel == targetChannel);
|
2020-01-30 20:17:46 +00:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2020-03-13 17:34:22 +00:00
|
|
|
|
private Channel expectedChannel;
|
|
|
|
|
|
|
|
|
|
[Test]
|
2020-03-16 18:10:42 +00:00
|
|
|
|
public void TestCloseChannelBehaviour()
|
2020-03-13 17:34:22 +00:00
|
|
|
|
{
|
|
|
|
|
AddUntilStep("Join until dropdown has channels", () =>
|
|
|
|
|
{
|
|
|
|
|
if (visibleChannels.Count() < joinedChannels.Count())
|
|
|
|
|
return true;
|
|
|
|
|
|
|
|
|
|
// Using temporary channels because they don't hide their names when not active
|
2020-03-16 18:10:42 +00:00
|
|
|
|
channelManager.JoinChannel(new Channel
|
2020-03-16 18:44:03 +00:00
|
|
|
|
{
|
2020-03-16 20:31:22 +00:00
|
|
|
|
Name = $"Channel no. {joinedChannels.Count() + 11}",
|
2020-03-16 18:44:03 +00:00
|
|
|
|
Type = ChannelType.Temporary
|
2020-03-16 18:10:42 +00:00
|
|
|
|
});
|
2020-03-13 17:34:22 +00:00
|
|
|
|
|
|
|
|
|
return false;
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
AddStep("Switch to last tab", () => clickDrawable(chatOverlay.TabMap[visibleChannels.Last()]));
|
|
|
|
|
AddAssert("Last visible selected", () => currentChannel == visibleChannels.Last());
|
|
|
|
|
|
|
|
|
|
// Closing the last channel before dropdown
|
|
|
|
|
AddStep("Close current channel", () =>
|
|
|
|
|
{
|
|
|
|
|
expectedChannel = nextChannel;
|
|
|
|
|
chatOverlay.ChannelTabControl.RemoveChannel(currentChannel);
|
|
|
|
|
});
|
|
|
|
|
AddAssert("Next channel selected", () => currentChannel == expectedChannel);
|
2020-03-16 18:10:42 +00:00
|
|
|
|
AddAssert("Selector remained closed", () => chatOverlay.SelectionOverlayState == Visibility.Hidden);
|
2020-03-13 17:34:22 +00:00
|
|
|
|
|
|
|
|
|
// Depending on the window size, one more channel might need to be closed for the selectorTab to appear
|
|
|
|
|
AddUntilStep("Close channels until selector visible", () =>
|
|
|
|
|
{
|
|
|
|
|
if (chatOverlay.ChannelTabControl.VisibleItems.Last().Name == "+")
|
|
|
|
|
return true;
|
|
|
|
|
|
|
|
|
|
chatOverlay.ChannelTabControl.RemoveChannel(visibleChannels.Last());
|
|
|
|
|
return false;
|
|
|
|
|
});
|
|
|
|
|
AddAssert("Last visible selected", () => currentChannel == visibleChannels.Last());
|
|
|
|
|
|
|
|
|
|
// Closing the last channel with dropdown no longer present
|
2020-03-13 20:29:10 +00:00
|
|
|
|
AddStep("Close last when selector next", () =>
|
2020-03-13 17:34:22 +00:00
|
|
|
|
{
|
|
|
|
|
expectedChannel = previousChannel;
|
|
|
|
|
chatOverlay.ChannelTabControl.RemoveChannel(currentChannel);
|
|
|
|
|
});
|
2020-03-16 18:10:42 +00:00
|
|
|
|
AddAssert("Previous channel selected", () => currentChannel == expectedChannel);
|
2020-03-13 17:34:22 +00:00
|
|
|
|
|
|
|
|
|
// Standard channel closing
|
|
|
|
|
AddStep("Switch to previous channel", () => chatOverlay.ChannelTabControl.SwitchTab(-1));
|
2020-03-13 20:29:10 +00:00
|
|
|
|
AddStep("Close current channel", () =>
|
2020-03-13 17:34:22 +00:00
|
|
|
|
{
|
|
|
|
|
expectedChannel = nextChannel;
|
|
|
|
|
chatOverlay.ChannelTabControl.RemoveChannel(currentChannel);
|
|
|
|
|
});
|
2020-03-16 18:10:42 +00:00
|
|
|
|
AddAssert("Next channel selected", () => currentChannel == expectedChannel);
|
|
|
|
|
|
|
|
|
|
// Selector reappearing after all channels closed
|
|
|
|
|
AddUntilStep("Close all channels", () =>
|
|
|
|
|
{
|
|
|
|
|
if (!joinedChannels.Any())
|
|
|
|
|
return true;
|
2020-03-16 18:44:03 +00:00
|
|
|
|
|
2020-03-16 18:10:42 +00:00
|
|
|
|
chatOverlay.ChannelTabControl.RemoveChannel(joinedChannels.Last());
|
|
|
|
|
return false;
|
|
|
|
|
});
|
|
|
|
|
AddAssert("Selector is visible", () => chatOverlay.SelectionOverlayState == Visibility.Visible);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
[Test]
|
|
|
|
|
public void TestChannelCloseButton()
|
|
|
|
|
{
|
2020-03-16 18:44:03 +00:00
|
|
|
|
AddStep("Join 2 channels", () =>
|
2020-03-16 18:10:42 +00:00
|
|
|
|
{
|
|
|
|
|
channelManager.JoinChannel(channel1);
|
2020-03-16 18:44:03 +00:00
|
|
|
|
channelManager.JoinChannel(channel2);
|
2020-03-16 18:10:42 +00:00
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
// PM channel close button only appears when active
|
2020-03-16 18:44:03 +00:00
|
|
|
|
AddStep("Select PM channel", () => clickDrawable(chatOverlay.TabMap[channel2]));
|
|
|
|
|
AddStep("Click PM close button", () => clickDrawable(((TestPrivateChannelTabItem)chatOverlay.TabMap[channel2]).CloseButton.Child));
|
|
|
|
|
AddAssert("PM channel closed", () => !channelManager.JoinedChannels.Contains(channel2));
|
2020-03-16 18:10:42 +00:00
|
|
|
|
|
|
|
|
|
// Non-PM chat channel close button only appears when hovered
|
|
|
|
|
AddStep("Hover normal channel tab", () => InputManager.MoveMouseTo(chatOverlay.TabMap[channel1]));
|
|
|
|
|
AddStep("Click normal close button", () => clickDrawable(((TestChannelTabItem)chatOverlay.TabMap[channel1]).CloseButton.Child));
|
|
|
|
|
AddAssert("All channels closed", () => !channelManager.JoinedChannels.Any());
|
2020-03-13 17:34:22 +00:00
|
|
|
|
}
|
2020-12-14 23:44:40 +00:00
|
|
|
|
|
2020-12-14 06:11:52 +00:00
|
|
|
|
[Test]
|
2021-06-03 06:34:06 +00:00
|
|
|
|
public void TestCloseTabShortcut()
|
2020-12-14 06:05:54 +00:00
|
|
|
|
{
|
2020-12-14 20:38:59 +00:00
|
|
|
|
AddStep("Join 2 channels", () =>
|
2020-12-14 06:05:54 +00:00
|
|
|
|
{
|
|
|
|
|
channelManager.JoinChannel(channel1);
|
|
|
|
|
channelManager.JoinChannel(channel2);
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
// Want to close channel 2
|
|
|
|
|
AddStep("Select channel 2", () => clickDrawable(chatOverlay.TabMap[channel2]));
|
2021-06-03 12:31:13 +00:00
|
|
|
|
AddStep("Close tab via shortcut", pressCloseDocumentKeys);
|
2020-12-14 06:05:54 +00:00
|
|
|
|
|
|
|
|
|
// Channel 2 should be closed
|
2020-12-17 22:59:19 +00:00
|
|
|
|
AddAssert("Channel 1 open", () => channelManager.JoinedChannels.Contains(channel1));
|
|
|
|
|
AddAssert("Channel 2 closed", () => !channelManager.JoinedChannels.Contains(channel2));
|
2020-12-14 06:05:54 +00:00
|
|
|
|
|
|
|
|
|
// Want to close channel 1
|
|
|
|
|
AddStep("Select channel 1", () => clickDrawable(chatOverlay.TabMap[channel1]));
|
|
|
|
|
|
2021-06-03 12:31:13 +00:00
|
|
|
|
AddStep("Close tab via shortcut", pressCloseDocumentKeys);
|
2020-12-14 06:05:54 +00:00
|
|
|
|
// Channel 1 and channel 2 should be closed
|
2020-12-14 20:38:59 +00:00
|
|
|
|
AddAssert("All channels closed", () => !channelManager.JoinedChannels.Any());
|
2020-12-14 06:05:54 +00:00
|
|
|
|
}
|
|
|
|
|
|
2020-12-14 06:11:52 +00:00
|
|
|
|
[Test]
|
2021-06-03 06:34:06 +00:00
|
|
|
|
public void TestNewTabShortcut()
|
2020-12-14 06:05:54 +00:00
|
|
|
|
{
|
2020-12-14 20:38:59 +00:00
|
|
|
|
AddStep("Join 2 channels", () =>
|
2020-12-14 06:05:54 +00:00
|
|
|
|
{
|
|
|
|
|
channelManager.JoinChannel(channel1);
|
|
|
|
|
channelManager.JoinChannel(channel2);
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
// Want to join another channel
|
2021-06-03 12:31:13 +00:00
|
|
|
|
AddStep("Press new tab shortcut", pressNewTabKeys);
|
2020-12-18 00:43:39 +00:00
|
|
|
|
|
2020-12-14 06:05:54 +00:00
|
|
|
|
// Selector should be visible
|
|
|
|
|
AddAssert("Selector is visible", () => chatOverlay.SelectionOverlayState == Visibility.Visible);
|
|
|
|
|
}
|
2020-03-13 17:34:22 +00:00
|
|
|
|
|
2020-12-20 19:18:00 +00:00
|
|
|
|
[Test]
|
2021-06-03 06:34:06 +00:00
|
|
|
|
public void TestRestoreTabShortcut()
|
2020-12-20 19:18:00 +00:00
|
|
|
|
{
|
|
|
|
|
AddStep("Join 3 channels", () =>
|
|
|
|
|
{
|
|
|
|
|
channelManager.JoinChannel(channel1);
|
|
|
|
|
channelManager.JoinChannel(channel2);
|
|
|
|
|
channelManager.JoinChannel(channel3);
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
// Should do nothing
|
2021-06-03 12:31:13 +00:00
|
|
|
|
AddStep("Restore tab via shortcut", pressRestoreTabKeys);
|
2020-12-20 19:18:00 +00:00
|
|
|
|
AddAssert("All channels still open", () => channelManager.JoinedChannels.Count == 3);
|
|
|
|
|
|
|
|
|
|
// Close channel 1
|
|
|
|
|
AddStep("Select channel 1", () => clickDrawable(chatOverlay.TabMap[channel1]));
|
|
|
|
|
AddStep("Click normal close button", () => clickDrawable(((TestChannelTabItem)chatOverlay.TabMap[channel1]).CloseButton.Child));
|
|
|
|
|
AddAssert("Channel 1 closed", () => !channelManager.JoinedChannels.Contains(channel1));
|
|
|
|
|
AddAssert("Other channels still open", () => channelManager.JoinedChannels.Count == 2);
|
|
|
|
|
|
|
|
|
|
// Reopen channel 1
|
2021-06-03 12:31:13 +00:00
|
|
|
|
AddStep("Restore tab via shortcut", pressRestoreTabKeys);
|
2020-12-20 19:18:00 +00:00
|
|
|
|
AddAssert("All channels now open", () => channelManager.JoinedChannels.Count == 3);
|
|
|
|
|
AddAssert("Current channel is channel 1", () => currentChannel == channel1);
|
|
|
|
|
|
|
|
|
|
// Close two channels
|
|
|
|
|
AddStep("Select channel 1", () => clickDrawable(chatOverlay.TabMap[channel1]));
|
|
|
|
|
AddStep("Close channel 1", () => clickDrawable(((TestChannelTabItem)chatOverlay.TabMap[channel1]).CloseButton.Child));
|
|
|
|
|
AddStep("Select channel 2", () => clickDrawable(chatOverlay.TabMap[channel2]));
|
|
|
|
|
AddStep("Close channel 2", () => clickDrawable(((TestPrivateChannelTabItem)chatOverlay.TabMap[channel2]).CloseButton.Child));
|
|
|
|
|
AddAssert("Only one channel open", () => channelManager.JoinedChannels.Count == 1);
|
|
|
|
|
AddAssert("Current channel is channel 3", () => currentChannel == channel3);
|
|
|
|
|
|
|
|
|
|
// Should first re-open channel 2
|
2021-06-03 12:31:13 +00:00
|
|
|
|
AddStep("Restore tab via shortcut", pressRestoreTabKeys);
|
2020-12-20 19:18:00 +00:00
|
|
|
|
AddAssert("Channel 1 still closed", () => !channelManager.JoinedChannels.Contains(channel1));
|
|
|
|
|
AddAssert("Channel 2 now open", () => channelManager.JoinedChannels.Contains(channel2));
|
|
|
|
|
AddAssert("Current channel is channel 2", () => currentChannel == channel2);
|
|
|
|
|
|
|
|
|
|
// Should then re-open channel 1
|
2021-06-03 12:31:13 +00:00
|
|
|
|
AddStep("Restore tab via shortcut", pressRestoreTabKeys);
|
2020-12-20 19:18:00 +00:00
|
|
|
|
AddAssert("All channels now open", () => channelManager.JoinedChannels.Count == 3);
|
|
|
|
|
AddAssert("Current channel is channel 1", () => currentChannel == channel1);
|
|
|
|
|
}
|
|
|
|
|
|
2021-09-11 15:22:35 +00:00
|
|
|
|
[Test]
|
|
|
|
|
public void TestChatCommand()
|
|
|
|
|
{
|
|
|
|
|
AddStep("Join channel 1", () => channelManager.JoinChannel(channel1));
|
|
|
|
|
AddStep("Select channel 1", () => clickDrawable(chatOverlay.TabMap[channel1]));
|
|
|
|
|
|
2021-09-12 11:00:52 +00:00
|
|
|
|
AddStep("Open chat with user", () => channelManager.PostCommand("chat some body"));
|
2021-09-11 15:22:35 +00:00
|
|
|
|
AddAssert("PM channel is selected", () =>
|
|
|
|
|
channelManager.CurrentChannel.Value.Type == ChannelType.PM && channelManager.CurrentChannel.Value.Users.Single().Username == "some body");
|
|
|
|
|
|
2021-09-12 11:00:52 +00:00
|
|
|
|
AddStep("Open chat with non-existent user", () => channelManager.PostCommand("chat nobody"));
|
|
|
|
|
AddAssert("Last message is error", () => channelManager.CurrentChannel.Value.Messages.Last() is ErrorMessage);
|
2021-09-11 15:22:35 +00:00
|
|
|
|
|
2021-09-11 15:23:17 +00:00
|
|
|
|
// Make sure no unnecessary requests are made when the PM channel is already open.
|
2021-09-11 15:22:35 +00:00
|
|
|
|
AddStep("Select channel 1", () => clickDrawable(chatOverlay.TabMap[channel1]));
|
|
|
|
|
AddStep("Unregister request handling", () => ((DummyAPIAccess)API).HandleRequest = null);
|
2021-09-12 11:00:52 +00:00
|
|
|
|
AddStep("Open chat with user", () => channelManager.PostCommand("chat some body"));
|
2021-09-11 15:22:35 +00:00
|
|
|
|
AddAssert("PM channel is selected", () =>
|
|
|
|
|
channelManager.CurrentChannel.Value.Type == ChannelType.PM && channelManager.CurrentChannel.Value.Users.Single().Username == "some body");
|
|
|
|
|
}
|
|
|
|
|
|
2020-01-30 20:17:46 +00:00
|
|
|
|
private void pressChannelHotkey(int number)
|
|
|
|
|
{
|
|
|
|
|
var channelKey = Key.Number0 + number;
|
|
|
|
|
InputManager.PressKey(Key.AltLeft);
|
2020-11-05 14:41:56 +00:00
|
|
|
|
InputManager.Key(channelKey);
|
2020-01-30 20:17:46 +00:00
|
|
|
|
InputManager.ReleaseKey(Key.AltLeft);
|
|
|
|
|
}
|
|
|
|
|
|
2021-08-03 09:37:01 +00:00
|
|
|
|
private void pressCloseDocumentKeys() => InputManager.Keys(PlatformAction.DocumentClose);
|
2020-12-16 04:50:23 +00:00
|
|
|
|
|
2021-08-03 09:37:01 +00:00
|
|
|
|
private void pressNewTabKeys() => InputManager.Keys(PlatformAction.TabNew);
|
2021-06-03 06:34:06 +00:00
|
|
|
|
|
2021-08-03 09:37:01 +00:00
|
|
|
|
private void pressRestoreTabKeys() => InputManager.Keys(PlatformAction.TabRestore);
|
2020-12-20 19:18:00 +00:00
|
|
|
|
|
2019-07-01 10:35:04 +00:00
|
|
|
|
private void clickDrawable(Drawable d)
|
2019-06-21 06:32:06 +00:00
|
|
|
|
{
|
2019-07-01 10:35:04 +00: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);
|
|
|
|
|
|
2020-06-03 09:00:31 +00:00
|
|
|
|
InternalChildren = new Drawable[]
|
|
|
|
|
{
|
|
|
|
|
ChannelManager,
|
|
|
|
|
ChatOverlay = new TestChatOverlay { RelativeSizeAxes = Axes.Both, },
|
|
|
|
|
};
|
|
|
|
|
|
2019-07-01 10:35:04 +00:00
|
|
|
|
ChatOverlay.Show();
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private class TestChatOverlay : ChatOverlay
|
|
|
|
|
{
|
|
|
|
|
public Visibility SelectionOverlayState => ChannelSelectionOverlay.State.Value;
|
|
|
|
|
|
2020-03-13 17:34:22 +00:00
|
|
|
|
public new ChannelTabControl ChannelTabControl => base.ChannelTabControl;
|
|
|
|
|
|
2019-07-01 10:35:04 +00:00
|
|
|
|
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
|
|
|
|
|
{
|
2020-03-13 17:33:58 +00:00
|
|
|
|
protected override TabItem<Channel> CreateTabItem(Channel value)
|
|
|
|
|
{
|
|
|
|
|
switch (value.Type)
|
|
|
|
|
{
|
|
|
|
|
case ChannelType.PM:
|
|
|
|
|
return new TestPrivateChannelTabItem(value);
|
|
|
|
|
|
|
|
|
|
default:
|
|
|
|
|
return new TestChannelTabItem(value);
|
|
|
|
|
}
|
|
|
|
|
}
|
2019-07-01 10:35:04 +00:00
|
|
|
|
|
|
|
|
|
public new IReadOnlyDictionary<Channel, TabItem<Channel>> TabMap => base.TabMap;
|
|
|
|
|
}
|
|
|
|
|
|
2020-03-13 17:33:58 +00:00
|
|
|
|
private class TestChannelTabItem : ChannelTabItem
|
2019-07-01 10:35:04 +00:00
|
|
|
|
{
|
|
|
|
|
public TestChannelTabItem(Channel channel)
|
|
|
|
|
: base(channel)
|
2019-06-21 06:32:06 +00:00
|
|
|
|
{
|
2019-07-01 10:35:04 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public new ClickableContainer CloseButton => base.CloseButton;
|
2019-06-21 06:32:06 +00:00
|
|
|
|
}
|
2020-03-13 17:33:58 +00:00
|
|
|
|
|
|
|
|
|
private class TestPrivateChannelTabItem : PrivateChannelTabItem
|
|
|
|
|
{
|
|
|
|
|
public TestPrivateChannelTabItem(Channel channel)
|
|
|
|
|
: base(channel)
|
|
|
|
|
{
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public new ClickableContainer CloseButton => base.CloseButton;
|
|
|
|
|
}
|
2019-06-21 06:32:06 +00:00
|
|
|
|
}
|
|
|
|
|
}
|