File tree Expand file tree Collapse file tree 4 files changed +63
-9
lines changed
LinkDotNet.Blog.UnitTests/Web/Shared Expand file tree Collapse file tree 4 files changed +63
-9
lines changed Original file line number Diff line number Diff line change
1
+ using System . Linq ;
2
+ using AngleSharp . Html . Dom ;
3
+ using Blazored . Toast . Services ;
4
+ using Bunit ;
5
+ using Bunit . TestDoubles ;
6
+ using FluentAssertions ;
7
+ using LinkDotNet . Blog . Web . Shared ;
8
+ using Microsoft . Extensions . DependencyInjection ;
9
+ using Moq ;
10
+ using Xunit ;
11
+
12
+ namespace LinkDotNet . Blog . UnitTests . Web . Shared ;
13
+
14
+ public class ShareBlogPostTests : TestContext
15
+ {
16
+ [ Fact ]
17
+ public void ShouldCopyLinkToClipboard ( )
18
+ {
19
+ JSInterop . Mode = JSRuntimeMode . Loose ;
20
+ Services . AddScoped ( _ => new Mock < IToastService > ( ) . Object ) ;
21
+ Services . GetRequiredService < FakeNavigationManager > ( ) . NavigateTo ( "blogPost/1" ) ;
22
+ var cut = RenderComponent < ShareBlogPost > ( ) ;
23
+
24
+ cut . FindAll ( "a" ) [ 1 ] . Click ( ) ;
25
+
26
+ var copyToClipboardInvocation = JSInterop . Invocations . SingleOrDefault ( i => i . Identifier == "navigator.clipboard.writeText" ) ;
27
+ copyToClipboardInvocation . Arguments [ 0 ] . Should ( ) . Be ( "http://localhost/blogPost/1" ) ;
28
+ }
29
+
30
+ [ Fact ]
31
+ public void ShouldShareToLinkedIn ( )
32
+ {
33
+ Services . AddScoped ( _ => new Mock < IToastService > ( ) . Object ) ;
34
+ Services . GetRequiredService < FakeNavigationManager > ( ) . NavigateTo ( "blogPost/1" ) ;
35
+
36
+ var cut = RenderComponent < ShareBlogPost > ( ) ;
37
+
38
+ var linkedInShare = ( IHtmlAnchorElement ) cut . FindAll ( "a" ) [ 0 ] ;
39
+ linkedInShare . Href . Should ( )
40
+ . Be ( "https://www.linkedin.com/shareArticle?mini=true&url=http://localhost/blogPost/1" ) ;
41
+ }
42
+ }
Original file line number Diff line number Diff line change 37
37
@( RenderMarkupString (BlogPost .Content ))
38
38
</div >
39
39
</div >
40
- <Like BlogPost =" @BlogPost" OnBlogPostLiked =" @UpdateLikes" ></Like >
40
+ <div class =" d-flex justify-content-between py-2" >
41
+ <Like BlogPost =" @BlogPost" OnBlogPostLiked =" @UpdateLikes" ></Like >
42
+ <ShareBlogPost ></ShareBlogPost >
43
+ </div >
41
44
<Giscus ></Giscus >
42
45
</div >
43
46
</div >
Load Diff This file was deleted.
Original file line number Diff line number Diff line change
1
+ @inject NavigationManager navigationManager
2
+ @inject IJSRuntime jsRuntime
3
+ @inject IToastService toastService
4
+
5
+ <div class =" flex-row" >
6
+ <a href =" @LinkedInShare" target =" _blank" ><i class =" fab fa-linkedin" ></i ></a >
7
+ <a href =" javascript:void(0)" @onclick =" CopyToClipboard" ><i class =" fas fa-link" ></i ></a >
8
+ </div >
9
+ @code {
10
+ private string LinkedInShare => $" https://www.linkedin.com/shareArticle?mini=true&url={navigationManager .Uri }" ;
11
+
12
+ private async Task CopyToClipboard ()
13
+ {
14
+ await jsRuntime .InvokeVoidAsync (" navigator.clipboard.writeText" , navigationManager .Uri );
15
+ toastService .ShowSuccess (" Copied link to clipboard" );
16
+ }
17
+ }
You can’t perform that action at this time.
0 commit comments