osu/osu.Game.Tests/Visual/Online/TestSceneNewsOverlay.cs

Ignoring revisions in .git-blame-ignore-revs. Click here to bypass and see the normal blame view.

117 lines
4.5 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.
2022-06-17 07:37:17 +00:00
#nullable disable
2020-07-12 13:13:48 +00:00
using System;
2021-05-09 01:49:40 +00:00
using System.Linq;
2020-07-12 13:13:48 +00:00
using NUnit.Framework;
2021-05-09 01:49:40 +00:00
using osu.Framework.Testing;
using osu.Game.Graphics.UserInterface;
2020-07-12 13:13:48 +00:00
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 10:26:54 +00:00
namespace osu.Game.Tests.Visual.Online
{
public partial class TestSceneNewsOverlay : OsuTestScene
{
2020-07-12 13:13:48 +00:00
private DummyAPIAccess dummyAPI => (DummyAPIAccess)API;
2020-07-08 17:07:29 +00:00
2021-05-09 01:49:40 +00:00
private NewsOverlay overlay;
2020-07-12 13:13:48 +00:00
[SetUp]
2021-05-09 01:49:40 +00:00
public void SetUp() => Schedule(() => Child = overlay = new NewsOverlay());
2020-07-12 13:13:48 +00:00
[Test]
public void TestRequest()
2019-08-10 10:26:54 +00:00
{
2020-07-12 13:13:48 +00:00
setUpNewsResponse(responseExample);
2021-05-09 01:49:40 +00:00
AddStep("Show", () => overlay.Show());
AddStep("Show article", () => overlay.ShowArticle("article"));
2020-07-12 13:13:48 +00:00
}
2021-05-09 01:49:40 +00:00
[Test]
public void TestCursorRequest()
{
setUpNewsResponse(responseWithCursor, "Set up cursor response");
AddStep("Show", () => overlay.Show());
AddUntilStep("Show More button is visible", () => showMoreButton?.Alpha == 1);
2021-05-09 01:49:40 +00:00
setUpNewsResponse(responseWithNoCursor, "Set up no cursor response");
2021-08-04 08:27:44 +00:00
AddStep("Click Show More", () => showMoreButton?.TriggerClick());
AddUntilStep("Show More button is hidden", () => showMoreButton?.Alpha == 0);
2021-05-09 01:49:40 +00:00
}
2021-05-09 06:12:37 +00:00
private ShowMoreButton showMoreButton => overlay.ChildrenOfType<ShowMoreButton>().FirstOrDefault();
2021-05-09 01:49:40 +00:00
private void setUpNewsResponse(GetNewsResponse r, string testName = "Set up response")
=> AddStep(testName, () =>
2020-07-12 13:13:48 +00:00
{
dummyAPI.HandleRequest = request =>
{
if (!(request is GetNewsRequest getNewsRequest))
return false;
2019-08-10 15:06:52 +00:00
2020-07-12 13:13:48 +00:00
getNewsRequest.TriggerSuccess(r);
return true;
2020-07-12 13:13:48 +00:00
};
});
2021-05-09 01:49:40 +00:00
private static GetNewsResponse responseExample => new GetNewsResponse
2020-07-12 13:13:48 +00:00
{
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
}
}
};
2021-05-09 01:49:40 +00:00
private static GetNewsResponse responseWithCursor => 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
}
},
Cursor = new Cursor()
};
private static GetNewsResponse responseWithNoCursor => new GetNewsResponse
{
NewsPosts = new[]
{
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
}
},
Cursor = null
};
2019-08-10 10:26:54 +00:00
}
}