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 11
11
12
12
private async Task CopyToClipboard ()
13
13
{
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
+ }
16
24
}
17
25
}
Original file line number Diff line number Diff line change 6
6
</PropertyGroup >
7
7
8
8
<ItemGroup >
9
- <PackageReference Include =" bunit" Version =" 1.3.42 " />
9
+ <PackageReference Include =" bunit" Version =" 1.4.15 " />
10
10
<PackageReference Include =" FluentAssertions" Version =" 6.2.0" />
11
11
<PackageReference Include =" Microsoft.AspNetCore.Mvc.Testing" Version =" 6.0.1" />
12
12
<PackageReference Include =" Microsoft.EntityFrameworkCore.Sqlite" Version =" 6.0.1" />
Original file line number Diff line number Diff line change 7
7
</PropertyGroup >
8
8
9
9
<ItemGroup >
10
- <PackageReference Include =" bunit" Version =" 1.3.42 " />
10
+ <PackageReference Include =" bunit" Version =" 1.4.15 " />
11
11
<PackageReference Include =" FluentAssertions" Version =" 6.2.0" />
12
12
<PackageReference Include =" Microsoft.NET.Test.Sdk" Version =" 17.1.0-preview-20211130-02" />
13
13
<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 ;
2
3
using AngleSharp . Html . Dom ;
3
4
using AngleSharpWrappers ;
4
5
using Blazored . Toast . Services ;
@@ -39,4 +40,16 @@ public void ShouldShareToLinkedIn()
39
40
var linkedInShare = ( IHtmlAnchorElement ) cut . Find ( "#share-linkedin" ) . Unwrap ( ) ;
40
41
linkedInShare . Href . Should ( ) . Be ( "https://www.linkedin.com/shareArticle?mini=true&url=http://localhost/blogPost/1" ) ;
41
42
}
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
+ }
42
55
}
You can’t perform that action at this time.
0 commit comments