1
0
mirror of https://github.com/ppy/osu.git synced 2025-01-28 05:22:54 +08:00

Fix incorrect no posts handling and add corresponding test

This commit is contained in:
Andrei Zavatski 2021-05-11 20:52:11 +03:00
parent 822d99e69f
commit b0297c6324
2 changed files with 28 additions and 2 deletions

View File

@ -24,13 +24,20 @@ namespace osu.Game.Tests.Visual.Online
public void SetUp() => Schedule(() => Child = sidebar = new NewsSideBar());
[Test]
public void TestMetadataChange()
public void TestYearsPanelVisibility()
{
AddUntilStep("Years panel is hidden", () => yearsPanel?.Alpha == 0);
AddStep("Add data", () => sidebar.Metadata.Value = metadata);
AddUntilStep("Years panel is visible", () => yearsPanel?.Alpha == 1);
}
[Test]
public void TestMetadataWithNoPosts()
{
AddStep("Add data with no posts", () => sidebar.Metadata.Value = metadata_with_no_posts);
AddUntilStep("No dropdowns were created", () => !sidebar.ChildrenOfType<MonthDropdown>().Any());
}
private YearsPanel yearsPanel => sidebar.ChildrenOfType<YearsPanel>().FirstOrDefault();
private static readonly APINewsSidebar metadata = new APINewsSidebar
@ -97,5 +104,24 @@ namespace osu.Game.Tests.Visual.Online
}
}
};
private static readonly APINewsSidebar metadata_with_no_posts = new APINewsSidebar
{
CurrentYear = 2022,
Years = new[]
{
2022,
2021,
2020,
2019,
2018,
2017,
2016,
2015,
2014,
2013
},
NewsPosts = Array.Empty<APINewsPost>()
};
}
}

View File

@ -78,7 +78,7 @@ namespace osu.Game.Overlays.News.Sidebar
var allPosts = metadata.NewValue.NewsPosts;
if (!allPosts?.Any() ?? false)
if (!allPosts?.Any() ?? true)
return;
var lookup = metadata.NewValue.NewsPosts.ToLookup(post => post.PublishedAt.Month);