This repository was archived by the owner on Jun 21, 2023. It is now read-only.
File tree 3 files changed +53
-1
lines changed
GitHub.UI.Reactive/Controls/Validation
3 files changed +53
-1
lines changed Original file line number Diff line number Diff line change @@ -17,6 +17,7 @@ namespace GitHub.UI
17
17
public class ValidationMessage : UserControl
18
18
{
19
19
const double defaultTextChangeThrottle = 0.2 ;
20
+ bool userHasInteracted ;
20
21
21
22
public ValidationMessage ( )
22
23
{
@@ -33,7 +34,7 @@ public ValidationMessage()
33
34
. Do ( CreateBinding )
34
35
. Select ( control =>
35
36
Observable . Merge (
36
- this . WhenAnyValue ( x => x . ShowError ) ,
37
+ this . WhenAnyValue ( x => x . ShowError ) . Where ( x => userHasInteracted ) ,
37
38
control . Events ( ) . TextChanged
38
39
. Throttle ( TimeSpan . FromSeconds ( ShowError ? defaultTextChangeThrottle : TextChangeThrottle ) ,
39
40
RxApp . MainThreadScheduler )
@@ -121,6 +122,7 @@ public string ErrorAdornerTemplate
121
122
void ShowValidateError ( bool showError )
122
123
{
123
124
IsShowingMessage = showError ;
125
+ userHasInteracted = true ;
124
126
125
127
if ( ValidatesControl == null || ! IsAdornerEnabled ( ) ) return ;
126
128
Original file line number Diff line number Diff line change
1
+ using System ;
2
+ using System . Net ;
3
+ using System . Reactive . Linq ;
4
+ using System . Reactive . Subjects ;
5
+ using GitHub . Authentication ;
6
+ using GitHub . Info ;
7
+ using GitHub . Models ;
8
+ using GitHub . Primitives ;
9
+ using GitHub . Services ;
10
+ using GitHub . ViewModels ;
11
+ using NSubstitute ;
12
+ using Octokit ;
13
+ using ReactiveUI ;
14
+ using Xunit ;
15
+
16
+ public class LoginControlViewModelTests
17
+ {
18
+ public class TheAuthenticationResultsCommand : TestBaseClass
19
+ {
20
+ [ Fact ]
21
+ public async void AllowsLoginFromEnterpriseAfterGitHubLoginHasFailed ( )
22
+ {
23
+ var repositoryHosts = Substitute . For < IRepositoryHosts > ( ) ;
24
+
25
+ var gitHubLogin = Substitute . For < ILoginToGitHubViewModel > ( ) ;
26
+ var gitHubLoginCommand = ReactiveCommand . CreateAsyncObservable ( _ =>
27
+ Observable . Return ( AuthenticationResult . CredentialFailure ) ) ;
28
+ gitHubLogin . Login . Returns ( gitHubLoginCommand ) ;
29
+
30
+ var enterpriseLogin = Substitute . For < ILoginToGitHubForEnterpriseViewModel > ( ) ;
31
+ var enterpriseLoginCommand = ReactiveCommand . CreateAsyncObservable ( _ =>
32
+ Observable . Return ( AuthenticationResult . Success ) ) ;
33
+ enterpriseLogin . Login . Returns ( enterpriseLoginCommand ) ;
34
+
35
+ var loginViewModel = new LoginControlViewModel ( repositoryHosts , gitHubLogin , enterpriseLogin ) ;
36
+ var success = false ;
37
+
38
+ loginViewModel . AuthenticationResults
39
+ . Where ( x => x == AuthenticationResult . Success )
40
+ . Subscribe ( _ => success = true ) ;
41
+
42
+ await gitHubLoginCommand . ExecuteAsync ( ) ;
43
+ await enterpriseLoginCommand . ExecuteAsync ( ) ;
44
+
45
+ Assert . True ( success ) ;
46
+ }
47
+ }
48
+ }
49
+
Original file line number Diff line number Diff line change 163
163
<Compile Include =" GitHub.App\Services\GitClientTests.cs" />
164
164
<Compile Include =" GitHub.App\Services\RepositoryCloneServiceTests.cs" />
165
165
<Compile Include =" GitHub.App\Services\RepositoryCreationServiceTests.cs" />
166
+ <Compile Include =" GitHub.App\ViewModels\LoginControlViewModelTests.cs" />
166
167
<Compile Include =" GitHub.App\ViewModels\LoginToGitHubViewModelTests.cs" />
167
168
<Compile Include =" GitHub.App\ViewModels\RepositoryCloneViewModelTests.cs" />
168
169
<Compile Include =" GitHub.App\ViewModels\RepositoryCreationViewModelTests.cs" />
You can’t perform that action at this time.
0 commit comments