1
0
mirror of https://github.com/ppy/osu.git synced 2024-11-11 09:27:29 +08:00

added tests

This commit is contained in:
Joshua Hegedus 2023-11-04 19:03:23 +01:00
parent a70bfca501
commit ec290ae953
No known key found for this signature in database
GPG Key ID: 9B61F76A5E82A99A
3 changed files with 125 additions and 22 deletions

View File

@ -0,0 +1,125 @@
// 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.Linq;
using NUnit.Framework;
using osu.Framework.Extensions.Color4Extensions;
using osu.Framework.Graphics;
using osu.Framework.Graphics.Containers;
using osu.Framework.Graphics.Effects;
using osu.Framework.Testing;
using osu.Game.Online.API.Requests.Responses;
using osu.Game.Users;
using osu.Game.Users.Drawables;
using osuTK;
using osuTK.Graphics;
namespace osu.Game.Tests.Visual.Online
{
public partial class TestSceneUserClickableAvatar : OsuManualInputManagerTestScene
{
[SetUp]
public void SetUp() => Schedule(() =>
{
Child = new FillFlowContainer
{
AutoSizeAxes = Axes.Both,
Anchor = Anchor.Centre,
Origin = Anchor.Centre,
Spacing = new Vector2(10f),
Children = new Drawable[]
{
new ClickableAvatar(new APIUser
{
Username = @"flyte", Id = 3103765, CoverUrl = @"https://osu.ppy.sh/images/headers/profile-covers/c6.jpg"
})
{
Width = 50,
Height = 50,
CornerRadius = 10,
Masking = true,
EdgeEffect = new EdgeEffectParameters
{
Type = EdgeEffectType.Shadow, Radius = 1, Colour = Color4.Black.Opacity(0.2f),
},
},
new ClickableAvatar(new APIUser
{
Username = @"peppy", Id = 2, Colour = "99EB47", CoverUrl = @"https://osu.ppy.sh/images/headers/profile-covers/c3.jpg",
})
{
Width = 50,
Height = 50,
CornerRadius = 10,
Masking = true,
EdgeEffect = new EdgeEffectParameters
{
Type = EdgeEffectType.Shadow, Radius = 1, Colour = Color4.Black.Opacity(0.2f),
},
},
new ClickableAvatar(new APIUser
{
Username = @"flyte",
Id = 3103765,
CountryCode = CountryCode.JP,
CoverUrl = @"https://osu.ppy.sh/images/headers/profile-covers/c6.jpg",
Status =
{
Value = new UserStatusOnline()
}
})
{
Width = 50,
Height = 50,
CornerRadius = 10,
Masking = true,
EdgeEffect = new EdgeEffectParameters
{
Type = EdgeEffectType.Shadow, Radius = 1, Colour = Color4.Black.Opacity(0.2f),
},
},
},
};
});
[Test]
public void TestClickableAvatarHover()
{
AddStep($"click {1}. {nameof(ClickableAvatar)}", () =>
{
var targets = this.ChildrenOfType<ClickableAvatar>().ToList();
if (targets.Count < 1)
return;
InputManager.MoveMouseTo(targets[0]);
});
AddWaitStep("wait for tooltip to show", 5);
AddStep("Hover out", () => InputManager.MoveMouseTo(new Vector2(0)));
AddWaitStep("wait for tooltip to hide", 3);
AddStep($"click {2}. {nameof(ClickableAvatar)}", () =>
{
var targets = this.ChildrenOfType<ClickableAvatar>().ToList();
if (targets.Count < 2)
return;
InputManager.MoveMouseTo(targets[1]);
});
AddWaitStep("wait for tooltip to show", 5);
AddStep("Hover out", () => InputManager.MoveMouseTo(new Vector2(0)));
AddWaitStep("wait for tooltip to hide", 3);
AddStep($"click {3}. {nameof(ClickableAvatar)}", () =>
{
var targets = this.ChildrenOfType<ClickableAvatar>().ToList();
if (targets.Count < 3)
return;
InputManager.MoveMouseTo(targets[2]);
});
AddWaitStep("wait for tooltip to show", 5);
AddStep("Hover out", () => InputManager.MoveMouseTo(new Vector2(0)));
AddWaitStep("wait for tooltip to hide", 3);
}
}
}

View File

@ -1,15 +1,12 @@
// 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;
using osu.Framework.Allocation;
using osu.Framework.Graphics;
using osu.Framework.Graphics.Containers;
using osu.Framework.Graphics.Cursor;
using osu.Framework.Input.Events;
using osu.Framework.Localisation;
using osu.Game.Graphics.Containers;
using osu.Game.Localisation;
using osu.Game.Online.API.Requests.Responses;
using osuTK;
@ -24,24 +21,6 @@ namespace osu.Game.Users.Drawables
Width = 300
};
public override LocalisableString TooltipText
{
get
{
if (!Enabled.Value)
return string.Empty;
return ShowUsernameTooltip ? (user?.Username ?? string.Empty) : ContextMenuStrings.ViewProfile;
}
set => throw new NotSupportedException();
}
/// <summary>
/// By default, the tooltip will show "view profile" as avatars are usually displayed next to a username.
/// Setting this to <c>true</c> exposes the username via tooltip for special cases where this is not true.
/// </summary>
public bool ShowUsernameTooltip { get; set; }
private readonly APIUser? user;
[Resolved]

View File

@ -74,7 +74,6 @@ namespace osu.Game.Users.Drawables
{
return new ClickableAvatar(user)
{
ShowUsernameTooltip = showUsernameTooltip,
RelativeSizeAxes = Axes.Both,
};
}