diff --git a/LinkDotNet.Blog.IntegrationTests/LinkDotNet.Blog.IntegrationTests.csproj b/LinkDotNet.Blog.IntegrationTests/LinkDotNet.Blog.IntegrationTests.csproj index bcdea410..eb50158f 100644 --- a/LinkDotNet.Blog.IntegrationTests/LinkDotNet.Blog.IntegrationTests.csproj +++ b/LinkDotNet.Blog.IntegrationTests/LinkDotNet.Blog.IntegrationTests.csproj @@ -11,6 +11,7 @@ + all runtime; build; native; contentfiles; analyzers; buildtransitive diff --git a/LinkDotNet.Blog.IntegrationTests/Web/Shared/Admin/BlogPostAdminActionsTests.cs b/LinkDotNet.Blog.IntegrationTests/Web/Shared/Admin/BlogPostAdminActionsTests.cs new file mode 100644 index 00000000..30d8f89f --- /dev/null +++ b/LinkDotNet.Blog.IntegrationTests/Web/Shared/Admin/BlogPostAdminActionsTests.cs @@ -0,0 +1,67 @@ +using Blazored.Toast.Services; +using Bunit; +using Bunit.TestDoubles; +using FluentAssertions; +using LinkDotNet.Blog.Web.Shared.Admin; +using LinkDotNet.Infrastructure.Persistence; +using Microsoft.AspNetCore.Components; +using Microsoft.Extensions.DependencyInjection; +using Moq; +using Xunit; + +namespace LinkDotNet.Blog.IntegrationTests.Web.Shared.Admin +{ + public class BlogPostAdminActionsTests + { + [Fact] + public void ShouldDeleteBlogPostWhenOkClicked() + { + const string blogPostId = "2"; + var repositoryMock = new Mock(); + using var ctx = new TestContext(); + ctx.AddTestAuthorization().SetAuthorized("s"); + ctx.Services.AddSingleton(repositoryMock.Object); + ctx.Services.AddSingleton(new Mock().Object); + var cut = ctx.RenderComponent(s => s.Add(p => p.BlogPostId, blogPostId)); + cut.Find("#delete-blogpost").Click(); + + cut.Find("#ok").Click(); + + repositoryMock.Verify(r => r.DeleteAsync(blogPostId), Times.Once); + } + + [Fact] + public void ShouldNotDeleteBlogPostWhenCancelClicked() + { + const string blogPostId = "2"; + var repositoryMock = new Mock(); + using var ctx = new TestContext(); + ctx.AddTestAuthorization().SetAuthorized("s"); + ctx.Services.AddSingleton(repositoryMock.Object); + ctx.Services.AddSingleton(new Mock().Object); + var cut = ctx.RenderComponent(s => s.Add(p => p.BlogPostId, blogPostId)); + cut.Find("#delete-blogpost").Click(); + + cut.Find("#cancel").Click(); + + repositoryMock.Verify(r => r.DeleteAsync(blogPostId), Times.Never); + } + + [Fact] + public void ShouldGoToEditPageOnEditClick() + { + const string blogPostId = "2"; + var repositoryMock = new Mock(); + using var ctx = new TestContext(); + ctx.AddTestAuthorization().SetAuthorized("s"); + ctx.Services.AddSingleton(repositoryMock.Object); + ctx.Services.AddSingleton(new Mock().Object); + var navigationManager = ctx.Services.GetRequiredService(); + var cut = ctx.RenderComponent(s => s.Add(p => p.BlogPostId, blogPostId)); + + cut.Find("#edit-blogpost").Click(); + + navigationManager.Uri.Should().EndWith($"update/{blogPostId}"); + } + } +} \ No newline at end of file diff --git a/LinkDotNet.Blog.IntegrationTests/Web/Shared/ConfirmDialogTests.cs b/LinkDotNet.Blog.IntegrationTests/Web/Shared/ConfirmDialogTests.cs new file mode 100644 index 00000000..933008df --- /dev/null +++ b/LinkDotNet.Blog.IntegrationTests/Web/Shared/ConfirmDialogTests.cs @@ -0,0 +1,25 @@ +using Bunit; +using FluentAssertions; +using LinkDotNet.Blog.Web.Shared; +using Xunit; + +namespace LinkDotNet.Blog.IntegrationTests.Web.Shared +{ + public class ConfirmDialogTests + { + [Fact] + public void ShouldInvokeEventOnOkClick() + { + var okWasClicked = false; + using var ctx = new TestContext(); + var cut = ctx.RenderComponent( + b => b + .Add(p => p.OnYesPressed, _ => okWasClicked = true)); + cut.Instance.Open(); + + cut.Find("#ok").Click(); + + okWasClicked.Should().BeTrue(); + } + } +} \ No newline at end of file diff --git a/LinkDotNet.Blog.Web/Shared/Admin/BlogPostAdminActions.razor b/LinkDotNet.Blog.Web/Shared/Admin/BlogPostAdminActions.razor index e418f51c..2a20ad6d 100644 --- a/LinkDotNet.Blog.Web/Shared/Admin/BlogPostAdminActions.razor +++ b/LinkDotNet.Blog.Web/Shared/Admin/BlogPostAdminActions.razor @@ -5,9 +5,11 @@
- -
diff --git a/LinkDotNet.Blog.Web/Shared/ConfirmDialog.razor b/LinkDotNet.Blog.Web/Shared/ConfirmDialog.razor index f8c26410..4b2b82b1 100644 --- a/LinkDotNet.Blog.Web/Shared/ConfirmDialog.razor +++ b/LinkDotNet.Blog.Web/Shared/ConfirmDialog.razor @@ -1,8 +1,8 @@ 

@Content

- - + +
@@ -15,10 +15,7 @@ [Parameter] public EventCallback OnYesPressed { get; set; } - - [Parameter] - public EventCallback OnNoPressed { get; set; } - + private ModalDialog ModalDialog { get; set; } private async Task OnYesButtonPressed() @@ -27,13 +24,14 @@ await OnYesPressed.InvokeAsync(); } - private void OnNoButtonPressed() + public void Open() { - ModalDialog.Close(); + ModalDialog.Open(); } - public void Open() + private void OnNoButtonPressed() { - ModalDialog.Open(); + ModalDialog.Close(); } + } \ No newline at end of file