File tree Expand file tree Collapse file tree 4 files changed +26
-5
lines changed
src/LinkDotNet.Blog.Web/Shared
LinkDotNet.Blog.IntegrationTests
LinkDotNet.Blog.UnitTests Expand file tree Collapse file tree 4 files changed +26
-5
lines changed Original file line number Diff line number Diff line change 1111
1212 private async Task CopyToClipboard ()
1313 {
14- await jsRuntime .InvokeVoidAsync (" navigator.clipboard.writeText" , navigationManager .Uri );
15- toastService .ShowSuccess (" Copied link to clipboard" );
14+ try
15+ {
16+ await jsRuntime .InvokeVoidAsync (" navigator.clipboard.writeText" , navigationManager .Uri );
17+ toastService .ShowSuccess (" Copied link to clipboard" );
18+ }
19+ catch (Exception e )
20+ {
21+ toastService .ShowError (" There was an error copying the link. Please copy the link from your address bar instead." );
22+ Console .WriteLine (e );
23+ }
1624 }
1725}
Original file line number Diff line number Diff line change 66 </PropertyGroup >
77
88 <ItemGroup >
9- <PackageReference Include =" bunit" Version =" 1.3.42 " />
9+ <PackageReference Include =" bunit" Version =" 1.4.15 " />
1010 <PackageReference Include =" FluentAssertions" Version =" 6.2.0" />
1111 <PackageReference Include =" Microsoft.AspNetCore.Mvc.Testing" Version =" 6.0.1" />
1212 <PackageReference Include =" Microsoft.EntityFrameworkCore.Sqlite" Version =" 6.0.1" />
Original file line number Diff line number Diff line change 77 </PropertyGroup >
88
99 <ItemGroup >
10- <PackageReference Include =" bunit" Version =" 1.3.42 " />
10+ <PackageReference Include =" bunit" Version =" 1.4.15 " />
1111 <PackageReference Include =" FluentAssertions" Version =" 6.2.0" />
1212 <PackageReference Include =" Microsoft.NET.Test.Sdk" Version =" 17.1.0-preview-20211130-02" />
1313 <PackageReference Include =" Moq" Version =" 4.16.1" />
Original file line number Diff line number Diff line change 1- using System . Linq ;
1+ using System ;
2+ using System . Linq ;
23using AngleSharp . Html . Dom ;
34using AngleSharpWrappers ;
45using Blazored . Toast . Services ;
@@ -39,4 +40,16 @@ public void ShouldShareToLinkedIn()
3940 var linkedInShare = ( IHtmlAnchorElement ) cut . Find ( "#share-linkedin" ) . Unwrap ( ) ;
4041 linkedInShare . Href . Should ( ) . Be ( "https://www.linkedin.com/shareArticle?mini=true&url=http://localhost/blogPost/1" ) ;
4142 }
43+
44+ [ Fact ]
45+ public void ShouldNotCrashWhenCopyingLinkNotWorking ( )
46+ {
47+ Services . AddScoped ( _ => new Mock < IToastService > ( ) . Object ) ;
48+ JSInterop . SetupVoid ( s => s . InvocationMethodName == "navigator.clipboard.writeText" ) . SetException ( new Exception ( ) ) ;
49+ var cut = RenderComponent < ShareBlogPost > ( ) ;
50+
51+ var act = ( ) => cut . Find ( "#share-clipboard" ) . Click ( ) ;
52+
53+ act . Should ( ) . NotThrow < Exception > ( ) ;
54+ }
4255}
You can’t perform that action at this time.
0 commit comments