1
0
mirror of https://github.com/ppy/osu.git synced 2024-12-16 07:42:54 +08:00
osu-lazer/osu.Game.Tests/Visual/Online/TestSceneNewsOverlay.cs

66 lines
2.3 KiB
C#
Raw Normal View History

// 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.
2020-07-12 21:13:48 +08:00
using System;
using NUnit.Framework;
using osu.Game.Online.API;
using osu.Game.Online.API.Requests;
using osu.Game.Online.API.Requests.Responses;
using osu.Game.Overlays;
2019-08-10 18:26:54 +08:00
namespace osu.Game.Tests.Visual.Online
{
public class TestSceneNewsOverlay : OsuTestScene
{
2020-07-12 21:13:48 +08:00
private DummyAPIAccess dummyAPI => (DummyAPIAccess)API;
2020-07-09 01:07:29 +08:00
2020-07-12 21:13:48 +08:00
private NewsOverlay news;
[SetUp]
public void SetUp() => Schedule(() => Child = news = new NewsOverlay());
[Test]
public void TestRequest()
2019-08-10 18:26:54 +08:00
{
2020-07-12 21:13:48 +08:00
setUpNewsResponse(responseExample);
AddStep("Show", () => news.Show());
AddStep("Show article", () => news.ShowArticle("article"));
}
2020-07-12 21:13:48 +08:00
private void setUpNewsResponse(GetNewsResponse r)
=> AddStep("set up response", () =>
{
dummyAPI.HandleRequest = request =>
{
if (!(request is GetNewsRequest getNewsRequest))
return;
2019-08-10 23:06:52 +08:00
2020-07-12 21:13:48 +08:00
getNewsRequest.TriggerSuccess(r);
};
});
2020-07-12 21:13:48 +08:00
private GetNewsResponse responseExample => new GetNewsResponse
{
NewsPosts = new[]
{
new APINewsPost
{
Title = "This post has an image which starts with \"/\" and has many authors!",
Preview = "Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua.",
Author = "someone, someone1, someone2, someone3, someone4",
FirstImage = "/help/wiki/shared/news/banners/monthly-beatmapping-contest.png",
PublishedAt = DateTimeOffset.Now
},
new APINewsPost
{
Title = "This post has a full-url image! (HTML entity: &amp;)",
Preview = "boom (HTML entity: &amp;)",
Author = "user (HTML entity: &amp;)",
FirstImage = "https://assets.ppy.sh/artists/88/header.jpg",
PublishedAt = DateTimeOffset.Now
}
}
};
2019-08-10 18:26:54 +08:00
}
}