mirror of
https://github.com/ppy/osu.git
synced 2024-11-13 16:13:34 +08:00
Improve test coverage
This commit is contained in:
parent
3847aae57d
commit
e9f15534ed
@ -1,6 +1,7 @@
|
||||
// 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.Linq;
|
||||
using NUnit.Framework;
|
||||
using osu.Framework.Graphics;
|
||||
using osu.Framework.Graphics.Containers;
|
||||
@ -21,6 +22,8 @@ namespace osu.Game.Tests.Visual.Menus
|
||||
{
|
||||
Child = onlineMenuBanner = new OnlineMenuBanner
|
||||
{
|
||||
FetchOnlineContent = false,
|
||||
DelayBetweenRotation = 500,
|
||||
Anchor = Anchor.Centre,
|
||||
Origin = Anchor.Centre,
|
||||
State = { Value = Visibility.Visible }
|
||||
@ -43,6 +46,18 @@ namespace osu.Game.Tests.Visual.Menus
|
||||
},
|
||||
});
|
||||
|
||||
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";
|
||||
});
|
||||
|
||||
AddStep("set another title", () => onlineMenuBanner.Current.Value = new APIMenuContent
|
||||
{
|
||||
Images = new[]
|
||||
@ -55,6 +70,40 @@ namespace osu.Game.Tests.Visual.Menus
|
||||
}
|
||||
});
|
||||
|
||||
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",
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
AddUntilStep("wait for no image shown", () => !onlineMenuBanner.ChildrenOfType<OnlineMenuBanner.MenuImage>().Any());
|
||||
|
||||
AddStep("unset system title", () => onlineMenuBanner.Current.Value = new APIMenuContent());
|
||||
|
||||
AddUntilStep("wait for no image shown", () => !onlineMenuBanner.ChildrenOfType<OnlineMenuBanner.MenuImage>().Any());
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void TestMultipleImages()
|
||||
{
|
||||
AddStep("set multiple images", () => onlineMenuBanner.Current.Value = new APIMenuContent
|
||||
{
|
||||
Images = new[]
|
||||
@ -72,19 +121,25 @@ namespace osu.Game.Tests.Visual.Menus
|
||||
},
|
||||
});
|
||||
|
||||
AddStep("set title with nonexistent image", () => onlineMenuBanner.Current.Value = new APIMenuContent
|
||||
AddUntilStep("wait for first image shown", () =>
|
||||
{
|
||||
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",
|
||||
}
|
||||
}
|
||||
var images = onlineMenuBanner.ChildrenOfType<OnlineMenuBanner.MenuImage>();
|
||||
|
||||
if (images.Count() != 2)
|
||||
return false;
|
||||
|
||||
return images.First().IsPresent && !images.Last().IsPresent;
|
||||
});
|
||||
|
||||
AddStep("unset system title", () => onlineMenuBanner.Current.Value = new APIMenuContent());
|
||||
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;
|
||||
});
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -21,7 +21,9 @@ namespace osu.Game.Screens.Menu
|
||||
{
|
||||
public partial class OnlineMenuBanner : VisibilityContainer
|
||||
{
|
||||
public double DelayBetweenRotation = 7500;
|
||||
public double DelayBetweenRotation { get; set; } = 7500;
|
||||
|
||||
public bool FetchOnlineContent { get; set; } = true;
|
||||
|
||||
internal Bindable<APIMenuContent> Current { get; } = new Bindable<APIMenuContent>(new APIMenuContent());
|
||||
|
||||
@ -64,6 +66,9 @@ namespace osu.Game.Screens.Menu
|
||||
|
||||
private void checkForUpdates()
|
||||
{
|
||||
if (!FetchOnlineContent)
|
||||
return;
|
||||
|
||||
var request = new GetMenuContentRequest();
|
||||
Task.Run(() => request.Perform())
|
||||
.ContinueWith(r =>
|
||||
|
Loading…
Reference in New Issue
Block a user