mirror of
https://github.com/ppy/osu.git
synced 2024-12-14 05:32:54 +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.
|
// 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.
|
// See the LICENCE file in the repository root for full licence text.
|
||||||
|
|
||||||
|
using System.Linq;
|
||||||
using NUnit.Framework;
|
using NUnit.Framework;
|
||||||
using osu.Framework.Graphics;
|
using osu.Framework.Graphics;
|
||||||
using osu.Framework.Graphics.Containers;
|
using osu.Framework.Graphics.Containers;
|
||||||
@ -21,6 +22,8 @@ namespace osu.Game.Tests.Visual.Menus
|
|||||||
{
|
{
|
||||||
Child = onlineMenuBanner = new OnlineMenuBanner
|
Child = onlineMenuBanner = new OnlineMenuBanner
|
||||||
{
|
{
|
||||||
|
FetchOnlineContent = false,
|
||||||
|
DelayBetweenRotation = 500,
|
||||||
Anchor = Anchor.Centre,
|
Anchor = Anchor.Centre,
|
||||||
Origin = Anchor.Centre,
|
Origin = Anchor.Centre,
|
||||||
State = { Value = Visibility.Visible }
|
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
|
AddStep("set another title", () => onlineMenuBanner.Current.Value = new APIMenuContent
|
||||||
{
|
{
|
||||||
Images = new[]
|
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
|
AddStep("set multiple images", () => onlineMenuBanner.Current.Value = new APIMenuContent
|
||||||
{
|
{
|
||||||
Images = new[]
|
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[]
|
var images = onlineMenuBanner.ChildrenOfType<OnlineMenuBanner.MenuImage>();
|
||||||
{
|
|
||||||
new APIMenuImage
|
if (images.Count() != 2)
|
||||||
{
|
return false;
|
||||||
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",
|
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 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());
|
internal Bindable<APIMenuContent> Current { get; } = new Bindable<APIMenuContent>(new APIMenuContent());
|
||||||
|
|
||||||
@ -64,6 +66,9 @@ namespace osu.Game.Screens.Menu
|
|||||||
|
|
||||||
private void checkForUpdates()
|
private void checkForUpdates()
|
||||||
{
|
{
|
||||||
|
if (!FetchOnlineContent)
|
||||||
|
return;
|
||||||
|
|
||||||
var request = new GetMenuContentRequest();
|
var request = new GetMenuContentRequest();
|
||||||
Task.Run(() => request.Perform())
|
Task.Run(() => request.Perform())
|
||||||
.ContinueWith(r =>
|
.ContinueWith(r =>
|
||||||
|
Loading…
Reference in New Issue
Block a user