1
0
mirror of https://github.com/ppy/osu.git synced 2024-11-16 10:17:36 +08:00
osu-lazer/osu.Game.Tests/Visual/Online/TestSceneWikiHeader.cs

106 lines
3.5 KiB
C#
Raw Normal View History

2021-04-19 17:24:47 +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.
2022-06-17 15:37:17 +08:00
#nullable disable
2021-05-20 15:24:28 +08:00
using System.Collections.Generic;
using System.Linq;
using NUnit.Framework;
2021-04-19 17:24:47 +08:00
using osu.Framework.Allocation;
2021-05-20 15:24:28 +08:00
using osu.Framework.Bindables;
2021-04-19 17:24:47 +08:00
using osu.Framework.Graphics;
2021-07-17 20:40:59 +08:00
using osu.Framework.Localisation;
2021-05-20 15:24:28 +08:00
using osu.Game.Online.API.Requests.Responses;
2021-04-19 17:24:47 +08:00
using osu.Game.Overlays;
using osu.Game.Overlays.Wiki;
namespace osu.Game.Tests.Visual.Online
{
2022-11-24 13:32:20 +08:00
public partial class TestSceneWikiHeader : OsuTestScene
2021-04-19 17:24:47 +08:00
{
[Cached]
private readonly OverlayColourProvider colourProvider = new OverlayColourProvider(OverlayColourScheme.Orange);
2021-05-20 15:24:28 +08:00
[Cached]
private readonly Bindable<APIWikiPage> wikiPageData = new Bindable<APIWikiPage>(new APIWikiPage
{
Title = "Main page",
2024-01-09 12:12:54 +08:00
Path = WikiOverlay.INDEX_PATH,
2021-05-20 15:24:28 +08:00
});
private TestHeader header;
[SetUp]
public void SetUp() => Schedule(() =>
2021-04-19 17:24:47 +08:00
{
2021-05-20 15:24:28 +08:00
Child = header = new TestHeader
2021-04-19 17:24:47 +08:00
{
Anchor = Anchor.Centre,
2021-05-20 15:24:28 +08:00
Origin = Anchor.Centre,
ShowIndexPage = dummyShowIndexPage,
ShowParentPage = dummyShowParentPage,
2021-04-19 17:24:47 +08:00
};
2021-05-20 15:24:28 +08:00
wikiPageData.BindTo(header.WikiPageData);
});
[Test]
public void TestWikiHeader()
{
AddAssert("Current is index", () => checkCurrent(WikiHeader.IndexPageString));
2021-05-20 15:24:28 +08:00
AddStep("Change wiki page data", () => wikiPageData.Value = new APIWikiPage
{
Title = "Welcome",
Path = "Welcome"
});
AddAssert("Current is welcome", () => checkCurrent("Welcome"));
AddAssert("Check breadcrumb", checkBreadcrumb);
AddStep("Change current to index", () => header.Current.Value = WikiHeader.IndexPageString);
AddAssert("Current is index", () => checkCurrent(WikiHeader.IndexPageString));
2021-05-20 15:24:28 +08:00
AddStep("Change wiki page data", () => wikiPageData.Value = new APIWikiPage
{
Title = "Developers",
Path = "People/The_Team/Developers",
Subtitle = "The Team",
});
AddAssert("Current is 'Developers'", () => checkCurrent("Developers"));
AddAssert("Check breadcrumb", checkBreadcrumb);
AddStep("Change current to 'The Team'", () => header.Current.Value = "The Team");
AddAssert("Current is 'The Team'", () => checkCurrent("The Team"));
AddAssert("Check breadcrumb", checkBreadcrumb);
}
private bool checkCurrent(LocalisableString expectedCurrent) => header.Current.Value == expectedCurrent;
2021-05-20 15:24:28 +08:00
private bool checkBreadcrumb()
{
bool result = header.TabControlItems.Contains(wikiPageData.Value.Title);
2021-05-20 15:24:28 +08:00
if (wikiPageData.Value.Subtitle != null)
result = header.TabControlItems.Contains(wikiPageData.Value.Subtitle) && result;
return result;
}
private void dummyShowIndexPage() => wikiPageData.SetDefault();
private void dummyShowParentPage()
{
wikiPageData.Value = new APIWikiPage
{
Path = "People/The_Team",
Title = "The Team",
Subtitle = "People"
};
}
2022-11-24 13:32:20 +08:00
private partial class TestHeader : WikiHeader
2021-05-20 15:24:28 +08:00
{
2021-07-17 20:40:59 +08:00
public IReadOnlyList<LocalisableString?> TabControlItems => TabControl.Items;
2021-04-19 17:24:47 +08:00
}
}
}