1
0
mirror of https://github.com/ppy/osu.git synced 2024-11-14 10:57:30 +08:00
osu-lazer/osu.Game.Tests/Visual/Online/TestSceneWikiMarkdownContainer.cs

176 lines
5.7 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-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);
[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 = $"{API.WebsiteRootUrl}/wiki/Article_styling_criteria/");
2021-05-23 17:30:41 +08:00
AddStep("set '/wiki/Main_Page''", () => markdownContainer.Text = "[wiki main page](/wiki/Main_Page)");
2021-05-26 23:12: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-26 23:12: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-26 23:12: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-26 23:12: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", () =>
{
2021-05-26 20:20:39 +08:00
markdownContainer.DocumentUrl = "https://dev.ppy.sh";
2021-05-23 17:30:41 +08:00
markdownContainer.Text = "![intro](/wiki/Interface/img/intro-screen.jpg)";
});
}
[Test]
public void TestRelativeImage()
{
AddStep("Add relative image", () =>
{
2021-05-26 20:20:39 +08:00
markdownContainer.DocumentUrl = "https://dev.ppy.sh";
markdownContainer.CurrentPath = $"{API.WebsiteRootUrl}/wiki/Interface/";
2021-05-23 17:30:41 +08:00
markdownContainer.Text = "![intro](img/intro-screen.jpg)";
});
}
[Test]
public void TestBlockImage()
{
AddStep("Add paragraph with block image", () =>
{
2021-05-26 20:20:39 +08:00
markdownContainer.DocumentUrl = "https://dev.ppy.sh";
markdownContainer.CurrentPath = $"{API.WebsiteRootUrl}/wiki/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", () =>
{
2021-05-26 20:20:39 +08:00
markdownContainer.DocumentUrl = "https://dev.ppy.sh";
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;
2021-05-26 16:04:04 +08:00
public new string DocumentUrl
{
set => base.DocumentUrl = value;
}
2021-05-25 10:56:26 +08:00
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-26 16:04:04 +08:00
protected override void AddImage(LinkInline linkInline) => AddDrawable(new WikiMarkdownImage(linkInline));
2021-05-25 10:56:26 +08:00
}
}
2021-05-23 17:30:41 +08:00
}
}