File tree Expand file tree Collapse file tree 2 files changed +26
-4
lines changed
src/LinkDotNet.Blog.Web/Features/Components
tests/LinkDotNet.Blog.UnitTests/Web/Features/Components Expand file tree Collapse file tree 2 files changed +26
-4
lines changed Original file line number Diff line number Diff line change 2
2
3
3
<HeadContent >
4
4
<meta name =" title" property =" og:title" content =" @Title" />
5
- <link rel =" canonical" href =" @NavigationManager.Uri " />
5
+ <link rel =" canonical" href =" @GetCanoncialUri() " />
6
6
@if (AbsolutePreviewImageUrl != null )
7
7
{
8
8
<meta name =" image" property =" og:image" content =" @AbsolutePreviewImageUrl" />
25
25
26
26
[Parameter ]
27
27
public string AbsolutePreviewImageUrl { get ; set ; }
28
-
28
+
29
29
[Parameter ]
30
30
public string Description { get ; set ; }
31
-
31
+
32
32
[Parameter ]
33
33
public string Keywords { get ; set ; }
34
+
35
+ private string GetCanoncialUri ()
36
+ {
37
+ var uri = new Uri (NavigationManager .Uri );
38
+ return uri .GetLeftPart (UriPartial .Path );
39
+ }
40
+
34
41
}
Original file line number Diff line number Diff line change @@ -42,16 +42,31 @@ public void ShouldNotSetMetaInformationWhenNotProvided()
42
42
[ Fact ]
43
43
public void ShouldSetCanoncialLink ( )
44
44
{
45
+ const string expectedUri = "https://steven.com/test" ;
46
+ Services . GetRequiredService < NavigationManager > ( ) . NavigateTo ( expectedUri ) ;
45
47
ComponentFactories . AddStub < HeadContent > ( ps => ps . Get ( p => p . ChildContent ) ) ;
46
48
47
49
var cut = RenderComponent < OgData > ( p => p
48
50
. Add ( s => s . Title , "Title" ) ) ;
49
51
50
52
var link = cut . FindAll ( "link" ) . FirstOrDefault ( l => l . Attributes . Any ( a => a . Name == "rel" && a . Value == "canonical" ) ) as IHtmlLinkElement ;
51
- var expectedUri = Services . GetRequiredService < NavigationManager > ( ) . Uri ;
53
+
52
54
link . Href . Should ( ) . Be ( expectedUri ) ;
53
55
}
54
56
57
+ [ Fact ]
58
+ public void ShouldSetCanoncialLinkWithoutQueryParameter ( )
59
+ {
60
+ ComponentFactories . AddStub < HeadContent > ( ps => ps . Get ( p => p . ChildContent ) ) ;
61
+ Services . GetRequiredService < NavigationManager > ( ) . NavigateTo ( "https://localhost.com/site?query=2" ) ;
62
+
63
+ var cut = RenderComponent < OgData > ( p => p
64
+ . Add ( s => s . Title , "Title" ) ) ;
65
+
66
+ var link = cut . FindAll ( "link" ) . FirstOrDefault ( l => l . Attributes . Any ( a => a . Name == "rel" && a . Value == "canonical" ) ) as IHtmlLinkElement ;
67
+ link . Href . Should ( ) . Be ( "https://localhost.com/site" ) ;
68
+ }
69
+
55
70
private static void AssertMetaTagExistsWithValue (
56
71
IRenderedFragment cut ,
57
72
string metaTag ,
You can’t perform that action at this time.
0 commit comments