File tree Expand file tree Collapse file tree 2 files changed +39
-2
lines changed
src/LinkDotNet.Blog.Web/Shared
tests/LinkDotNet.Blog.IntegrationTests/Web/Shared Expand file tree Collapse file tree 2 files changed +39
-2
lines changed Original file line number Diff line number Diff line change 1
1
@inject AppConfiguration configuration
2
2
@inject NavigationManager navigationManager
3
+ @implements IDisposable
3
4
4
5
<nav class =" navbar navbar-expand-lg position-absolute navbar-background inverted-colors navbar-dark" style =" width : 100% " >
5
6
<div class =" container-fluid" >
29
30
me </a ></li >
30
31
}
31
32
32
- <AccessControl CurrentUri =" @navigationManager.Uri " ></AccessControl >
33
+ <AccessControl CurrentUri =" @currentUri " ></AccessControl >
33
34
<li class =" nav-item d-flex" >
34
35
<SearchInput SearchEntered =" NavigateToSearchPage" ></SearchInput >
35
36
</li >
38
39
</div >
39
40
</nav >
40
41
@code {
42
+ private string currentUri = string .Empty ;
43
+
44
+ protected override void OnInitialized ()
45
+ {
46
+ navigationManager .LocationChanged += UpdateUri ;
47
+ currentUri = navigationManager .Uri ;
48
+ }
49
+
41
50
private void NavigateToSearchPage (string searchTerm )
42
51
{
43
52
var escapeDataString = Uri .EscapeDataString (searchTerm );
44
53
navigationManager .NavigateTo ($" search/{escapeDataString }" );
45
54
}
55
+
56
+ public void Dispose ()
57
+ {
58
+ navigationManager .LocationChanged -= UpdateUri ;
59
+ }
60
+
61
+ private void UpdateUri (object sender , LocationChangedEventArgs e )
62
+ {
63
+ currentUri = e .Location ;
64
+ StateHasChanged ();
65
+ }
66
+
46
67
}
Original file line number Diff line number Diff line change @@ -69,4 +69,20 @@ public void ShouldDisplayAboutMePage()
69
69
. Cast < IHtmlAnchorElement > ( )
70
70
. Count ( a => a . Href . Contains ( "AboutMe" ) ) . Should ( ) . Be ( 1 ) ;
71
71
}
72
- }
72
+
73
+ [ Fact ]
74
+ public void ShouldPassCorrectUriToComponent ( )
75
+ {
76
+ var config = new AppConfiguration
77
+ {
78
+ ProfileInformation = new ProfileInformation ( ) ,
79
+ } ;
80
+ Services . AddScoped ( _ => config ) ;
81
+ this . AddTestAuthorization ( ) ;
82
+ var cut = RenderComponent < NavMenu > ( ) ;
83
+
84
+ Services . GetService < NavigationManager > ( ) ! . NavigateTo ( "test" ) ;
85
+
86
+ cut . FindComponent < AccessControl > ( ) . Instance . CurrentUri . Should ( ) . Contain ( "test" ) ;
87
+ }
88
+ }
You can’t perform that action at this time.
0 commit comments