File tree Expand file tree Collapse file tree 3 files changed +62
-7
lines changed
LinkDotNet.Blog.UnitTests/Web/Shared
LinkDotNet.Blog.Web/Shared Expand file tree Collapse file tree 3 files changed +62
-7
lines changed Original file line number Diff line number Diff line change
1
+ using Bunit ;
2
+ using FluentAssertions ;
3
+ using LinkDotNet . Blog . Web . Shared ;
4
+ using Xunit ;
5
+
6
+ namespace LinkDotNet . Blog . UnitTests . Web . Shared
7
+ {
8
+ public class SearchInputTests : TestContext
9
+ {
10
+ [ Fact ]
11
+ public void ShouldReturnEnteredText ( )
12
+ {
13
+ var enteredString = string . Empty ;
14
+ var cut = RenderComponent < SearchInput > ( p => p . Add ( s => s . SearchEntered , s => enteredString = s ) ) ;
15
+ cut . Find ( "input" ) . Change ( "Test" ) ;
16
+
17
+ cut . Find ( "button" ) . Click ( ) ;
18
+
19
+ enteredString . Should ( ) . Be ( "Test" ) ;
20
+ }
21
+
22
+ [ Theory ]
23
+ [ InlineData ( "" ) ]
24
+ [ InlineData ( " " ) ]
25
+ [ InlineData ( "\t " ) ]
26
+ public void ShouldNotReturnValueWhenOnlyWhitespaces ( string input )
27
+ {
28
+ var wasInvoked = false ;
29
+ var cut = RenderComponent < SearchInput > ( p => p . Add ( s => s . SearchEntered , _ => wasInvoked = true ) ) ;
30
+ cut . Find ( "input" ) . Change ( input ) ;
31
+
32
+ cut . Find ( "button" ) . Click ( ) ;
33
+
34
+ wasInvoked . Should ( ) . BeFalse ( ) ;
35
+ }
36
+
37
+ [ Fact ]
38
+ public void ShouldTrimData ( )
39
+ {
40
+ var enteredString = string . Empty ;
41
+ var cut = RenderComponent < SearchInput > ( p => p . Add ( s => s . SearchEntered , s => enteredString = s ) ) ;
42
+ cut . Find ( "input" ) . Change ( " Test 1 " ) ;
43
+
44
+ cut . Find ( "button" ) . Click ( ) ;
45
+
46
+ enteredString . Should ( ) . Be ( "Test 1" ) ;
47
+ }
48
+ }
49
+ }
Original file line number Diff line number Diff line change 31
31
@code {
32
32
private void NavigateToSearchPage (string searchTerm )
33
33
{
34
- if (string .IsNullOrWhiteSpace (searchTerm ))
35
- {
36
- return ;
37
- }
38
-
39
- navigationManager .NavigateTo ($" search/{Uri .EscapeDataString (searchTerm .Trim ())}" );
34
+ navigationManager .NavigateTo ($" search/{searchTerm }" );
40
35
}
41
36
}
Original file line number Diff line number Diff line change 11
11
12
12
private async Task CallSearchEntered ()
13
13
{
14
- await SearchEntered .InvokeAsync (searchTerm );
14
+ if (string .IsNullOrWhiteSpace (searchTerm ))
15
+ {
16
+ return ;
17
+ }
18
+
19
+ var trimmed = searchTerm .Trim ();
20
+ if (trimmed == string .Empty )
21
+ {
22
+ return ;
23
+ }
24
+
25
+ await SearchEntered .InvokeAsync (trimmed );
15
26
}
16
27
17
28
}
You can’t perform that action at this time.
0 commit comments