2018-04-14 19:32:48 +08:00
// Copyright (c) 2007-2018 ppy Pty Ltd <contact@ppy.sh>.
// Licensed under the MIT Licence - https://raw.githubusercontent.com/ppy/osu/master/LICENCE
using System ;
using System.Collections.Generic ;
2018-06-01 04:56:12 +08:00
using System.Linq ;
using osu.Framework.Allocation ;
2018-04-14 19:32:48 +08:00
using osu.Framework.Extensions.Color4Extensions ;
using osu.Framework.Graphics ;
using osu.Framework.Graphics.Containers ;
using osu.Framework.Graphics.Shapes ;
using osu.Framework.Graphics.Sprites ;
using osu.Framework.MathUtils ;
2018-06-01 04:56:12 +08:00
using osu.Game.Online.API ;
using osu.Game.Online.API.Requests ;
2018-04-14 19:32:48 +08:00
using osu.Game.Online.Chat ;
2018-07-10 04:09:27 +08:00
using osu.Game.Overlays.Chat.Tabs ;
2018-04-14 19:32:48 +08:00
using osu.Game.Users ;
using OpenTK.Graphics ;
namespace osu.Game.Tests.Visual
{
2018-07-30 03:18:37 +08:00
public class TestCaseChannelTabControl : OsuTestCase
2018-04-14 19:32:48 +08:00
{
public override IReadOnlyList < Type > RequiredTypes = > new [ ]
{
2018-07-30 03:18:37 +08:00
typeof ( ChannelTabControl ) ,
2018-04-14 19:32:48 +08:00
} ;
2018-07-30 03:18:37 +08:00
private readonly ChannelTabControl channelTabControl ;
2018-04-14 19:32:48 +08:00
2018-07-30 03:18:37 +08:00
public TestCaseChannelTabControl ( )
2018-04-14 19:32:48 +08:00
{
SpriteText currentText ;
Add ( new Container
{
RelativeSizeAxes = Axes . X ,
Origin = Anchor . Centre ,
Anchor = Anchor . Centre ,
Children = new Drawable [ ]
{
2018-07-30 03:18:37 +08:00
channelTabControl = new ChannelTabControl
2018-04-14 19:32:48 +08: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 SpriteText
{
2018-07-30 03:18:37 +08:00
Text = "Currently selected channel:"
2018-04-14 19:32:48 +08:00
}
}
} ) ;
2018-07-30 03:18:37 +08:00
channelTabControl . OnRequestLeave + = channel = > channelTabControl . RemoveChannel ( channel ) ;
channelTabControl . Current . ValueChanged + = channel = > currentText . Text = "Currently selected channel: " + channel . ToString ( ) ;
2018-04-14 19:32:48 +08:00
2018-07-30 06:13:32 +08:00
AddStep ( "Add random private channel" , addRandomUser ) ;
AddAssert ( "There is only one channels" , ( ) = > channelTabControl . Items . Count ( ) = = 2 ) ;
AddRepeatStep ( "Add 3 random private channels" , addRandomUser , 3 ) ;
AddAssert ( "There are four channels" , ( ) = > channelTabControl . Items . Count ( ) = = 5 ) ;
AddStep ( "Add random public channel" , ( ) = > addChannel ( RNG . Next ( ) . ToString ( ) ) ) ;
2018-08-04 07:00:46 +08:00
AddRepeatStep ( "Select a random channel" , ( ) = > channelTabControl . Current . Value = channelTabControl . Items . ElementAt ( RNG . Next ( channelTabControl . Items . Count ( ) ) ) , 20 ) ;
2018-04-14 19:32:48 +08:00
}
2018-06-01 04:56:12 +08:00
private List < User > users ;
private void addRandomUser ( )
2018-04-14 19:32:48 +08:00
{
2018-11-13 14:20:40 +08:00
channelTabControl . AddChannel ( new Channel
2018-08-04 07:00:46 +08:00
{
2018-11-13 14:20:40 +08:00
Users =
{
users ? . Count > 0
2018-08-04 07:00:46 +08:00
? users [ RNG . Next ( 0 , users . Count - 1 ) ]
: new User
{
Id = RNG . Next ( ) ,
Username = "testuser" + RNG . Next ( 1000 )
}
2018-11-13 14:20:40 +08:00
}
2018-08-04 07:00:46 +08:00
} ) ;
2018-04-14 19:32:48 +08:00
}
private void addChannel ( string name )
{
2018-07-30 03:18:37 +08:00
channelTabControl . AddChannel ( new Channel
2018-04-14 19:32:48 +08:00
{
2018-11-13 14:36:36 +08:00
Type = ChannelType . Public ,
2018-04-14 19:32:48 +08:00
Name = name
} ) ;
}
2018-06-01 04:56:12 +08:00
[BackgroundDependencyLoader]
private void load ( IAPIProvider api )
{
GetUsersRequest req = new GetUsersRequest ( ) ;
req . Success + = list = > users = list . Select ( e = > e . User ) . ToList ( ) ;
api . Queue ( req ) ;
}
2018-04-14 19:32:48 +08:00
}
}