2024-03-23 20:07:17 +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.
2024-03-25 14:28:23 +08:00
using System ;
2024-03-25 12:14:47 +08:00
using System.Linq ;
2024-03-23 20:07:17 +08:00
using NUnit.Framework ;
using osu.Framework.Graphics ;
using osu.Framework.Graphics.Containers ;
using osu.Framework.Testing ;
using osu.Game.Online.API.Requests.Responses ;
using osu.Game.Screens.Menu ;
2024-03-26 20:44:12 +08:00
using osuTK ;
2024-03-23 20:07:17 +08:00
namespace osu.Game.Tests.Visual.Menus
{
public partial class TestSceneOnlineMenuBanner : OsuTestScene
{
private OnlineMenuBanner onlineMenuBanner = null ! ;
[SetUpSteps]
public void SetUpSteps ( )
{
AddStep ( "Create banner" , ( ) = >
{
Child = onlineMenuBanner = new OnlineMenuBanner
{
2024-03-25 12:14:47 +08:00
FetchOnlineContent = false ,
DelayBetweenRotation = 500 ,
2024-03-23 20:07:17 +08:00
Anchor = Anchor . Centre ,
Origin = Anchor . Centre ,
State = { Value = Visibility . Visible }
} ;
} ) ;
}
[Test]
public void TestBasic ( )
{
AddStep ( "set online content" , ( ) = > onlineMenuBanner . Current . Value = new APIMenuContent
{
Images = new [ ]
{
new APIMenuImage
{
Image = @"https://assets.ppy.sh/main-menu/project-loved-2@2x.png" ,
Url = @"https://osu.ppy.sh/home/news/2023-12-21-project-loved-december-2023" ,
}
} ,
} ) ;
2024-03-24 15:14:56 +08:00
2024-03-25 12:14:47 +08:00
AddUntilStep ( "wait for one image shown" , ( ) = >
{
var images = onlineMenuBanner . ChildrenOfType < OnlineMenuBanner . MenuImage > ( ) ;
if ( images . Count ( ) ! = 1 )
return false ;
var image = images . Single ( ) ;
return image . IsPresent & & image . Image . Url = = "https://osu.ppy.sh/home/news/2023-12-21-project-loved-december-2023" ;
} ) ;
2024-03-23 20:07:17 +08:00
AddStep ( "set another title" , ( ) = > onlineMenuBanner . Current . Value = new APIMenuContent
{
Images = new [ ]
{
new APIMenuImage
{
Image = @"https://assets.ppy.sh/main-menu/wf2023-vote@2x.png" ,
Url = @"https://osu.ppy.sh/community/contests/189" ,
}
}
} ) ;
2024-03-24 15:14:56 +08:00
2024-03-25 12:14:47 +08:00
AddUntilStep ( "wait for new image shown" , ( ) = >
{
var images = onlineMenuBanner . ChildrenOfType < OnlineMenuBanner . MenuImage > ( ) ;
if ( images . Count ( ) ! = 1 )
return false ;
var image = images . Single ( ) ;
return image . IsPresent & & image . Image . Url = = "https://osu.ppy.sh/community/contests/189" ;
} ) ;
AddStep ( "set title with nonexistent image" , ( ) = > onlineMenuBanner . Current . Value = new APIMenuContent
{
Images = new [ ]
{
new APIMenuImage
{
Image = @"https://test.invalid/@2x" , // .invalid TLD reserved by https://datatracker.ietf.org/doc/html/rfc2606#section-2
Url = @"https://osu.ppy.sh/community/contests/189" ,
}
}
} ) ;
2024-03-26 21:20:22 +08:00
AddUntilStep ( "wait for no image shown" , ( ) = > onlineMenuBanner . ChildrenOfType < OnlineMenuBanner . MenuImage > ( ) . SingleOrDefault ( ) ? . Size , ( ) = > Is . EqualTo ( Vector2 . Zero ) ) ;
2024-03-25 12:14:47 +08:00
AddStep ( "unset system title" , ( ) = > onlineMenuBanner . Current . Value = new APIMenuContent ( ) ) ;
AddUntilStep ( "wait for no image shown" , ( ) = > ! onlineMenuBanner . ChildrenOfType < OnlineMenuBanner . MenuImage > ( ) . Any ( ) ) ;
}
[Test]
public void TestMultipleImages ( )
{
2024-03-24 15:14:56 +08:00
AddStep ( "set multiple images" , ( ) = > onlineMenuBanner . Current . Value = new APIMenuContent
{
Images = new [ ]
{
new APIMenuImage
{
Image = @"https://assets.ppy.sh/main-menu/project-loved-2@2x.png" ,
Url = @"https://osu.ppy.sh/home/news/2023-12-21-project-loved-december-2023" ,
} ,
new APIMenuImage
{
Image = @"https://assets.ppy.sh/main-menu/wf2023-vote@2x.png" ,
Url = @"https://osu.ppy.sh/community/contests/189" ,
}
} ,
} ) ;
2024-03-25 12:14:47 +08:00
AddUntilStep ( "wait for first image shown" , ( ) = >
2024-03-23 20:07:17 +08:00
{
2024-03-25 12:14:47 +08:00
var images = onlineMenuBanner . ChildrenOfType < OnlineMenuBanner . MenuImage > ( ) ;
if ( images . Count ( ) ! = 2 )
return false ;
return images . First ( ) . IsPresent & & ! images . Last ( ) . IsPresent ;
2024-03-23 20:07:17 +08:00
} ) ;
2024-03-24 15:14:56 +08:00
2024-03-25 12:14:47 +08:00
AddUntilStep ( "wait for second image shown" , ( ) = >
{
var images = onlineMenuBanner . ChildrenOfType < OnlineMenuBanner . MenuImage > ( ) ;
if ( images . Count ( ) ! = 2 )
return false ;
return ! images . First ( ) . IsPresent & & images . Last ( ) . IsPresent ;
} ) ;
2024-03-23 20:07:17 +08:00
}
2024-03-25 14:28:23 +08:00
[Test]
2024-03-25 14:53:05 +08:00
public void TestFutureSingle ( )
{
AddStep ( "set image with time constraints" , ( ) = > onlineMenuBanner . Current . Value = new APIMenuContent
{
Images = new [ ]
{
new APIMenuImage
{
Image = @"https://assets.ppy.sh/main-menu/project-loved-2@2x.png" ,
Url = @"https://osu.ppy.sh/home/news/2023-12-21-project-loved-december-2023" ,
Begins = DateTimeOffset . Now . AddSeconds ( 2 ) ,
Expires = DateTimeOffset . Now . AddSeconds ( 5 ) ,
} ,
} ,
} ) ;
AddUntilStep ( "wait for no image shown" , ( ) = > ! onlineMenuBanner . ChildrenOfType < OnlineMenuBanner . MenuImage > ( ) . Any ( i = > i . IsPresent ) ) ;
AddUntilStep ( "wait for one image shown" , ( ) = >
{
var images = onlineMenuBanner . ChildrenOfType < OnlineMenuBanner . MenuImage > ( ) ;
if ( images . Count ( ) ! = 1 )
return false ;
var image = images . Single ( ) ;
return image . IsPresent & & image . Image . Url = = "https://osu.ppy.sh/home/news/2023-12-21-project-loved-december-2023" ;
} ) ;
AddUntilStep ( "wait for no image shown" , ( ) = > ! onlineMenuBanner . ChildrenOfType < OnlineMenuBanner . MenuImage > ( ) . Any ( i = > i . IsPresent ) ) ;
}
[Test]
public void TestExpiryMultiple ( )
2024-03-25 14:28:23 +08:00
{
AddStep ( "set multiple images, second expiring soon" , ( ) = > onlineMenuBanner . Current . Value = new APIMenuContent
{
Images = new [ ]
{
new APIMenuImage
{
Image = @"https://assets.ppy.sh/main-menu/project-loved-2@2x.png" ,
Url = @"https://osu.ppy.sh/home/news/2023-12-21-project-loved-december-2023" ,
} ,
new APIMenuImage
{
Image = @"https://assets.ppy.sh/main-menu/wf2023-vote@2x.png" ,
Url = @"https://osu.ppy.sh/community/contests/189" ,
Expires = DateTimeOffset . Now . AddSeconds ( 2 ) ,
}
} ,
} ) ;
AddUntilStep ( "wait for first image shown" , ( ) = >
{
var images = onlineMenuBanner . ChildrenOfType < OnlineMenuBanner . MenuImage > ( ) ;
if ( images . Count ( ) ! = 2 )
return false ;
return images . First ( ) . IsPresent & & ! images . Last ( ) . IsPresent ;
} ) ;
AddUntilStep ( "wait for second image shown" , ( ) = >
{
var images = onlineMenuBanner . ChildrenOfType < OnlineMenuBanner . MenuImage > ( ) ;
if ( images . Count ( ) ! = 2 )
return false ;
return ! images . First ( ) . IsPresent & & images . Last ( ) . IsPresent ;
} ) ;
AddUntilStep ( "wait for expiry" , ( ) = >
{
return onlineMenuBanner
. ChildrenOfType < OnlineMenuBanner . MenuImage > ( )
. Any ( i = > ! i . Image . IsCurrent ) ;
} ) ;
AddUntilStep ( "wait for first image shown" , ( ) = >
{
var images = onlineMenuBanner . ChildrenOfType < OnlineMenuBanner . MenuImage > ( ) ;
if ( images . Count ( ) ! = 2 )
return false ;
return images . First ( ) . IsPresent & & ! images . Last ( ) . IsPresent ;
} ) ;
}
2024-03-23 20:07:17 +08:00
}
}