File tree Expand file tree Collapse file tree 3 files changed +39
-7
lines changed
src/LinkDotNet.Blog.Web/Shared
tests/LinkDotNet.Blog.UnitTests/Web Expand file tree Collapse file tree 3 files changed +39
-7
lines changed Original file line number Diff line number Diff line change 2
2
<Authorized >
3
3
<li class =" nav-item dropdown" >
4
4
<a class =" nav-link dropdown-toggle" href =" #" id =" navbarDropdown" role =" button" data-bs-toggle =" dropdown"
5
- aria-expanded =" false" >
5
+ aria-expanded =" false" >
6
6
Admin
7
7
</a >
8
8
<ul class =" dropdown-menu original" aria-labelledby =" navbarDropdown" >
19
19
<li ><a class =" dropdown-item" target =" _blank" href =" https://github.com/linkdotnet/Blog/releases" >Version 2.12</a ></li >
20
20
</ul >
21
21
</li >
22
- <li class =" nav-item" ><a class =" nav-link" href =" logout" >Log out</a ></li >
22
+ <li class =" nav-item" ><a class =" nav-link" href =" logout?redirectUri=@CurrentUri " >Log out</a ></li >
23
23
</Authorized >
24
24
<NotAuthorized >
25
- <li class =" nav-item" ><a class =" nav-link" href =" login?redirectUri=/ " >Log in</a ></li >
25
+ <li class =" nav-item" ><a class =" nav-link" href =" login?redirectUri=@CurrentUri " >Log in</a ></li >
26
26
</NotAuthorized >
27
- </AuthorizeView >
27
+ </AuthorizeView >
28
+
29
+ @code {
30
+ [Parameter ]
31
+ public string CurrentUri { get ; set ; } = string .Empty ;
32
+
33
+ }
Original file line number Diff line number Diff line change 29
29
me </a ></li >
30
30
}
31
31
32
- <AccessControl ></AccessControl >
32
+ <AccessControl CurrentUri = " @navigationManager.Uri " ></AccessControl >
33
33
<li class =" nav-item d-flex" >
34
34
<SearchInput SearchEntered =" NavigateToSearchPage" ></SearchInput >
35
35
</li >
Original file line number Diff line number Diff line change 1
- using Bunit ;
1
+ using AngleSharp . Html . Dom ;
2
+ using AngleSharpWrappers ;
3
+ using Bunit ;
2
4
using Bunit . TestDoubles ;
3
5
using FluentAssertions ;
4
6
using LinkDotNet . Blog . Web . Shared ;
@@ -29,4 +31,28 @@ public void ShouldShowLogoutAndAdminWhenLoggedIn()
29
31
cut . FindAll ( "a:contains('Admin')" ) . Should ( ) . HaveCount ( 1 ) ;
30
32
cut . FindAll ( "a:contains('Log out')" ) . Should ( ) . HaveCount ( 1 ) ;
31
33
}
32
- }
34
+
35
+ [ Fact ]
36
+ public void LoginShouldHaveCurrentUriAsRedirectUri ( )
37
+ {
38
+ const string currentUri = "http://localhost/test" ;
39
+ this . AddTestAuthorization ( ) ;
40
+
41
+ var cut = RenderComponent < AccessControl > (
42
+ p => p . Add ( s => s . CurrentUri , currentUri ) ) ;
43
+
44
+ ( ( IHtmlAnchorElement ) cut . Find ( "a:contains('Log in')" ) . Unwrap ( ) ) . Href . Should ( ) . Contain ( currentUri ) ;
45
+ }
46
+
47
+ [ Fact ]
48
+ public void LogoutShouldHaveCurrentUriAsRedirectUri ( )
49
+ {
50
+ const string currentUri = "http://localhost/test" ;
51
+ this . AddTestAuthorization ( ) . SetAuthorized ( "steven" ) ;
52
+
53
+ var cut = RenderComponent < AccessControl > (
54
+ p => p . Add ( s => s . CurrentUri , currentUri ) ) ;
55
+
56
+ ( ( IHtmlAnchorElement ) cut . Find ( "a:contains('Log out')" ) . Unwrap ( ) ) . Href . Should ( ) . Contain ( currentUri ) ;
57
+ }
58
+ }
You can’t perform that action at this time.
0 commit comments