mirror of
https://github.com/ppy/osu.git
synced 2024-12-14 10:52:53 +08:00
Add test coverage
This commit is contained in:
parent
4d3b605e04
commit
c24af5bfeb
@ -170,6 +170,24 @@ namespace osu.Game.Tests.Visual.Online
|
||||
});
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void TestPostAsOwner()
|
||||
{
|
||||
setUpCommentsResponse(getExampleComments());
|
||||
AddStep("show comments", () => commentsContainer.ShowComments(CommentableType.Beatmapset, 123));
|
||||
|
||||
setUpPostResponse(true);
|
||||
AddStep("enter text", () => editorTextBox.Current.Value = "comm");
|
||||
AddStep("submit", () => commentsContainer.ChildrenOfType<CommentEditor>().Single().ChildrenOfType<RoundedButton>().First().TriggerClick());
|
||||
|
||||
AddUntilStep("comment sent", () =>
|
||||
{
|
||||
string writtenText = editorTextBox.Current.Value;
|
||||
var comment = commentsContainer.ChildrenOfType<DrawableComment>().LastOrDefault();
|
||||
return comment != null && comment.ChildrenOfType<SpriteText>().Any(y => y.Text == writtenText) && comment.ChildrenOfType<SpriteText>().Any(y => y.Text == "MAPPER");
|
||||
});
|
||||
}
|
||||
|
||||
private void setUpCommentsResponse(CommentBundle commentBundle)
|
||||
=> AddStep("set up response", () =>
|
||||
{
|
||||
@ -183,7 +201,7 @@ namespace osu.Game.Tests.Visual.Online
|
||||
};
|
||||
});
|
||||
|
||||
private void setUpPostResponse()
|
||||
private void setUpPostResponse(bool asOwner = false)
|
||||
=> AddStep("set up response", () =>
|
||||
{
|
||||
dummyAPI.HandleRequest = request =>
|
||||
@ -191,7 +209,7 @@ namespace osu.Game.Tests.Visual.Online
|
||||
if (!(request is CommentPostRequest req))
|
||||
return false;
|
||||
|
||||
req.TriggerSuccess(new CommentBundle
|
||||
var bundle = new CommentBundle
|
||||
{
|
||||
Comments = new List<Comment>
|
||||
{
|
||||
@ -202,9 +220,26 @@ namespace osu.Game.Tests.Visual.Online
|
||||
LegacyName = "FirstUser",
|
||||
CreatedAt = DateTimeOffset.Now,
|
||||
VotesCount = 98,
|
||||
CommentableId = 2001,
|
||||
CommentableType = "test",
|
||||
}
|
||||
}
|
||||
});
|
||||
};
|
||||
|
||||
if (asOwner)
|
||||
{
|
||||
bundle.Comments[0].UserId = 1001;
|
||||
bundle.Comments[0].User = new APIUser { Id = 1001, Username = "FirstUser" };
|
||||
bundle.CommentableMeta.Add(new CommentableMeta
|
||||
{
|
||||
Id = 2001,
|
||||
OwnerId = 1001,
|
||||
OwnerTitle = "MAPPER",
|
||||
Type = "test",
|
||||
});
|
||||
}
|
||||
|
||||
req.TriggerSuccess(bundle);
|
||||
return true;
|
||||
};
|
||||
});
|
||||
|
@ -4,62 +4,66 @@
|
||||
#nullable disable
|
||||
|
||||
using System;
|
||||
using NUnit.Framework;
|
||||
using osu.Framework.Allocation;
|
||||
using System.Linq;
|
||||
using osu.Framework.Graphics;
|
||||
using osu.Framework.Graphics.Containers;
|
||||
using osu.Framework.Graphics.Shapes;
|
||||
using osu.Game.Graphics.Containers;
|
||||
using osu.Game.Online.API.Requests.Responses;
|
||||
using osu.Game.Overlays;
|
||||
using osu.Game.Overlays.Comments;
|
||||
using osu.Game.Tests.Visual.UserInterface;
|
||||
|
||||
namespace osu.Game.Tests.Visual.Online
|
||||
{
|
||||
public partial class TestSceneDrawableComment : OsuTestScene
|
||||
public partial class TestSceneDrawableComment : ThemeComparisonTestScene
|
||||
{
|
||||
[Cached]
|
||||
private readonly OverlayColourProvider colourProvider = new OverlayColourProvider(OverlayColourScheme.Purple);
|
||||
|
||||
private Container container;
|
||||
|
||||
[SetUp]
|
||||
public void SetUp() => Schedule(() =>
|
||||
public TestSceneDrawableComment()
|
||||
: base(false)
|
||||
{
|
||||
Children = new Drawable[]
|
||||
{
|
||||
new Box
|
||||
{
|
||||
RelativeSizeAxes = Axes.Both,
|
||||
Colour = colourProvider.Background4,
|
||||
},
|
||||
container = new Container
|
||||
{
|
||||
RelativeSizeAxes = Axes.X,
|
||||
AutoSizeAxes = Axes.Y,
|
||||
},
|
||||
};
|
||||
});
|
||||
|
||||
[TestCaseSource(nameof(comments))]
|
||||
public void TestComment(string description, string text)
|
||||
{
|
||||
AddStep(description, () =>
|
||||
{
|
||||
comment.Pinned = description == "Pinned";
|
||||
comment.Message = text;
|
||||
container.Add(new DrawableComment(comment));
|
||||
});
|
||||
}
|
||||
|
||||
private static readonly Comment comment = new Comment
|
||||
protected override Drawable CreateContent() => new OsuScrollContainer(Direction.Vertical)
|
||||
{
|
||||
Id = 1,
|
||||
LegacyName = "Test User",
|
||||
CreatedAt = DateTimeOffset.Now,
|
||||
VotesCount = 0,
|
||||
RelativeSizeAxes = Axes.Both,
|
||||
Child = new FillFlowContainer
|
||||
{
|
||||
RelativeSizeAxes = Axes.X,
|
||||
AutoSizeAxes = Axes.Y,
|
||||
Direction = FillDirection.Vertical,
|
||||
ChildrenEnumerable = comments.Select(info =>
|
||||
{
|
||||
var comment = new Comment
|
||||
{
|
||||
Id = 1,
|
||||
UserId = 1000,
|
||||
User = new APIUser { Id = 1000, Username = "Someone" },
|
||||
CreatedAt = DateTimeOffset.Now,
|
||||
VotesCount = 0,
|
||||
Pinned = info[0] == "Pinned",
|
||||
Message = info[1],
|
||||
CommentableId = 2001,
|
||||
CommentableType = "test"
|
||||
};
|
||||
|
||||
return new[]
|
||||
{
|
||||
new DrawableComment(comment, Array.Empty<CommentableMeta>()),
|
||||
new DrawableComment(comment, new[]
|
||||
{
|
||||
new CommentableMeta
|
||||
{
|
||||
Id = 2001,
|
||||
OwnerId = comment.UserId,
|
||||
OwnerTitle = "MAPPER",
|
||||
Type = "test",
|
||||
},
|
||||
new CommentableMeta { Title = "Other Meta" },
|
||||
}),
|
||||
};
|
||||
}).SelectMany(c => c)
|
||||
}
|
||||
};
|
||||
|
||||
private static object[] comments =
|
||||
private static readonly string[][] comments =
|
||||
{
|
||||
new[] { "Plain", "This is plain comment" },
|
||||
new[] { "Pinned", "This is pinned comment" },
|
||||
|
@ -14,31 +14,39 @@ namespace osu.Game.Tests.Visual.UserInterface
|
||||
{
|
||||
public abstract partial class ThemeComparisonTestScene : OsuGridTestScene
|
||||
{
|
||||
protected ThemeComparisonTestScene()
|
||||
: base(1, 2)
|
||||
private readonly bool showNoColourProvider;
|
||||
|
||||
protected ThemeComparisonTestScene(bool showNoColourProvider = true)
|
||||
: base(1, showNoColourProvider ? 2 : 1)
|
||||
{
|
||||
this.showNoColourProvider = showNoColourProvider;
|
||||
}
|
||||
|
||||
[BackgroundDependencyLoader]
|
||||
private void load(OsuColour colours)
|
||||
{
|
||||
Cell(0, 0).AddRange(new[]
|
||||
if (showNoColourProvider)
|
||||
{
|
||||
new Box
|
||||
Cell(0, 0).AddRange(new[]
|
||||
{
|
||||
RelativeSizeAxes = Axes.Both,
|
||||
Colour = colours.GreySeaFoam
|
||||
},
|
||||
CreateContent()
|
||||
});
|
||||
new Box
|
||||
{
|
||||
RelativeSizeAxes = Axes.Both,
|
||||
Colour = colours.GreySeaFoam
|
||||
},
|
||||
CreateContent()
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
protected void CreateThemedContent(OverlayColourScheme colourScheme)
|
||||
{
|
||||
var colourProvider = new OverlayColourProvider(colourScheme);
|
||||
|
||||
Cell(0, 1).Clear();
|
||||
Cell(0, 1).Add(new DependencyProvidingContainer
|
||||
int col = showNoColourProvider ? 1 : 0;
|
||||
|
||||
Cell(0, col).Clear();
|
||||
Cell(0, col).Add(new DependencyProvidingContainer
|
||||
{
|
||||
RelativeSizeAxes = Axes.Both,
|
||||
CachedDependencies = new (Type, object)[]
|
||||
|
Loading…
Reference in New Issue
Block a user