1
0
mirror of https://github.com/ppy/osu.git synced 2024-09-22 03:27:24 +08:00
osu-lazer/osu.Game.Tests/Visual/Online/TestSceneWikiMarkdownContainer.cs

169 lines
5.2 KiB
C#
Raw Normal View History

2021-05-23 17:30:41 +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.
2021-05-25 10:56:26 +08:00
using System;
using Markdig.Syntax.Inlines;
2021-05-23 17:30:41 +08:00
using NUnit.Framework;
using osu.Framework.Allocation;
using osu.Framework.Graphics;
using osu.Framework.Graphics.Containers;
2021-05-25 10:56:26 +08:00
using osu.Framework.Graphics.Containers.Markdown;
2021-05-23 17:30:41 +08:00
using osu.Framework.Graphics.Shapes;
2021-05-25 10:56:26 +08:00
using osu.Game.Graphics.Containers.Markdown;
2021-05-25 11:44:22 +08:00
using osu.Game.Online.API;
2021-05-23 17:30:41 +08:00
using osu.Game.Overlays;
using osu.Game.Overlays.Wiki.Markdown;
namespace osu.Game.Tests.Visual.Online
{
public class TestSceneWikiMarkdownContainer : OsuTestScene
{
2021-05-25 10:56:26 +08:00
private TestMarkdownContainer markdownContainer;
2021-05-23 17:30:41 +08:00
[Cached]
private readonly OverlayColourProvider overlayColour = new OverlayColourProvider(OverlayColourScheme.Orange);
2021-05-25 11:44:22 +08:00
[Cached]
private readonly IAPIProvider api = new DummyAPIAccess();
2021-05-23 17:30:41 +08:00
[SetUp]
public void Setup() => Schedule(() =>
{
Children = new Drawable[]
{
new Box
{
Colour = overlayColour.Background5,
RelativeSizeAxes = Axes.Both,
},
new BasicScrollContainer
{
RelativeSizeAxes = Axes.Both,
Padding = new MarginPadding(20),
2021-05-25 10:56:26 +08:00
Child = markdownContainer = new TestMarkdownContainer
2021-05-23 17:30:41 +08:00
{
RelativeSizeAxes = Axes.X,
AutoSizeAxes = Axes.Y,
}
}
};
});
[Test]
public void TestLink()
{
AddStep("set current path", () => markdownContainer.CurrentPath = "Article_styling_criteria/");
AddStep("set '/wiki/Main_Page''", () => markdownContainer.Text = "[wiki main page](/wiki/Main_Page)");
2021-05-25 11:44:22 +08:00
AddAssert("check url", () => markdownContainer.Link.Url == $"{api.WebsiteRootUrl}/wiki/Main_Page");
2021-05-23 17:30:41 +08:00
AddStep("set '../FAQ''", () => markdownContainer.Text = "[FAQ](../FAQ)");
2021-05-25 11:44:22 +08:00
AddAssert("check url", () => markdownContainer.Link.Url == $"{api.WebsiteRootUrl}/wiki/FAQ");
2021-05-23 17:30:41 +08:00
AddStep("set './Writing''", () => markdownContainer.Text = "[wiki writing guidline](./Writing)");
2021-05-25 11:44:22 +08:00
AddAssert("check url", () => markdownContainer.Link.Url == $"{api.WebsiteRootUrl}/wiki/Article_styling_criteria/Writing");
2021-05-23 17:30:41 +08:00
AddStep("set 'Formatting''", () => markdownContainer.Text = "[wiki formatting guidline](Formatting)");
2021-05-25 11:44:22 +08:00
AddAssert("check url", () => markdownContainer.Link.Url == $"{api.WebsiteRootUrl}/wiki/Article_styling_criteria/Formatting");
2021-05-23 17:30:41 +08:00
}
2021-05-25 10:56:26 +08:00
2021-05-23 18:29:48 +08:00
[Test]
public void TestOutdatedNoticeBox()
{
AddStep("Add outdated yaml header", () =>
{
markdownContainer.Text = @"---
outdated: true
---";
});
}
[Test]
public void TestNeedsCleanupNoticeBox()
{
AddStep("Add needs cleanup yaml header", () =>
{
markdownContainer.Text = @"---
needs_cleanup: true
---";
});
}
[Test]
public void TestOnlyShowOutdatedNoticeBox()
{
AddStep("Add outdated and needs cleanup yaml", () =>
{
markdownContainer.Text = @"---
outdated: true
needs_cleanup: true
---";
});
}
2021-05-23 17:30:41 +08:00
[Test]
public void TestAbsoluteImage()
{
AddStep("Add absolute image", () =>
{
markdownContainer.Text = "![intro](/wiki/Interface/img/intro-screen.jpg)";
});
}
[Test]
public void TestRelativeImage()
{
AddStep("Add relative image", () =>
{
markdownContainer.CurrentPath = "Interface/";
markdownContainer.Text = "![intro](img/intro-screen.jpg)";
});
}
[Test]
public void TestBlockImage()
{
AddStep("Add paragraph with block image", () =>
{
markdownContainer.CurrentPath = "Interface/";
markdownContainer.Text = @"Line before image
![play menu](img/play-menu.jpg ""Main Menu in osu!"")
Line after image";
});
}
[Test]
public void TestInlineImage()
{
AddStep("Add inline image", () =>
{
markdownContainer.Text = "![osu! mode icon](/wiki/shared/mode/osu.png) osu!";
});
}
2021-05-25 10:56:26 +08:00
private class TestMarkdownContainer : WikiMarkdownContainer
{
public LinkInline Link;
public override MarkdownTextFlowContainer CreateTextFlow() => new TestMarkdownTextFlowContainer
{
UrlAdded = link => Link = link,
};
private class TestMarkdownTextFlowContainer : OsuMarkdownTextFlowContainer
{
public Action<LinkInline> UrlAdded;
protected override void AddLinkText(string text, LinkInline linkInline)
{
base.AddLinkText(text, linkInline);
UrlAdded?.Invoke(linkInline);
}
}
}
2021-05-23 17:30:41 +08:00
}
}