2024-05-17 16:39:24 +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.
|
|
|
|
|
|
|
|
using System;
|
2024-07-30 16:36:26 +08:00
|
|
|
using System.Linq;
|
2024-05-17 16:39:24 +08:00
|
|
|
using NUnit.Framework;
|
|
|
|
using osu.Framework.Allocation;
|
|
|
|
using osu.Framework.Graphics;
|
|
|
|
using osu.Game.Graphics;
|
|
|
|
using osu.Game.Localisation;
|
|
|
|
using osu.Game.Online.API;
|
|
|
|
using osu.Game.Online.Metadata;
|
|
|
|
using osu.Game.Online.Rooms;
|
2024-07-30 16:36:26 +08:00
|
|
|
using osu.Game.Overlays;
|
2024-05-17 16:39:24 +08:00
|
|
|
using osu.Game.Screens.Menu;
|
|
|
|
using osuTK.Input;
|
|
|
|
using Color4 = osuTK.Graphics.Color4;
|
|
|
|
|
|
|
|
namespace osu.Game.Tests.Visual.UserInterface
|
|
|
|
{
|
|
|
|
[TestFixture]
|
|
|
|
public partial class TestSceneMainMenuButton : OsuTestScene
|
|
|
|
{
|
|
|
|
[Resolved]
|
|
|
|
private MetadataClient metadataClient { get; set; } = null!;
|
|
|
|
|
|
|
|
private DummyAPIAccess dummyAPI => (DummyAPIAccess)API;
|
|
|
|
|
|
|
|
[Test]
|
|
|
|
public void TestStandardButton()
|
|
|
|
{
|
|
|
|
AddStep("add button", () => Child = new MainMenuButton(
|
|
|
|
ButtonSystemStrings.Solo, @"button-default-select", OsuIcon.Player, new Color4(102, 68, 204, 255), _ => { }, 0, Key.P)
|
|
|
|
{
|
|
|
|
Anchor = Anchor.Centre,
|
|
|
|
Origin = Anchor.Centre,
|
|
|
|
ButtonSystemState = ButtonSystemState.TopLevel,
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
[Test]
|
|
|
|
public void TestDailyChallengeButton()
|
|
|
|
{
|
|
|
|
AddStep("set up API", () => dummyAPI.HandleRequest = req =>
|
|
|
|
{
|
|
|
|
switch (req)
|
|
|
|
{
|
|
|
|
case GetRoomRequest getRoomRequest:
|
|
|
|
if (getRoomRequest.RoomId != 1234)
|
|
|
|
return false;
|
|
|
|
|
|
|
|
var beatmap = CreateAPIBeatmap();
|
|
|
|
beatmap.OnlineID = 1001;
|
|
|
|
getRoomRequest.TriggerSuccess(new Room
|
|
|
|
{
|
2024-11-13 15:28:39 +08:00
|
|
|
RoomID = 1234,
|
2024-05-17 16:39:24 +08:00
|
|
|
Playlist =
|
|
|
|
{
|
|
|
|
new PlaylistItem(beatmap)
|
|
|
|
},
|
2024-08-12 17:19:02 +08:00
|
|
|
StartDate = { Value = DateTimeOffset.Now.AddMinutes(-5) },
|
2024-05-17 16:39:24 +08:00
|
|
|
EndDate = { Value = DateTimeOffset.Now.AddSeconds(30) }
|
|
|
|
});
|
|
|
|
return true;
|
|
|
|
|
|
|
|
default:
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
});
|
|
|
|
|
2024-07-30 16:36:26 +08:00
|
|
|
NotificationOverlay notificationOverlay = null!;
|
|
|
|
DependencyProvidingContainer buttonContainer = null!;
|
|
|
|
|
|
|
|
AddStep("beatmap of the day active", () => metadataClient.DailyChallengeUpdated(new DailyChallengeInfo
|
2024-05-23 14:31:20 +08:00
|
|
|
{
|
2024-07-30 16:36:26 +08:00
|
|
|
RoomID = 1234,
|
|
|
|
}));
|
|
|
|
AddStep("add content", () =>
|
|
|
|
{
|
|
|
|
notificationOverlay = new NotificationOverlay();
|
|
|
|
Children = new Drawable[]
|
|
|
|
{
|
|
|
|
notificationOverlay,
|
|
|
|
buttonContainer = new DependencyProvidingContainer
|
|
|
|
{
|
|
|
|
Anchor = Anchor.Centre,
|
|
|
|
Origin = Anchor.Centre,
|
|
|
|
AutoSizeAxes = Axes.Both,
|
|
|
|
CachedDependencies = [(typeof(INotificationOverlay), notificationOverlay)],
|
|
|
|
Child = new DailyChallengeButton(@"button-default-select", new Color4(102, 68, 204, 255), _ => { }, 0, Key.D)
|
|
|
|
{
|
|
|
|
Anchor = Anchor.Centre,
|
|
|
|
Origin = Anchor.Centre,
|
|
|
|
ButtonSystemState = ButtonSystemState.TopLevel,
|
|
|
|
},
|
|
|
|
},
|
|
|
|
};
|
2024-05-23 14:31:20 +08:00
|
|
|
});
|
2024-08-12 17:19:02 +08:00
|
|
|
AddAssert("notification posted", () => notificationOverlay.AllNotifications.Count(), () => Is.EqualTo(1));
|
2024-07-30 16:36:26 +08:00
|
|
|
|
2024-08-12 17:19:02 +08:00
|
|
|
AddStep("clear notifications", () =>
|
|
|
|
{
|
|
|
|
foreach (var notification in notificationOverlay.AllNotifications)
|
|
|
|
notification.Close(runFlingAnimation: false);
|
|
|
|
});
|
2024-08-22 05:00:07 +08:00
|
|
|
|
2024-07-30 16:36:26 +08:00
|
|
|
AddStep("beatmap of the day not active", () => metadataClient.DailyChallengeUpdated(null));
|
|
|
|
AddAssert("no notification posted", () => notificationOverlay.AllNotifications.Count(), () => Is.Zero);
|
2024-05-23 14:31:20 +08:00
|
|
|
|
2024-07-30 16:36:26 +08:00
|
|
|
AddStep("hide button's parent", () => buttonContainer.Hide());
|
2024-08-22 05:00:07 +08:00
|
|
|
|
2024-05-17 16:39:24 +08:00
|
|
|
AddStep("beatmap of the day active", () => metadataClient.DailyChallengeUpdated(new DailyChallengeInfo
|
|
|
|
{
|
|
|
|
RoomID = 1234,
|
|
|
|
}));
|
2024-08-12 17:19:02 +08:00
|
|
|
AddAssert("no notification posted", () => notificationOverlay.AllNotifications.Count(), () => Is.Zero);
|
2024-08-22 05:00:07 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
[Test]
|
|
|
|
public void TestDailyChallengeButtonOldChallenge()
|
|
|
|
{
|
|
|
|
AddStep("set up API", () => dummyAPI.HandleRequest = req =>
|
|
|
|
{
|
|
|
|
switch (req)
|
|
|
|
{
|
|
|
|
case GetRoomRequest getRoomRequest:
|
|
|
|
if (getRoomRequest.RoomId != 1234)
|
|
|
|
return false;
|
|
|
|
|
|
|
|
var beatmap = CreateAPIBeatmap();
|
|
|
|
beatmap.OnlineID = 1001;
|
|
|
|
getRoomRequest.TriggerSuccess(new Room
|
|
|
|
{
|
2024-11-13 15:28:39 +08:00
|
|
|
RoomID = 1234,
|
2024-08-22 05:00:07 +08:00
|
|
|
Playlist =
|
|
|
|
{
|
|
|
|
new PlaylistItem(beatmap)
|
|
|
|
},
|
|
|
|
StartDate = { Value = DateTimeOffset.Now.AddMinutes(-50) },
|
|
|
|
EndDate = { Value = DateTimeOffset.Now.AddSeconds(30) }
|
|
|
|
});
|
|
|
|
return true;
|
|
|
|
|
|
|
|
default:
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
});
|
|
|
|
|
|
|
|
NotificationOverlay notificationOverlay = null!;
|
|
|
|
|
|
|
|
AddStep("beatmap of the day not active", () => metadataClient.DailyChallengeUpdated(null));
|
|
|
|
AddStep("add content", () =>
|
|
|
|
{
|
|
|
|
notificationOverlay = new NotificationOverlay();
|
|
|
|
Children = new Drawable[]
|
|
|
|
{
|
|
|
|
notificationOverlay,
|
|
|
|
new DependencyProvidingContainer
|
|
|
|
{
|
|
|
|
Anchor = Anchor.Centre,
|
|
|
|
Origin = Anchor.Centre,
|
|
|
|
AutoSizeAxes = Axes.Both,
|
|
|
|
CachedDependencies = [(typeof(INotificationOverlay), notificationOverlay)],
|
|
|
|
Child = new DailyChallengeButton(@"button-default-select", new Color4(102, 68, 204, 255), _ => { }, 0, Key.D)
|
|
|
|
{
|
|
|
|
Anchor = Anchor.Centre,
|
|
|
|
Origin = Anchor.Centre,
|
|
|
|
ButtonSystemState = ButtonSystemState.TopLevel,
|
|
|
|
},
|
|
|
|
},
|
|
|
|
};
|
|
|
|
});
|
|
|
|
|
|
|
|
AddStep("beatmap of the day active", () => metadataClient.DailyChallengeUpdated(new DailyChallengeInfo
|
|
|
|
{
|
|
|
|
RoomID = 1234
|
|
|
|
}));
|
|
|
|
AddAssert("no notification posted", () => notificationOverlay.AllNotifications.Count(), () => Is.Zero);
|
2024-05-17 16:39:24 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|