2022-08-09 14:34:33 +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-02-10 00:14:15 +08:00
|
|
|
using System.Linq;
|
2022-08-09 14:34:33 +08:00
|
|
|
using NUnit.Framework;
|
|
|
|
using osu.Framework.Graphics;
|
|
|
|
using osu.Framework.Graphics.Containers;
|
|
|
|
using osu.Framework.Graphics.Shapes;
|
2024-02-10 00:14:15 +08:00
|
|
|
using osu.Framework.Testing;
|
2024-02-29 06:13:31 +08:00
|
|
|
using osu.Game.Online;
|
2022-08-09 14:34:33 +08:00
|
|
|
using osu.Game.Online.API;
|
|
|
|
using osu.Game.Overlays.Toolbar;
|
2024-02-10 00:14:15 +08:00
|
|
|
using osu.Game.Scoring;
|
|
|
|
using osu.Game.Users;
|
2022-08-09 14:34:33 +08:00
|
|
|
using osuTK;
|
|
|
|
using osuTK.Graphics;
|
|
|
|
|
|
|
|
namespace osu.Game.Tests.Visual.Menus
|
|
|
|
{
|
|
|
|
[TestFixture]
|
2022-11-24 13:32:20 +08:00
|
|
|
public partial class TestSceneToolbarUserButton : OsuManualInputManagerTestScene
|
2022-08-09 14:34:33 +08:00
|
|
|
{
|
2024-01-24 01:04:41 +08:00
|
|
|
private DummyAPIAccess dummyAPI => (DummyAPIAccess)API;
|
|
|
|
|
2022-08-09 14:34:33 +08:00
|
|
|
public TestSceneToolbarUserButton()
|
|
|
|
{
|
|
|
|
Container mainContainer;
|
|
|
|
|
|
|
|
Children = new Drawable[]
|
|
|
|
{
|
|
|
|
mainContainer = new Container
|
|
|
|
{
|
|
|
|
Anchor = Anchor.Centre,
|
|
|
|
Origin = Anchor.Centre,
|
|
|
|
RelativeSizeAxes = Axes.X,
|
|
|
|
Height = Toolbar.HEIGHT,
|
|
|
|
Children = new Drawable[]
|
|
|
|
{
|
|
|
|
new Box
|
|
|
|
{
|
|
|
|
Colour = Color4.Black,
|
|
|
|
RelativeSizeAxes = Axes.Both,
|
|
|
|
},
|
|
|
|
new FillFlowContainer
|
|
|
|
{
|
|
|
|
Anchor = Anchor.Centre,
|
|
|
|
Origin = Anchor.Centre,
|
|
|
|
RelativeSizeAxes = Axes.Y,
|
|
|
|
AutoSizeAxes = Axes.X,
|
|
|
|
Direction = FillDirection.Horizontal,
|
|
|
|
Children = new Drawable[]
|
|
|
|
{
|
|
|
|
new Box
|
|
|
|
{
|
|
|
|
Colour = Color4.DarkRed,
|
|
|
|
RelativeSizeAxes = Axes.Y,
|
|
|
|
Width = 2,
|
|
|
|
},
|
|
|
|
new ToolbarUserButton(),
|
|
|
|
new Box
|
|
|
|
{
|
|
|
|
Colour = Color4.DarkRed,
|
|
|
|
RelativeSizeAxes = Axes.Y,
|
|
|
|
Width = 2,
|
|
|
|
},
|
|
|
|
}
|
|
|
|
},
|
|
|
|
}
|
|
|
|
},
|
|
|
|
};
|
|
|
|
|
|
|
|
AddSliderStep("scale", 0.5, 4, 1, scale => mainContainer.Scale = new Vector2((float)scale));
|
|
|
|
}
|
|
|
|
|
|
|
|
[Test]
|
|
|
|
public void TestLoginLogout()
|
|
|
|
{
|
2024-01-24 01:04:41 +08:00
|
|
|
AddStep("Log out", () => dummyAPI.Logout());
|
|
|
|
AddStep("Log in", () => dummyAPI.Login("wang", "jang"));
|
|
|
|
AddStep("Authenticate via second factor", () => dummyAPI.AuthenticateSecondFactor("abcdefgh"));
|
2022-08-09 14:34:33 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
[Test]
|
|
|
|
public void TestStates()
|
|
|
|
{
|
2024-01-24 01:04:41 +08:00
|
|
|
AddStep("Log in", () => dummyAPI.Login("wang", "jang"));
|
|
|
|
AddStep("Authenticate via second factor", () => dummyAPI.AuthenticateSecondFactor("abcdefgh"));
|
2022-08-09 14:34:33 +08:00
|
|
|
|
|
|
|
foreach (var state in Enum.GetValues<APIState>())
|
|
|
|
{
|
2024-01-24 01:04:41 +08:00
|
|
|
AddStep($"Change state to {state}", () => dummyAPI.SetState(state));
|
2022-08-09 14:34:33 +08:00
|
|
|
}
|
|
|
|
}
|
2024-02-10 00:14:15 +08:00
|
|
|
|
|
|
|
[Test]
|
|
|
|
public void TestTransientUserStatisticsDisplay()
|
|
|
|
{
|
|
|
|
AddStep("Log in", () => dummyAPI.Login("wang", "jang"));
|
|
|
|
AddStep("Gain", () =>
|
|
|
|
{
|
|
|
|
var transientUpdateDisplay = this.ChildrenOfType<TransientUserStatisticsUpdateDisplay>().Single();
|
2024-02-23 02:50:46 +08:00
|
|
|
transientUpdateDisplay.LatestUpdate.Value = new UserStatisticsUpdate(
|
2024-02-10 00:14:15 +08:00
|
|
|
new ScoreInfo(),
|
|
|
|
new UserStatistics
|
|
|
|
{
|
|
|
|
GlobalRank = 123_456,
|
|
|
|
PP = 1234
|
|
|
|
},
|
|
|
|
new UserStatistics
|
|
|
|
{
|
|
|
|
GlobalRank = 111_111,
|
|
|
|
PP = 1357
|
|
|
|
});
|
|
|
|
});
|
|
|
|
AddStep("Loss", () =>
|
|
|
|
{
|
|
|
|
var transientUpdateDisplay = this.ChildrenOfType<TransientUserStatisticsUpdateDisplay>().Single();
|
2024-02-23 02:50:46 +08:00
|
|
|
transientUpdateDisplay.LatestUpdate.Value = new UserStatisticsUpdate(
|
2024-02-10 00:14:15 +08:00
|
|
|
new ScoreInfo(),
|
|
|
|
new UserStatistics
|
|
|
|
{
|
|
|
|
GlobalRank = 111_111,
|
|
|
|
PP = 1357
|
|
|
|
},
|
|
|
|
new UserStatistics
|
|
|
|
{
|
|
|
|
GlobalRank = 123_456,
|
|
|
|
PP = 1234
|
|
|
|
});
|
|
|
|
});
|
|
|
|
AddStep("No change", () =>
|
|
|
|
{
|
|
|
|
var transientUpdateDisplay = this.ChildrenOfType<TransientUserStatisticsUpdateDisplay>().Single();
|
2024-02-23 02:50:46 +08:00
|
|
|
transientUpdateDisplay.LatestUpdate.Value = new UserStatisticsUpdate(
|
2024-02-10 00:14:15 +08:00
|
|
|
new ScoreInfo(),
|
|
|
|
new UserStatistics
|
|
|
|
{
|
|
|
|
GlobalRank = 111_111,
|
|
|
|
PP = 1357
|
|
|
|
},
|
|
|
|
new UserStatistics
|
|
|
|
{
|
|
|
|
GlobalRank = 111_111,
|
|
|
|
PP = 1357
|
|
|
|
});
|
|
|
|
});
|
|
|
|
AddStep("Was null", () =>
|
|
|
|
{
|
|
|
|
var transientUpdateDisplay = this.ChildrenOfType<TransientUserStatisticsUpdateDisplay>().Single();
|
2024-02-23 02:50:46 +08:00
|
|
|
transientUpdateDisplay.LatestUpdate.Value = new UserStatisticsUpdate(
|
2024-02-10 00:14:15 +08:00
|
|
|
new ScoreInfo(),
|
|
|
|
new UserStatistics
|
|
|
|
{
|
|
|
|
GlobalRank = null,
|
|
|
|
PP = null
|
|
|
|
},
|
|
|
|
new UserStatistics
|
|
|
|
{
|
|
|
|
GlobalRank = 111_111,
|
|
|
|
PP = 1357
|
|
|
|
});
|
|
|
|
});
|
|
|
|
AddStep("Became null", () =>
|
|
|
|
{
|
|
|
|
var transientUpdateDisplay = this.ChildrenOfType<TransientUserStatisticsUpdateDisplay>().Single();
|
2024-02-23 02:50:46 +08:00
|
|
|
transientUpdateDisplay.LatestUpdate.Value = new UserStatisticsUpdate(
|
2024-02-10 00:14:15 +08:00
|
|
|
new ScoreInfo(),
|
|
|
|
new UserStatistics
|
|
|
|
{
|
|
|
|
GlobalRank = 111_111,
|
|
|
|
PP = 1357
|
|
|
|
},
|
|
|
|
new UserStatistics
|
|
|
|
{
|
|
|
|
GlobalRank = null,
|
|
|
|
PP = null
|
|
|
|
});
|
|
|
|
});
|
|
|
|
}
|
2022-08-09 14:34:33 +08:00
|
|
|
}
|
|
|
|
}
|