2019-01-24 16:43:03 +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.
|
2018-04-13 17:19:50 +08:00
|
|
|
|
|
|
|
|
|
using System.Collections.Generic;
|
|
|
|
|
using System.Linq;
|
|
|
|
|
using NUnit.Framework;
|
|
|
|
|
using osu.Framework.Graphics;
|
|
|
|
|
using osu.Framework.Graphics.Containers;
|
|
|
|
|
using osu.Framework.Graphics.Sprites;
|
2020-01-09 12:43:44 +08:00
|
|
|
|
using osu.Framework.Utils;
|
2019-05-21 13:13:52 +08:00
|
|
|
|
using osu.Game.Graphics.Sprites;
|
2018-04-13 17:19:50 +08:00
|
|
|
|
using osu.Game.Overlays;
|
|
|
|
|
using osu.Game.Overlays.Notifications;
|
|
|
|
|
|
2019-03-25 00:02:36 +08:00
|
|
|
|
namespace osu.Game.Tests.Visual.UserInterface
|
2018-04-13 17:19:50 +08:00
|
|
|
|
{
|
|
|
|
|
[TestFixture]
|
2019-05-15 03:37:25 +08:00
|
|
|
|
public class TestSceneNotificationOverlay : OsuTestScene
|
2018-04-13 17:19:50 +08:00
|
|
|
|
{
|
2019-06-20 18:06:21 +08:00
|
|
|
|
private NotificationOverlay notificationOverlay;
|
2018-04-13 17:19:50 +08:00
|
|
|
|
|
2019-06-20 18:06:21 +08:00
|
|
|
|
private readonly List<ProgressNotification> progressingNotifications = new List<ProgressNotification>();
|
2018-04-13 17:19:50 +08:00
|
|
|
|
|
2019-06-20 18:06:21 +08:00
|
|
|
|
private SpriteText displayedCount;
|
2018-04-13 17:19:50 +08:00
|
|
|
|
|
2019-06-20 18:06:21 +08:00
|
|
|
|
[SetUp]
|
|
|
|
|
public void SetUp() => Schedule(() =>
|
|
|
|
|
{
|
|
|
|
|
progressingNotifications.Clear();
|
2018-04-13 17:19:50 +08:00
|
|
|
|
|
2019-06-20 18:06:21 +08:00
|
|
|
|
Content.Children = new Drawable[]
|
|
|
|
|
{
|
|
|
|
|
notificationOverlay = new NotificationOverlay
|
|
|
|
|
{
|
|
|
|
|
Anchor = Anchor.TopRight,
|
|
|
|
|
Origin = Anchor.TopRight
|
|
|
|
|
},
|
|
|
|
|
displayedCount = new OsuSpriteText()
|
|
|
|
|
};
|
2018-04-13 17:19:50 +08:00
|
|
|
|
|
2019-06-20 18:06:21 +08:00
|
|
|
|
notificationOverlay.UnreadCount.ValueChanged += count => { displayedCount.Text = $"displayed count: {count.NewValue}"; };
|
|
|
|
|
});
|
2018-04-13 17:19:50 +08:00
|
|
|
|
|
2019-06-20 18:06:21 +08:00
|
|
|
|
[Test]
|
|
|
|
|
public void TestBasicFlow()
|
|
|
|
|
{
|
2018-04-13 17:19:50 +08:00
|
|
|
|
setState(Visibility.Visible);
|
|
|
|
|
AddStep(@"simple #1", sendHelloNotification);
|
|
|
|
|
AddStep(@"simple #2", sendAmazingNotification);
|
|
|
|
|
AddStep(@"progress #1", sendUploadProgress);
|
|
|
|
|
AddStep(@"progress #2", sendDownloadProgress);
|
|
|
|
|
|
|
|
|
|
checkProgressingCount(2);
|
|
|
|
|
|
|
|
|
|
setState(Visibility.Hidden);
|
|
|
|
|
|
|
|
|
|
AddRepeatStep(@"add many simple", sendManyNotifications, 3);
|
2019-06-20 18:06:21 +08:00
|
|
|
|
|
2019-12-27 05:23:25 +08:00
|
|
|
|
waitForCompletion();
|
2018-04-13 17:19:50 +08:00
|
|
|
|
|
|
|
|
|
AddStep(@"progress #3", sendUploadProgress);
|
|
|
|
|
|
|
|
|
|
checkProgressingCount(1);
|
|
|
|
|
|
2019-06-20 18:06:21 +08:00
|
|
|
|
checkDisplayedCount(33);
|
2018-04-13 17:19:50 +08:00
|
|
|
|
|
2019-12-27 05:23:25 +08:00
|
|
|
|
waitForCompletion();
|
2019-06-20 18:06:21 +08:00
|
|
|
|
}
|
2018-04-13 17:19:50 +08:00
|
|
|
|
|
2019-06-20 18:06:21 +08:00
|
|
|
|
[Test]
|
|
|
|
|
public void TestImportantWhileClosed()
|
|
|
|
|
{
|
|
|
|
|
AddStep(@"simple #1", sendHelloNotification);
|
|
|
|
|
|
|
|
|
|
AddAssert("Is visible", () => notificationOverlay.State.Value == Visibility.Visible);
|
|
|
|
|
|
|
|
|
|
checkDisplayedCount(1);
|
|
|
|
|
|
|
|
|
|
AddStep(@"progress #1", sendUploadProgress);
|
|
|
|
|
AddStep(@"progress #2", sendDownloadProgress);
|
|
|
|
|
|
|
|
|
|
checkProgressingCount(2);
|
2019-06-20 18:23:27 +08:00
|
|
|
|
checkDisplayedCount(3);
|
2018-04-13 17:19:50 +08:00
|
|
|
|
}
|
|
|
|
|
|
2019-06-20 18:06:21 +08:00
|
|
|
|
[Test]
|
|
|
|
|
public void TestUnimportantWhileClosed()
|
2018-04-13 17:19:50 +08:00
|
|
|
|
{
|
2019-06-20 18:06:21 +08:00
|
|
|
|
AddStep(@"background #1", sendBackgroundNotification);
|
2019-04-01 11:44:46 +08:00
|
|
|
|
|
2019-06-20 18:06:21 +08:00
|
|
|
|
AddAssert("Is not visible", () => notificationOverlay.State.Value == Visibility.Hidden);
|
2019-04-01 11:44:46 +08:00
|
|
|
|
|
2019-06-20 18:06:21 +08:00
|
|
|
|
checkDisplayedCount(1);
|
2019-04-01 11:44:46 +08:00
|
|
|
|
|
2019-06-20 18:06:21 +08:00
|
|
|
|
AddStep(@"background progress #1", sendBackgroundUploadProgress);
|
2018-04-13 17:19:50 +08:00
|
|
|
|
|
2019-12-27 05:23:25 +08:00
|
|
|
|
checkProgressingCount(1);
|
2019-06-20 18:06:21 +08:00
|
|
|
|
|
2019-12-27 05:23:25 +08:00
|
|
|
|
waitForCompletion();
|
2019-06-20 18:06:21 +08:00
|
|
|
|
|
2019-06-20 18:23:27 +08:00
|
|
|
|
checkDisplayedCount(2);
|
2019-06-20 18:06:21 +08:00
|
|
|
|
|
|
|
|
|
AddStep(@"simple #1", sendHelloNotification);
|
|
|
|
|
|
|
|
|
|
checkDisplayedCount(3);
|
|
|
|
|
}
|
|
|
|
|
|
2021-01-21 17:42:53 +08:00
|
|
|
|
[Test]
|
|
|
|
|
public void TestError()
|
|
|
|
|
{
|
|
|
|
|
setState(Visibility.Visible);
|
|
|
|
|
AddStep(@"error #1", sendErrorNotification);
|
|
|
|
|
AddAssert("Is visible", () => notificationOverlay.State.Value == Visibility.Visible);
|
|
|
|
|
checkDisplayedCount(1);
|
|
|
|
|
}
|
|
|
|
|
|
2019-06-20 18:06:21 +08:00
|
|
|
|
[Test]
|
|
|
|
|
public void TestSpam()
|
|
|
|
|
{
|
|
|
|
|
setState(Visibility.Visible);
|
2019-06-20 18:23:27 +08:00
|
|
|
|
AddRepeatStep("send barrage", sendBarrage, 10);
|
2018-04-13 17:19:50 +08:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
protected override void Update()
|
|
|
|
|
{
|
|
|
|
|
base.Update();
|
|
|
|
|
|
|
|
|
|
progressingNotifications.RemoveAll(n => n.State == ProgressNotificationState.Completed);
|
|
|
|
|
|
|
|
|
|
if (progressingNotifications.Count(n => n.State == ProgressNotificationState.Active) < 3)
|
|
|
|
|
{
|
2019-01-06 00:35:33 +08:00
|
|
|
|
var p = progressingNotifications.Find(n => n.State == ProgressNotificationState.Queued);
|
2019-06-20 18:06:21 +08:00
|
|
|
|
|
2018-04-13 17:19:50 +08:00
|
|
|
|
if (p != null)
|
|
|
|
|
p.State = ProgressNotificationState.Active;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
foreach (var n in progressingNotifications.FindAll(n => n.State == ProgressNotificationState.Active))
|
|
|
|
|
{
|
|
|
|
|
if (n.Progress < 1)
|
|
|
|
|
n.Progress += (float)(Time.Elapsed / 400) * RNG.NextSingle();
|
|
|
|
|
else
|
|
|
|
|
n.State = ProgressNotificationState.Completed;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2019-06-20 18:06:21 +08:00
|
|
|
|
private void checkDisplayedCount(int expected) =>
|
|
|
|
|
AddAssert($"Displayed count is {expected}", () => notificationOverlay.UnreadCount.Value == expected);
|
|
|
|
|
|
2018-04-13 17:19:50 +08:00
|
|
|
|
private void sendDownloadProgress()
|
|
|
|
|
{
|
|
|
|
|
var n = new ProgressNotification
|
|
|
|
|
{
|
|
|
|
|
Text = @"Downloading Haitai...",
|
|
|
|
|
CompletionText = "Downloaded Haitai!",
|
|
|
|
|
};
|
2019-06-20 18:06:21 +08:00
|
|
|
|
notificationOverlay.Post(n);
|
2018-04-13 17:19:50 +08:00
|
|
|
|
progressingNotifications.Add(n);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private void sendUploadProgress()
|
|
|
|
|
{
|
|
|
|
|
var n = new ProgressNotification
|
|
|
|
|
{
|
|
|
|
|
Text = @"Uploading to BSS...",
|
|
|
|
|
CompletionText = "Uploaded to BSS!",
|
|
|
|
|
};
|
2019-06-20 18:06:21 +08:00
|
|
|
|
notificationOverlay.Post(n);
|
|
|
|
|
progressingNotifications.Add(n);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private void sendBackgroundUploadProgress()
|
|
|
|
|
{
|
|
|
|
|
var n = new BackgroundProgressNotification
|
|
|
|
|
{
|
|
|
|
|
Text = @"Uploading to BSS...",
|
|
|
|
|
CompletionText = "Uploaded to BSS!",
|
|
|
|
|
};
|
|
|
|
|
notificationOverlay.Post(n);
|
2018-04-13 17:19:50 +08:00
|
|
|
|
progressingNotifications.Add(n);
|
|
|
|
|
}
|
|
|
|
|
|
2019-06-20 18:06:21 +08:00
|
|
|
|
private void setState(Visibility state) => AddStep(state.ToString(), () => notificationOverlay.State.Value = state);
|
|
|
|
|
|
|
|
|
|
private void checkProgressingCount(int expected) => AddAssert($"progressing count is {expected}", () => progressingNotifications.Count == expected);
|
|
|
|
|
|
2019-12-27 05:23:25 +08:00
|
|
|
|
private void waitForCompletion() => AddUntilStep("wait for notification progress completion", () => progressingNotifications.Count == 0);
|
|
|
|
|
|
2019-06-20 18:23:27 +08:00
|
|
|
|
private void sendBarrage()
|
2019-06-20 18:06:21 +08:00
|
|
|
|
{
|
2021-01-21 17:42:53 +08:00
|
|
|
|
switch (RNG.Next(0, 5))
|
2019-06-20 18:06:21 +08:00
|
|
|
|
{
|
|
|
|
|
case 0:
|
|
|
|
|
sendHelloNotification();
|
|
|
|
|
break;
|
|
|
|
|
|
|
|
|
|
case 1:
|
|
|
|
|
sendAmazingNotification();
|
|
|
|
|
break;
|
|
|
|
|
|
|
|
|
|
case 2:
|
|
|
|
|
sendUploadProgress();
|
|
|
|
|
break;
|
|
|
|
|
|
|
|
|
|
case 3:
|
|
|
|
|
sendDownloadProgress();
|
|
|
|
|
break;
|
2021-01-21 17:42:53 +08:00
|
|
|
|
|
|
|
|
|
case 4:
|
|
|
|
|
sendErrorNotification();
|
|
|
|
|
break;
|
2019-06-20 18:06:21 +08:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2018-04-13 17:19:50 +08:00
|
|
|
|
private void sendAmazingNotification()
|
|
|
|
|
{
|
2019-06-20 18:06:21 +08:00
|
|
|
|
notificationOverlay.Post(new SimpleNotification { Text = @"You are amazing" });
|
2018-04-13 17:19:50 +08:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private void sendHelloNotification()
|
|
|
|
|
{
|
2019-06-20 18:06:21 +08:00
|
|
|
|
notificationOverlay.Post(new SimpleNotification { Text = @"Welcome to osu!. Enjoy your stay!" });
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private void sendBackgroundNotification()
|
|
|
|
|
{
|
|
|
|
|
notificationOverlay.Post(new BackgroundNotification { Text = @"Welcome to osu!. Enjoy your stay!" });
|
2018-04-13 17:19:50 +08:00
|
|
|
|
}
|
|
|
|
|
|
2021-01-21 17:42:53 +08:00
|
|
|
|
private void sendErrorNotification()
|
|
|
|
|
{
|
|
|
|
|
notificationOverlay.Post(new SimpleErrorNotification { Text = @"Rut roh!. Something went wrong!" });
|
|
|
|
|
}
|
|
|
|
|
|
2018-04-13 17:19:50 +08:00
|
|
|
|
private void sendManyNotifications()
|
|
|
|
|
{
|
|
|
|
|
for (int i = 0; i < 10; i++)
|
2019-06-20 18:06:21 +08:00
|
|
|
|
notificationOverlay.Post(new SimpleNotification { Text = @"Spam incoming!!" });
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private class BackgroundNotification : SimpleNotification
|
|
|
|
|
{
|
|
|
|
|
public override bool IsImportant => false;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private class BackgroundProgressNotification : ProgressNotification
|
|
|
|
|
{
|
|
|
|
|
public override bool IsImportant => false;
|
2018-04-13 17:19:50 +08:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|