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

115 lines
4.4 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;
2021-05-09 09:49:40 +08:00
using System.Linq;
2020-07-12 21:13:48 +08:00
using NUnit.Framework;
2021-05-09 09:49:40 +08:00
using osu.Framework.Testing;
using osu.Game.Graphics.UserInterface;
2020-07-12 21:13:48 +08: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 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
2021-05-09 09:49:40 +08:00
private NewsOverlay overlay;
2020-07-12 21:13:48 +08:00
[SetUp]
2021-05-09 09:49:40 +08:00
public void SetUp() => Schedule(() => Child = overlay = new NewsOverlay());
2020-07-12 21:13:48 +08:00
[Test]
public void TestRequest()
2019-08-10 18:26:54 +08:00
{
2020-07-12 21:13:48 +08:00
setUpNewsResponse(responseExample);
2021-05-09 09:49:40 +08:00
AddStep("Show", () => overlay.Show());
AddStep("Show article", () => overlay.ShowArticle("article"));
2020-07-12 21:13:48 +08:00
}
2021-05-09 09:49:40 +08: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 09:49:40 +08:00
setUpNewsResponse(responseWithNoCursor, "Set up no cursor response");
2021-08-04 16:27:44 +08:00
AddStep("Click Show More", () => showMoreButton?.TriggerClick());
AddUntilStep("Show More button is hidden", () => showMoreButton?.Alpha == 0);
2021-05-09 09:49:40 +08:00
}
2021-05-09 14:12:37 +08:00
private ShowMoreButton showMoreButton => overlay.ChildrenOfType<ShowMoreButton>().FirstOrDefault();
2021-05-09 09:49:40 +08:00
private void setUpNewsResponse(GetNewsResponse r, string testName = "Set up response")
=> AddStep(testName, () =>
2020-07-12 21:13:48 +08:00
{
dummyAPI.HandleRequest = request =>
{
if (!(request is GetNewsRequest getNewsRequest))
return false;
2019-08-10 23:06:52 +08:00
2020-07-12 21:13:48 +08:00
getNewsRequest.TriggerSuccess(r);
return true;
2020-07-12 21:13:48 +08:00
};
});
2021-05-09 09:49:40 +08:00
private static GetNewsResponse responseExample => new GetNewsResponse
2020-07-12 21:13:48 +08: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 09:49:40 +08: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 18:26:54 +08:00
}
}