diff --git a/README.md b/README.md index 91918cc6e..a77d6cfb9 100644 --- a/README.md +++ b/README.md @@ -3,13 +3,12 @@

A set of enterprise-class UI components based on Bootstrap and Blazor.

- -[![Github build](https://img.shields.io/github/workflow/status/ArgoZhang/BootstrapBlazor/Build%20Project/main?label=main&logo=github&logoColor=green)](https://github.com/ArgoZhang/BootstrapBlazor/actions?query=workflow%3A%22Build+Project%22+branch%3Amain) +[![License](https://img.shields.io/github/license/argozhang/bootstrapblazor.svg?logo=git&logoColor=red)](https://github.com/ArgoZhang/BootstrapBlazor/blob/main/LICENSE) [![Nuget](https://img.shields.io/nuget/v/BootstrapBlazor.svg?color=red&logo=nuget&logoColor=green)](https://www.nuget.org/packages/BootstrapBlazor/) [![Nuget](https://img.shields.io/nuget/dt/BootstrapBlazor.svg?logo=nuget&logoColor=green)](https://www.nuget.org/packages/BootstrapBlazor/) -[![Github](https://img.shields.io/github/license/argozhang/bootstrapblazor.svg?logo=git&logoColor=red)](https://github.com/ArgoZhang/BootstrapBlazor/blob/main/LICENSE) [![Repo Size](https://img.shields.io/github/repo-size/ArgoZhang/BootstrapBlazor.svg?logo=github&logoColor=green&label=repo)](https://github.com/ArgoZhang/BootstrapBlazor) [![Commit Date](https://img.shields.io/github/last-commit/ArgoZhang/BootstrapBlazor/main.svg?logo=github&logoColor=green&label=commit)](https://github.com/ArgoZhang/BootstrapBlazor) +[![Github build](https://img.shields.io/github/workflow/status/ArgoZhang/BootstrapBlazor/Build%20Project/main?label=main&logo=github&logoColor=green)](https://github.com/ArgoZhang/BootstrapBlazor/actions?query=workflow%3A%22Build+Project%22+branch%3Amain) [![codecov](https://codecov.io/gh/dotnetcore/BootstrapBlazor/branch/main/graph/badge.svg?token=5SXIWHXZC3)](https://codecov.io/gh/dotnetcore/BootstrapBlazor)
diff --git a/README.zh-CN.md b/README.zh-CN.md index f3e5729b9..f6bf580e0 100644 --- a/README.zh-CN.md +++ b/README.zh-CN.md @@ -3,12 +3,12 @@

一套基于 Bootstrap 和 Blazor 的企业级组件库

-[![Github build](https://img.shields.io/github/workflow/status/ArgoZhang/BootstrapBlazor/Build%20Project/main?label=main&logo=github&logoColor=green)](https://github.com/ArgoZhang/BootstrapBlazor/actions?query=workflow%3A%22Build+Project%22+branch%3Amain) +[![License](https://img.shields.io/github/license/argozhang/bootstrapblazor.svg?logo=git&logoColor=red)](https://github.com/ArgoZhang/BootstrapBlazor/blob/main/LICENSE) [![Nuget](https://img.shields.io/nuget/v/BootstrapBlazor.svg?color=red&logo=nuget&logoColor=green)](https://www.nuget.org/packages/BootstrapBlazor/) [![Nuget](https://img.shields.io/nuget/dt/BootstrapBlazor.svg?logo=nuget&logoColor=green)](https://www.nuget.org/packages/BootstrapBlazor/) -[![Github](https://img.shields.io/github/license/argozhang/bootstrapblazor.svg?logo=git&logoColor=red)](https://github.com/ArgoZhang/BootstrapBlazor/blob/main/LICENSE) [![Repo Size](https://img.shields.io/github/repo-size/ArgoZhang/BootstrapBlazor.svg?logo=github&logoColor=green&label=repo)](https://github.com/ArgoZhang/BootstrapBlazor) [![Commit Date](https://img.shields.io/github/last-commit/ArgoZhang/BootstrapBlazor/main.svg?logo=github&logoColor=green&label=commit)](https://github.com/ArgoZhang/BootstrapBlazor) +[![Github build](https://img.shields.io/github/workflow/status/ArgoZhang/BootstrapBlazor/Build%20Project/main?label=main&logo=github&logoColor=green)](https://github.com/ArgoZhang/BootstrapBlazor/actions?query=workflow%3A%22Build+Project%22+branch%3Amain) [![codecov](https://codecov.io/gh/dotnetcore/BootstrapBlazor/branch/main/graph/badge.svg?token=5SXIWHXZC3)](https://codecov.io/gh/dotnetcore/BootstrapBlazor)
diff --git a/src/BootstrapBlazor/Components/Print/Print.cs b/src/BootstrapBlazor/Components/Print/Print.cs index 33236f244..e56ab314e 100644 --- a/src/BootstrapBlazor/Components/Print/Print.cs +++ b/src/BootstrapBlazor/Components/Print/Print.cs @@ -42,11 +42,7 @@ namespace BootstrapBlazor.Components PrintService.Register(this, PrintDialogAsync); } - private Task PrintDialogAsync(DialogOption option) - { - DialogService.Show(option); - return Task.CompletedTask; - } + private Task PrintDialogAsync(DialogOption option) => DialogService.Show(option); /// /// Dispose 方法 diff --git a/src/BootstrapBlazor/Components/Print/PrintButton.razor.cs b/src/BootstrapBlazor/Components/Print/PrintButton.razor.cs index 3e4addf6e..5bd8dcdd9 100644 --- a/src/BootstrapBlazor/Components/Print/PrintButton.razor.cs +++ b/src/BootstrapBlazor/Components/Print/PrintButton.razor.cs @@ -42,15 +42,14 @@ namespace BootstrapBlazor.Components protected override void OnParametersSet() { // 不需要走 base.OnParametersSet 方法 + AdditionalAttributes ??= new Dictionary(); if (string.IsNullOrEmpty(PreviewUrl)) { - AdditionalAttributes ??= new Dictionary(); AdditionalAttributes.Add("onclick", "$.bb_printview(this)"); Target = null; } else { - AdditionalAttributes ??= new Dictionary(); AdditionalAttributes.Remove("onclick", out _); Target = "_blank"; } diff --git a/test/UnitTest/Components/PrintTest.cs b/test/UnitTest/Components/PrintTest.cs new file mode 100644 index 000000000..b33f744ad --- /dev/null +++ b/test/UnitTest/Components/PrintTest.cs @@ -0,0 +1,77 @@ +// Copyright (c) Argo Zhang (argo@163.com). All rights reserved. +// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. +// Website: https://www.blazor.zone or https://argozhang.github.io/ + +using BootstrapBlazor.Components; +using Bunit; +using Microsoft.AspNetCore.Components; +using Microsoft.Extensions.DependencyInjection; +using System; +using System.Collections.Generic; +using System.Diagnostics.CodeAnalysis; +using System.Threading.Tasks; +using System.Web; +using UnitTest.Core; +using Xunit; + +namespace UnitTest.Components +{ + public class PrintTest : BootstrapBlazorTestBase + { + [Fact] + public void PrintButton_Ok() + { + var cut = Context.RenderComponent(pb => + { + pb.AddChildContent(); + }); + Assert.Contains("打印", HttpUtility.HtmlDecode(cut.Markup)); + + var button = cut.FindComponent(); + button.SetParametersAndRender(pb => + { + pb.Add(b => b.PreviewUrl, "/PrintTest"); + }); + Assert.Contains("href=\"/PrintTest\"", button.Markup); + } + + [Fact] + public void PrintService_Error() + { + var cut = Context.RenderComponent(); + var printService = cut.Services.CreateScope().ServiceProvider.GetRequiredService(); + Assert.ThrowsAsync(() => printService.PrintAsync