From c384093802edbbe0147a66a226125c6b02638a9f Mon Sep 17 00:00:00 2001
From: ansel <79257300125@ya.ru>
Date: Sat, 8 Oct 2022 18:53:41 +0300
Subject: [PATCH] Update main test and add failure scenario test

---
 .../Visual/Online/TestSceneCommentActions.cs  | 52 ++++++++++++++++++-
 osu.Game/Overlays/Comments/DrawableComment.cs |  1 +
 2 files changed, 52 insertions(+), 1 deletion(-)

diff --git a/osu.Game.Tests/Visual/Online/TestSceneCommentActions.cs b/osu.Game.Tests/Visual/Online/TestSceneCommentActions.cs
index 8f9e2f6ba4..11210db8a9 100644
--- a/osu.Game.Tests/Visual/Online/TestSceneCommentActions.cs
+++ b/osu.Game.Tests/Visual/Online/TestSceneCommentActions.cs
@@ -140,7 +140,57 @@ namespace osu.Game.Tests.Visual.Online
             AddAssert("Loading spinner shown", () => commentsContainer.ChildrenOfType<LoadingSpinner>().Any(d => d.IsPresent));
             AddUntilStep("Comment is deleted locally", () =>
             {
-                return this.ChildrenOfType<DrawableComment>().SingleOrDefault(x => x.Comment.Id == 1) == null;
+                return this.ChildrenOfType<DrawableComment>().Single(x => x.Comment.Id == 1).WasDeleted;
+            });
+        }
+
+        [Test]
+        public void TestDeletionFail()
+        {
+            DrawableComment? ourComment = null;
+            bool delete = false;
+
+            addTestComments();
+            AddUntilStep("Comment exists", () =>
+            {
+                var comments = this.ChildrenOfType<DrawableComment>();
+                ourComment = comments.SingleOrDefault(x => x.Comment.Id == 1);
+                return ourComment != null;
+            });
+            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 not CommentDeleteRequest req)
+                        return false;
+
+                    req.TriggerFailure(new Exception());
+                    delete = true;
+                    return false;
+                };
+            });
+            AddStep("Confirm dialog", () => InputManager.Key(Key.Number1));
+            AddUntilStep("Deletion requested", () => delete);
+            AddUntilStep("Comment is available", () =>
+            {
+                return !this.ChildrenOfType<DrawableComment>().Single(x => x.Comment.Id == 1).WasDeleted;
+            });
+            AddAssert("Loading spinner hidden", () =>
+            {
+                return ourComment.ChildrenOfType<LoadingSpinner>().All(d => !d.IsPresent);
+            });
+            AddAssert("Actions available", () =>
+            {
+                return ourComment.ChildrenOfType<LinkFlowContainer>().Single(x => x.Name == @"Actions buttons").IsPresent;
             });
         }
 
diff --git a/osu.Game/Overlays/Comments/DrawableComment.cs b/osu.Game/Overlays/Comments/DrawableComment.cs
index 00a832cac8..105618c728 100644
--- a/osu.Game/Overlays/Comments/DrawableComment.cs
+++ b/osu.Game/Overlays/Comments/DrawableComment.cs
@@ -201,6 +201,7 @@ namespace osu.Game.Overlays.Comments
                                                         },
                                                         actionsContainer = new LinkFlowContainer(s => s.Font = OsuFont.GetFont(size: 12, weight: FontWeight.Bold))
                                                         {
+                                                            Name = @"Actions buttons",
                                                             AutoSizeAxes = Axes.Both,
                                                             Spacing = new Vector2(10, 0)
                                                         },