2019-05-12 15:36:05 +00: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.
|
|
|
|
|
|
2020-12-25 18:28:33 +00:00
|
|
|
|
using System;
|
2019-05-17 01:29:43 +00:00
|
|
|
|
using System.Collections.Generic;
|
2020-12-25 18:28:33 +00:00
|
|
|
|
using System.Linq;
|
|
|
|
|
using Humanizer;
|
2018-07-16 21:50:22 +00:00
|
|
|
|
using NUnit.Framework;
|
2020-12-25 18:28:33 +00:00
|
|
|
|
using osu.Game.Online.API;
|
|
|
|
|
using osu.Game.Online.API.Requests;
|
2018-07-25 12:31:41 +00:00
|
|
|
|
using osu.Game.Online.API.Requests.Responses;
|
2018-07-16 21:50:22 +00:00
|
|
|
|
using osu.Game.Overlays;
|
2019-05-17 01:29:43 +00:00
|
|
|
|
using osu.Game.Overlays.Changelog;
|
2018-07-16 21:50:22 +00:00
|
|
|
|
|
2019-05-15 09:30:02 +00:00
|
|
|
|
namespace osu.Game.Tests.Visual.Online
|
2018-07-16 21:50:22 +00:00
|
|
|
|
{
|
|
|
|
|
[TestFixture]
|
2019-05-15 09:30:02 +00:00
|
|
|
|
public class TestSceneChangelogOverlay : OsuTestScene
|
2018-07-16 21:50:22 +00:00
|
|
|
|
{
|
2020-12-25 18:28:33 +00:00
|
|
|
|
private DummyAPIAccess dummyAPI => (DummyAPIAccess)API;
|
|
|
|
|
|
|
|
|
|
private readonly Dictionary<string, APIUpdateStream> streams;
|
|
|
|
|
private readonly Dictionary<string, APIChangelogBuild> builds;
|
|
|
|
|
|
|
|
|
|
private APIChangelogBuild requestedBuild;
|
2020-01-27 05:50:24 +00:00
|
|
|
|
private TestChangelogOverlay changelog;
|
2018-07-16 21:50:22 +00:00
|
|
|
|
|
2020-12-25 18:28:33 +00:00
|
|
|
|
public TestSceneChangelogOverlay()
|
|
|
|
|
{
|
|
|
|
|
streams = APIUpdateStream.KNOWN_STREAMS.Keys.Select((stream, id) => new APIUpdateStream
|
|
|
|
|
{
|
|
|
|
|
Id = id + 1,
|
|
|
|
|
Name = stream,
|
|
|
|
|
DisplayName = stream.Humanize(), // not quite there, but good enough.
|
|
|
|
|
}).ToDictionary(stream => stream.Name);
|
|
|
|
|
|
|
|
|
|
string version = DateTimeOffset.Now.ToString("yyyy.Mdd.0");
|
|
|
|
|
builds = APIUpdateStream.KNOWN_STREAMS.Keys.Select(stream => new APIChangelogBuild
|
|
|
|
|
{
|
|
|
|
|
Version = version,
|
|
|
|
|
DisplayVersion = version,
|
|
|
|
|
UpdateStream = streams[stream],
|
|
|
|
|
ChangelogEntries = new List<APIChangelogEntry>()
|
|
|
|
|
}).ToDictionary(build => build.UpdateStream.Name);
|
|
|
|
|
|
|
|
|
|
foreach (var stream in streams.Values)
|
|
|
|
|
stream.LatestBuild = builds[stream.Name];
|
|
|
|
|
}
|
2019-07-31 19:44:44 +00:00
|
|
|
|
|
2020-01-27 05:50:24 +00:00
|
|
|
|
[SetUp]
|
2020-12-25 19:44:19 +00:00
|
|
|
|
public void SetUp() => Schedule(() =>
|
2018-07-16 21:50:22 +00:00
|
|
|
|
{
|
2020-12-25 18:28:33 +00:00
|
|
|
|
requestedBuild = null;
|
|
|
|
|
|
|
|
|
|
dummyAPI.HandleRequest = request =>
|
|
|
|
|
{
|
|
|
|
|
switch (request)
|
|
|
|
|
{
|
|
|
|
|
case GetChangelogRequest changelogRequest:
|
|
|
|
|
var changelogResponse = new APIChangelogIndex
|
|
|
|
|
{
|
|
|
|
|
Streams = streams.Values.ToList(),
|
|
|
|
|
Builds = builds.Values.ToList()
|
|
|
|
|
};
|
|
|
|
|
changelogRequest.TriggerSuccess(changelogResponse);
|
2021-03-23 09:08:32 +00:00
|
|
|
|
return true;
|
2020-12-25 18:28:33 +00:00
|
|
|
|
|
|
|
|
|
case GetChangelogBuildRequest buildRequest:
|
|
|
|
|
if (requestedBuild != null)
|
|
|
|
|
buildRequest.TriggerSuccess(requestedBuild);
|
2021-03-23 09:08:32 +00:00
|
|
|
|
return true;
|
2020-12-25 18:28:33 +00:00
|
|
|
|
}
|
2021-03-23 09:08:32 +00:00
|
|
|
|
|
|
|
|
|
return false;
|
2020-12-25 18:28:33 +00:00
|
|
|
|
};
|
|
|
|
|
|
2020-12-25 19:44:19 +00:00
|
|
|
|
Child = changelog = new TestChangelogOverlay();
|
|
|
|
|
});
|
2018-07-16 21:50:22 +00:00
|
|
|
|
|
2020-01-27 05:50:24 +00:00
|
|
|
|
[Test]
|
|
|
|
|
public void ShowWithNoFetch()
|
|
|
|
|
{
|
|
|
|
|
AddStep(@"Show", () => changelog.Show());
|
|
|
|
|
AddUntilStep(@"wait for streams", () => changelog.Streams?.Count > 0);
|
|
|
|
|
AddAssert(@"listing displayed", () => changelog.Current.Value == null);
|
|
|
|
|
AddAssert(@"no stream selected", () => changelog.Header.Streams.Current.Value == null);
|
|
|
|
|
}
|
2019-05-12 15:46:22 +00:00
|
|
|
|
|
2020-01-27 05:50:24 +00:00
|
|
|
|
[Test]
|
|
|
|
|
public void ShowWithListing()
|
|
|
|
|
{
|
|
|
|
|
AddStep(@"Show with listing", () => changelog.ShowListing());
|
|
|
|
|
AddUntilStep(@"wait for streams", () => changelog.Streams?.Count > 0);
|
|
|
|
|
AddAssert(@"listing displayed", () => changelog.Current.Value == null);
|
|
|
|
|
AddAssert(@"no stream selected", () => changelog.Header.Streams.Current.Value == null);
|
|
|
|
|
}
|
2019-05-12 15:46:22 +00:00
|
|
|
|
|
2020-01-27 05:50:24 +00:00
|
|
|
|
[Test]
|
|
|
|
|
public void ShowWithBuild()
|
|
|
|
|
{
|
2020-12-25 18:28:33 +00:00
|
|
|
|
showBuild(() => new APIChangelogBuild
|
2018-07-25 12:31:41 +00:00
|
|
|
|
{
|
2020-12-25 18:28:33 +00:00
|
|
|
|
Version = "2018.712.0",
|
|
|
|
|
DisplayVersion = "2018.712.0",
|
|
|
|
|
UpdateStream = streams[OsuGameBase.CLIENT_STREAM_NAME],
|
|
|
|
|
ChangelogEntries = new List<APIChangelogEntry>
|
2018-07-25 12:31:41 +00:00
|
|
|
|
{
|
2020-12-25 18:28:33 +00:00
|
|
|
|
new APIChangelogEntry
|
2019-05-21 05:46:12 +00:00
|
|
|
|
{
|
2020-12-25 19:08:57 +00:00
|
|
|
|
Type = ChangelogEntryType.Fix,
|
|
|
|
|
Category = "osu!",
|
|
|
|
|
Title = "Fix thing",
|
|
|
|
|
MessageHtml = "Additional info goes here.",
|
2020-12-25 19:41:35 +00:00
|
|
|
|
Repository = "osu",
|
|
|
|
|
GithubPullRequestId = 11100,
|
|
|
|
|
GithubUser = new APIChangelogUser
|
|
|
|
|
{
|
|
|
|
|
OsuUsername = "smoogipoo",
|
|
|
|
|
UserId = 1040328
|
|
|
|
|
}
|
2020-12-25 19:08:57 +00:00
|
|
|
|
},
|
|
|
|
|
new APIChangelogEntry
|
|
|
|
|
{
|
|
|
|
|
Type = ChangelogEntryType.Add,
|
|
|
|
|
Category = "osu!",
|
|
|
|
|
Title = "Add thing",
|
2020-12-25 19:41:35 +00:00
|
|
|
|
Major = true,
|
|
|
|
|
Repository = "ppy/osu-framework",
|
|
|
|
|
GithubPullRequestId = 4444,
|
|
|
|
|
GithubUser = new APIChangelogUser
|
|
|
|
|
{
|
|
|
|
|
DisplayName = "frenzibyte",
|
|
|
|
|
GithubUrl = "https://github.com/frenzibyte"
|
|
|
|
|
}
|
|
|
|
|
},
|
|
|
|
|
new APIChangelogEntry
|
|
|
|
|
{
|
|
|
|
|
Type = ChangelogEntryType.Misc,
|
|
|
|
|
Category = "Code quality",
|
|
|
|
|
Title = "Clean up thing",
|
|
|
|
|
GithubUser = new APIChangelogUser
|
|
|
|
|
{
|
|
|
|
|
DisplayName = "some dude"
|
|
|
|
|
}
|
2020-12-25 19:08:57 +00:00
|
|
|
|
},
|
|
|
|
|
new APIChangelogEntry
|
|
|
|
|
{
|
|
|
|
|
Type = ChangelogEntryType.Misc,
|
|
|
|
|
Category = "Code quality",
|
2020-12-25 19:41:35 +00:00
|
|
|
|
Title = "Clean up another thing"
|
2019-05-21 05:46:12 +00:00
|
|
|
|
}
|
2020-12-25 18:28:33 +00:00
|
|
|
|
}
|
2018-07-25 12:31:41 +00:00
|
|
|
|
});
|
2019-05-12 15:46:22 +00:00
|
|
|
|
|
2020-01-27 05:50:24 +00:00
|
|
|
|
AddUntilStep(@"wait for streams", () => changelog.Streams?.Count > 0);
|
|
|
|
|
AddAssert(@"correct build displayed", () => changelog.Current.Value.Version == "2018.712.0");
|
2020-12-24 12:28:21 +00:00
|
|
|
|
AddAssert(@"correct stream selected", () => changelog.Header.Streams.Current.Value.Id == 5);
|
2020-01-27 05:50:24 +00:00
|
|
|
|
}
|
2019-09-20 19:35:26 +00:00
|
|
|
|
|
2020-01-27 05:50:24 +00:00
|
|
|
|
[Test]
|
|
|
|
|
public void TestHTMLUnescaping()
|
|
|
|
|
{
|
2020-12-25 18:28:33 +00:00
|
|
|
|
showBuild(() => new APIChangelogBuild
|
2019-09-20 19:35:26 +00:00
|
|
|
|
{
|
2020-12-25 18:28:33 +00:00
|
|
|
|
Version = "2019.920.0",
|
|
|
|
|
DisplayVersion = "2019.920.0",
|
|
|
|
|
UpdateStream = new APIUpdateStream
|
2019-09-20 19:35:26 +00:00
|
|
|
|
{
|
2020-12-25 18:28:33 +00:00
|
|
|
|
Name = "Test",
|
|
|
|
|
DisplayName = "Test"
|
|
|
|
|
},
|
|
|
|
|
ChangelogEntries = new List<APIChangelogEntry>
|
|
|
|
|
{
|
|
|
|
|
new APIChangelogEntry
|
2019-09-20 19:35:26 +00:00
|
|
|
|
{
|
2020-12-25 18:28:33 +00:00
|
|
|
|
Category = "Testing HTML strings unescaping",
|
|
|
|
|
Title = "Ensuring HTML strings are being unescaped",
|
|
|
|
|
MessageHtml = """"This text should appear triple-quoted""" >_<",
|
|
|
|
|
GithubUser = new APIChangelogUser
|
2019-09-20 19:35:26 +00:00
|
|
|
|
{
|
2020-12-25 18:28:33 +00:00
|
|
|
|
DisplayName = "Dummy",
|
|
|
|
|
OsuUsername = "Dummy",
|
|
|
|
|
}
|
|
|
|
|
},
|
|
|
|
|
}
|
2019-09-20 19:35:26 +00:00
|
|
|
|
});
|
2018-07-16 21:50:22 +00:00
|
|
|
|
}
|
2020-01-27 05:50:24 +00:00
|
|
|
|
|
2020-12-25 18:28:33 +00:00
|
|
|
|
private void showBuild(Func<APIChangelogBuild> build)
|
|
|
|
|
{
|
|
|
|
|
AddStep("set up build", () => requestedBuild = build.Invoke());
|
|
|
|
|
AddStep("show build", () => changelog.ShowBuild(requestedBuild));
|
|
|
|
|
}
|
|
|
|
|
|
2020-01-27 05:50:24 +00:00
|
|
|
|
private class TestChangelogOverlay : ChangelogOverlay
|
|
|
|
|
{
|
|
|
|
|
public new List<APIUpdateStream> Streams => base.Streams;
|
|
|
|
|
|
|
|
|
|
public new ChangelogHeader Header => base.Header;
|
|
|
|
|
}
|
2018-07-16 21:50:22 +00:00
|
|
|
|
}
|
|
|
|
|
}
|