mirror of
https://github.com/ppy/osu.git
synced 2025-01-06 08:22:56 +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)
|
private void setUpCommentsResponse(CommentBundle commentBundle)
|
||||||
=> AddStep("set up response", () =>
|
=> 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", () =>
|
=> AddStep("set up response", () =>
|
||||||
{
|
{
|
||||||
dummyAPI.HandleRequest = request =>
|
dummyAPI.HandleRequest = request =>
|
||||||
@ -191,7 +209,7 @@ namespace osu.Game.Tests.Visual.Online
|
|||||||
if (!(request is CommentPostRequest req))
|
if (!(request is CommentPostRequest req))
|
||||||
return false;
|
return false;
|
||||||
|
|
||||||
req.TriggerSuccess(new CommentBundle
|
var bundle = new CommentBundle
|
||||||
{
|
{
|
||||||
Comments = new List<Comment>
|
Comments = new List<Comment>
|
||||||
{
|
{
|
||||||
@ -202,9 +220,26 @@ namespace osu.Game.Tests.Visual.Online
|
|||||||
LegacyName = "FirstUser",
|
LegacyName = "FirstUser",
|
||||||
CreatedAt = DateTimeOffset.Now,
|
CreatedAt = DateTimeOffset.Now,
|
||||||
VotesCount = 98,
|
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;
|
return true;
|
||||||
};
|
};
|
||||||
});
|
});
|
||||||
|
@ -4,62 +4,66 @@
|
|||||||
#nullable disable
|
#nullable disable
|
||||||
|
|
||||||
using System;
|
using System;
|
||||||
using NUnit.Framework;
|
using System.Linq;
|
||||||
using osu.Framework.Allocation;
|
|
||||||
using osu.Framework.Graphics;
|
using osu.Framework.Graphics;
|
||||||
using osu.Framework.Graphics.Containers;
|
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.Online.API.Requests.Responses;
|
||||||
using osu.Game.Overlays;
|
|
||||||
using osu.Game.Overlays.Comments;
|
using osu.Game.Overlays.Comments;
|
||||||
|
using osu.Game.Tests.Visual.UserInterface;
|
||||||
|
|
||||||
namespace osu.Game.Tests.Visual.Online
|
namespace osu.Game.Tests.Visual.Online
|
||||||
{
|
{
|
||||||
public partial class TestSceneDrawableComment : OsuTestScene
|
public partial class TestSceneDrawableComment : ThemeComparisonTestScene
|
||||||
{
|
{
|
||||||
[Cached]
|
public TestSceneDrawableComment()
|
||||||
private readonly OverlayColourProvider colourProvider = new OverlayColourProvider(OverlayColourScheme.Purple);
|
: base(false)
|
||||||
|
|
||||||
private Container container;
|
|
||||||
|
|
||||||
[SetUp]
|
|
||||||
public void SetUp() => Schedule(() =>
|
|
||||||
{
|
{
|
||||||
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,
|
RelativeSizeAxes = Axes.Both,
|
||||||
LegacyName = "Test User",
|
Child = new FillFlowContainer
|
||||||
CreatedAt = DateTimeOffset.Now,
|
{
|
||||||
VotesCount = 0,
|
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[] { "Plain", "This is plain comment" },
|
||||||
new[] { "Pinned", "This is pinned comment" },
|
new[] { "Pinned", "This is pinned comment" },
|
||||||
|
@ -14,31 +14,39 @@ namespace osu.Game.Tests.Visual.UserInterface
|
|||||||
{
|
{
|
||||||
public abstract partial class ThemeComparisonTestScene : OsuGridTestScene
|
public abstract partial class ThemeComparisonTestScene : OsuGridTestScene
|
||||||
{
|
{
|
||||||
protected ThemeComparisonTestScene()
|
private readonly bool showNoColourProvider;
|
||||||
: base(1, 2)
|
|
||||||
|
protected ThemeComparisonTestScene(bool showNoColourProvider = true)
|
||||||
|
: base(1, showNoColourProvider ? 2 : 1)
|
||||||
{
|
{
|
||||||
|
this.showNoColourProvider = showNoColourProvider;
|
||||||
}
|
}
|
||||||
|
|
||||||
[BackgroundDependencyLoader]
|
[BackgroundDependencyLoader]
|
||||||
private void load(OsuColour colours)
|
private void load(OsuColour colours)
|
||||||
{
|
{
|
||||||
Cell(0, 0).AddRange(new[]
|
if (showNoColourProvider)
|
||||||
{
|
{
|
||||||
new Box
|
Cell(0, 0).AddRange(new[]
|
||||||
{
|
{
|
||||||
RelativeSizeAxes = Axes.Both,
|
new Box
|
||||||
Colour = colours.GreySeaFoam
|
{
|
||||||
},
|
RelativeSizeAxes = Axes.Both,
|
||||||
CreateContent()
|
Colour = colours.GreySeaFoam
|
||||||
});
|
},
|
||||||
|
CreateContent()
|
||||||
|
});
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
protected void CreateThemedContent(OverlayColourScheme colourScheme)
|
protected void CreateThemedContent(OverlayColourScheme colourScheme)
|
||||||
{
|
{
|
||||||
var colourProvider = new OverlayColourProvider(colourScheme);
|
var colourProvider = new OverlayColourProvider(colourScheme);
|
||||||
|
|
||||||
Cell(0, 1).Clear();
|
int col = showNoColourProvider ? 1 : 0;
|
||||||
Cell(0, 1).Add(new DependencyProvidingContainer
|
|
||||||
|
Cell(0, col).Clear();
|
||||||
|
Cell(0, col).Add(new DependencyProvidingContainer
|
||||||
{
|
{
|
||||||
RelativeSizeAxes = Axes.Both,
|
RelativeSizeAxes = Axes.Both,
|
||||||
CachedDependencies = new (Type, object)[]
|
CachedDependencies = new (Type, object)[]
|
||||||
|
Loading…
Reference in New Issue
Block a user