mirror of https://github.com/ppy/osu
Fix `displayIndex` not being correctly set to `-1` after last expiry date
This commit is contained in:
parent
057f86dd14
commit
bb9fa52fda
|
@ -144,7 +144,41 @@ public void TestMultipleImages()
|
||||||
}
|
}
|
||||||
|
|
||||||
[Test]
|
[Test]
|
||||||
public void TestExpiry()
|
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()
|
||||||
{
|
{
|
||||||
AddStep("set multiple images, second expiring soon", () => onlineMenuBanner.Current.Value = new APIMenuContent
|
AddStep("set multiple images, second expiring soon", () => onlineMenuBanner.Current.Value = new APIMenuContent
|
||||||
{
|
{
|
||||||
|
|
|
@ -127,14 +127,15 @@ private void showNext()
|
||||||
{
|
{
|
||||||
int previousIndex = displayIndex;
|
int previousIndex = displayIndex;
|
||||||
|
|
||||||
if (displayIndex == -1)
|
|
||||||
displayIndex = 0;
|
|
||||||
|
|
||||||
// To handle expiration simply, arrange all images in best-next order.
|
// To handle expiration simply, arrange all images in best-next order.
|
||||||
// Fade in the first valid one, then handle fading out the last if required.
|
// Fade in the first valid one, then handle fading out the last if required.
|
||||||
var currentRotation = content
|
var currentRotation = content
|
||||||
.Skip(displayIndex + 1)
|
.Skip(Math.Max(0, previousIndex) + 1)
|
||||||
.Concat(content.Take(displayIndex + 1));
|
.Concat(content.Take(Math.Max(0, previousIndex) + 1));
|
||||||
|
|
||||||
|
// After the loop, displayIndex will be the new valid index or -1 if
|
||||||
|
// none valid.
|
||||||
|
displayIndex = -1;
|
||||||
|
|
||||||
foreach (var image in currentRotation)
|
foreach (var image in currentRotation)
|
||||||
{
|
{
|
||||||
|
|
Loading…
Reference in New Issue