osu/osu.Game.Tests/Visual/Online/TestSceneChannelTabControl.cs

130 lines
5.1 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.
2018-04-14 11:32:48 +00:00
using System.Collections.Generic;
using System.Linq;
2018-04-14 11:32:48 +00:00
using osu.Framework.Extensions.Color4Extensions;
2020-01-16 09:34:56 +00:00
using osu.Framework.Extensions.IEnumerableExtensions;
2018-04-14 11:32:48 +00:00
using osu.Framework.Graphics;
using osu.Framework.Graphics.Containers;
using osu.Framework.Graphics.Shapes;
using osu.Framework.Graphics.Sprites;
2020-01-09 04:43:44 +00:00
using osu.Framework.Utils;
using osu.Game.Graphics.Sprites;
2018-04-14 11:32:48 +00:00
using osu.Game.Online.Chat;
2018-07-09 20:09:27 +00:00
using osu.Game.Overlays.Chat.Tabs;
2018-04-14 11:32:48 +00:00
using osu.Game.Users;
2018-11-20 07:51:59 +00:00
using osuTK.Graphics;
2018-04-14 11:32:48 +00:00
2019-03-24 16:02:36 +00:00
namespace osu.Game.Tests.Visual.Online
2018-04-14 11:32:48 +00:00
{
public class TestSceneChannelTabControl : OsuTestScene
2018-04-14 11:32:48 +00:00
{
2020-01-16 09:34:56 +00:00
private readonly TestTabControl channelTabControl;
2018-04-14 11:32:48 +00:00
public TestSceneChannelTabControl()
2018-04-14 11:32:48 +00:00
{
SpriteText currentText;
Add(new Container
{
RelativeSizeAxes = Axes.X,
Origin = Anchor.Centre,
Anchor = Anchor.Centre,
Children = new Drawable[]
{
2020-01-16 09:34:56 +00:00
channelTabControl = new TestTabControl
2018-04-14 11:32:48 +00:00
{
RelativeSizeAxes = Axes.X,
Origin = Anchor.Centre,
Anchor = Anchor.Centre,
Height = 50
},
new Box
{
Colour = Color4.Black.Opacity(0.1f),
RelativeSizeAxes = Axes.X,
Height = 50,
Depth = -1,
Origin = Anchor.Centre,
Anchor = Anchor.Centre,
}
}
});
Add(new Container
{
Origin = Anchor.TopLeft,
Anchor = Anchor.TopLeft,
Children = new Drawable[]
{
currentText = new OsuSpriteText
2018-04-14 11:32:48 +00:00
{
Text = "Currently selected channel:"
2018-04-14 11:32:48 +00:00
}
}
});
channelTabControl.OnRequestLeave += channel => channelTabControl.RemoveChannel(channel);
2019-07-08 07:34:11 +00:00
channelTabControl.Current.ValueChanged += channel => currentText.Text = "Currently selected channel: " + channel.NewValue;
2018-04-14 11:32:48 +00:00
2018-12-07 05:00:16 +00:00
AddStep("Add random private channel", addRandomPrivateChannel);
2020-01-16 09:34:56 +00:00
AddAssert("There is only one channels", () => channelTabControl.Items.Count == 2);
2018-12-07 05:00:16 +00:00
AddRepeatStep("Add 3 random private channels", addRandomPrivateChannel, 3);
2020-01-16 09:34:56 +00:00
AddAssert("There are four channels", () => channelTabControl.Items.Count == 5);
2018-07-29 22:13:32 +00:00
AddStep("Add random public channel", () => addChannel(RNG.Next().ToString()));
2020-01-16 09:34:56 +00:00
AddRepeatStep("Select a random channel", () =>
{
List<Channel> validChannels = channelTabControl.Items.Where(c => !(c is ChannelSelectorTabItem.ChannelSelectorTabChannel)).ToList();
channelTabControl.SelectChannel(validChannels[RNG.Next(0, validChannels.Count)]);
}, 20);
2018-04-14 11:32:48 +00:00
2020-01-16 09:34:56 +00:00
Channel channelBefore = null;
AddStep("set first channel", () => channelTabControl.SelectChannel(channelBefore = channelTabControl.Items.First(c => !(c is ChannelSelectorTabItem.ChannelSelectorTabChannel))));
2020-01-16 09:34:56 +00:00
AddStep("select selector tab", () => channelTabControl.SelectChannel(channelTabControl.Items.Single(c => c is ChannelSelectorTabItem.ChannelSelectorTabChannel)));
2018-12-07 05:00:16 +00:00
AddAssert("selector tab is active", () => channelTabControl.ChannelSelectorActive.Value);
AddAssert("check channel unchanged", () => channelBefore == channelTabControl.Current.Value);
2020-01-16 09:34:56 +00:00
AddStep("set second channel", () => channelTabControl.SelectChannel(channelTabControl.Items.GetNext(channelBefore)));
2018-12-07 05:00:16 +00:00
AddAssert("selector tab is inactive", () => !channelTabControl.ChannelSelectorActive.Value);
2019-03-19 08:24:26 +00:00
AddUntilStep("remove all channels", () =>
2018-08-03 23:00:46 +00:00
{
2020-01-16 09:34:56 +00:00
foreach (var item in channelTabControl.Items.ToList())
{
if (item is ChannelSelectorTabItem.ChannelSelectorTabChannel)
continue;
channelTabControl.RemoveChannel(item);
return false;
}
2018-12-07 05:00:16 +00:00
2020-01-16 09:34:56 +00:00
return true;
2019-03-19 08:24:26 +00:00
});
2018-12-07 05:00:16 +00:00
AddAssert("selector tab is active", () => channelTabControl.ChannelSelectorActive.Value);
2018-04-14 11:32:48 +00:00
}
2018-12-07 05:00:16 +00:00
private void addRandomPrivateChannel() =>
channelTabControl.AddChannel(new Channel(new User
{
Id = RNG.Next(1000, 10000000),
Username = "Test User " + RNG.Next(1000)
}));
private void addChannel(string name) =>
channelTabControl.AddChannel(new Channel
2018-04-14 11:32:48 +00:00
{
2018-11-13 06:36:36 +00:00
Type = ChannelType.Public,
2018-04-14 11:32:48 +00:00
Name = name
});
2020-01-16 09:34:56 +00:00
private class TestTabControl : ChannelTabControl
{
public void SelectChannel(Channel channel) => base.SelectTab(TabMap[channel]);
}
2018-04-14 11:32:48 +00:00
}
}