From 2f551be1befa1fd1d0c6d8b6387bc023a3fd0efe Mon Sep 17 00:00:00 2001
From: ansel <79257300125@ya.ru>
Date: Tue, 27 Sep 2022 19:03:02 +0300
Subject: [PATCH] Implement tests

---
 .../Visual/Online/TestSceneCommentActions.cs  | 73 ++++++++++++++++++-
 1 file changed, 72 insertions(+), 1 deletion(-)

diff --git a/osu.Game.Tests/Visual/Online/TestSceneCommentActions.cs b/osu.Game.Tests/Visual/Online/TestSceneCommentActions.cs
index 2778cb509a..dcab92d772 100644
--- a/osu.Game.Tests/Visual/Online/TestSceneCommentActions.cs
+++ b/osu.Game.Tests/Visual/Online/TestSceneCommentActions.cs
@@ -3,20 +3,23 @@
 
 using System;
 using System.Collections.Generic;
+using System.Linq;
 using NUnit.Framework;
 using osu.Framework.Allocation;
 using osu.Framework.Graphics;
 using osu.Framework.Graphics.Containers;
 using osu.Framework.Testing;
+using osu.Game.Graphics.Sprites;
 using osu.Game.Online.API;
 using osu.Game.Online.API.Requests;
 using osu.Game.Online.API.Requests.Responses;
 using osu.Game.Overlays;
 using osu.Game.Overlays.Comments;
+using osuTK.Input;
 
 namespace osu.Game.Tests.Visual.Online
 {
-    public class TestSceneCommentActions : OsuTestScene
+    public class TestSceneCommentActions : OsuManualInputManagerTestScene
     {
         private DummyAPIAccess dummyAPI => (DummyAPIAccess)API;
 
@@ -51,12 +54,80 @@ namespace osu.Game.Tests.Visual.Online
         public void TestNonOwnCommentCantBeDeleted()
         {
             addTestComments();
+
+            AddAssert("First comment has button", () =>
+            {
+                var comments = this.ChildrenOfType<DrawableComment>();
+                var ourComment = comments.Single(x => x.Comment.Id == 1);
+                return ourComment.ChildrenOfType<OsuSpriteText>().Any(x => x.Text == "Delete");
+            });
+
+            AddAssert("Second doesn't", () =>
+            {
+                var comments = this.ChildrenOfType<DrawableComment>();
+                var ourComment = comments.Single(x => x.Comment.Id == 2);
+                return ourComment.ChildrenOfType<OsuSpriteText>().All(x => x.Text != "Delete");
+            });
         }
 
         [Test]
         public void TestDeletion()
         {
+            DrawableComment ourComment = null!;
+            bool delete = false;
+
             addTestComments();
+            AddStep("Comment exists", () =>
+            {
+                var comments = this.ChildrenOfType<DrawableComment>();
+                ourComment = comments.Single(x => x.Comment.Id == 1);
+            });
+            AddStep("It has delete button", () =>
+            {
+                var btn = ourComment.ChildrenOfType<OsuSpriteText>().Single(x => x.Text == "Delete");
+                InputManager.MoveMouseTo(btn);
+            });
+            AddStep("Click delete button", () =>
+            {
+                InputManager.Click(MouseButton.Left);
+            });
+            AddStep("Setup request handling", () =>
+            {
+                dummyAPI.HandleRequest = request =>
+                {
+                    if (!(request is CommentDeleteRequest req))
+                        return false;
+
+                    if (req.ID != 1)
+                        return false;
+
+                    CommentBundle cb = new CommentBundle
+                    {
+                        Comments = new List<Comment>
+                        {
+                            new Comment
+                            {
+                                Id = 2,
+                                Message = "This is a comment by another user",
+                                UserId = API.LocalUser.Value.Id + 1,
+                                CreatedAt = DateTimeOffset.Now,
+                                User = new APIUser
+                                {
+                                    Id = API.LocalUser.Value.Id + 1,
+                                    Username = "Another user"
+                                }
+                            },
+                        },
+                        IncludedComments = new List<Comment>(),
+                        PinnedComments = new List<Comment>(),
+                    };
+                    delete = true;
+                    req.TriggerSuccess(cb);
+                    return true;
+                };
+            });
+            AddStep("Confirm dialog", () => InputManager.Key(Key.Number1));
+            AddUntilStep("Deletion requested", () => delete);
         }
 
         private void addTestComments()