1
1
using System ;
2
2
using System . Linq ;
3
3
using AngleSharp . Html . Dom ;
4
- using Blazored . Toast . Services ;
5
4
using LinkDotNet . Blog . Web . Features . ShowBlogPost . Components ;
6
5
using Microsoft . Extensions . DependencyInjection ;
7
6
@@ -12,38 +11,25 @@ public class ShareBlogPostTests : TestContext
12
11
[ Fact ]
13
12
public void ShouldCopyLinkToClipboard ( )
14
13
{
15
- JSInterop . Mode = JSRuntimeMode . Loose ;
16
- Services . AddScoped ( _ => Substitute . For < IToastService > ( ) ) ;
17
14
Services . GetRequiredService < FakeNavigationManager > ( ) . NavigateTo ( "blogPost/1" ) ;
18
15
var cut = RenderComponent < ShareBlogPost > ( ) ;
19
16
20
- cut . Find ( "#share-clipboard" ) . Click ( ) ;
17
+ var element = cut . Find ( "#share-clipboard" ) as IHtmlAnchorElement ;
21
18
22
- var copyToClipboardInvocation = JSInterop . Invocations . SingleOrDefault ( i => i . Identifier == "navigator.clipboard.writeText" ) ;
23
- copyToClipboardInvocation . Arguments [ 0 ] . Should ( ) . Be ( "http://localhost/blogPost/1" ) ;
19
+ element . Should ( ) . NotBeNull ( ) ;
20
+ var onclick = element ! . Attributes . FirstOrDefault ( a => a . Name . Equals ( "onclick" , StringComparison . InvariantCultureIgnoreCase ) ) ;
21
+ onclick . Should ( ) . NotBeNull ( ) ;
22
+ onclick ! . Value . Should ( ) . Contain ( "blogPost/1" ) ;
24
23
}
25
24
26
25
[ Fact ]
27
26
public void ShouldShareToLinkedIn ( )
28
27
{
29
- Services . AddScoped ( _ => Substitute . For < IToastService > ( ) ) ;
30
28
Services . GetRequiredService < FakeNavigationManager > ( ) . NavigateTo ( "blogPost/1" ) ;
31
29
32
30
var cut = RenderComponent < ShareBlogPost > ( ) ;
33
31
34
32
var linkedInShare = ( IHtmlAnchorElement ) cut . Find ( "#share-linkedin" ) ;
35
33
linkedInShare . Href . Should ( ) . Be ( "https://www.linkedin.com/shareArticle?mini=true&url=http://localhost/blogPost/1" ) ;
36
34
}
37
-
38
- [ Fact ]
39
- public void ShouldNotCrashWhenCopyingLinkNotWorking ( )
40
- {
41
- Services . AddScoped ( _ => Substitute . For < IToastService > ( ) ) ;
42
- JSInterop . SetupVoid ( s => s . InvocationMethodName == "navigator.clipboard.writeText" ) . SetException ( new Exception ( ) ) ;
43
- var cut = RenderComponent < ShareBlogPost > ( ) ;
44
-
45
- var act = ( ) => cut . Find ( "#share-clipboard" ) . Click ( ) ;
46
-
47
- act . Should ( ) . NotThrow < Exception > ( ) ;
48
- }
49
35
}
0 commit comments