File tree Expand file tree Collapse file tree 1 file changed +42
-0
lines changed Expand file tree Collapse file tree 1 file changed +42
-0
lines changed Original file line number Diff line number Diff line change @@ -513,6 +513,48 @@ await cut.InvokeAsync(() =>
513513 Assert . True ( invalid ) ;
514514 }
515515
516+ [ Fact ]
517+ public async Task IsAutoClearWhenInvalid_Ok ( )
518+ {
519+ var model = new MockModel ( ) { Value = new Foo ( ) { Name = "Test-Select1" } } ;
520+ var items = new List < Foo > ( )
521+ {
522+ new ( ) { Name = "test1" } ,
523+ new ( ) { Name = "test2" }
524+ } ;
525+ var cut = Context . RenderComponent < AutoFill < Foo > > ( pb =>
526+ {
527+ pb . Add ( a => a . Items , items ) ;
528+ pb . Add ( a => a . Value , model . Value ) ;
529+ pb . Add ( a => a . IsAutoClearWhenInvalid , true ) ;
530+ pb . Add ( a => a . OnGetDisplayText , f => f ? . Name ) ;
531+ } ) ;
532+ // 设置一个无效值
533+ await cut . InvokeAsync ( ( ) => cut . Instance . TriggerChange ( "Invalid-Value" ) ) ;
534+
535+ // 触发 OnBlur 回调
536+ await cut . InvokeAsync ( ( ) => cut . Instance . TriggerBlur ( ) ) ;
537+
538+ // 值应被清空
539+ Assert . Null ( cut . Instance . Value ) ;
540+
541+ // 设定 IsAutoClearWhenInvalid false
542+ cut . SetParametersAndRender ( pb =>
543+ {
544+ pb . Add ( a => a . IsAutoClearWhenInvalid , false ) ;
545+ pb . Add ( a => a . Value , model . Value ) ;
546+ } ) ;
547+
548+ // 设置一个无效值
549+ await cut . InvokeAsync ( ( ) => cut . Instance . TriggerChange ( "Invalid-Value" ) ) ;
550+
551+ // 触发 OnBlur 回调
552+ await cut . InvokeAsync ( ( ) => cut . Instance . TriggerBlur ( ) ) ;
553+
554+ // 值不应被清空
555+ Assert . NotNull ( cut . Instance . Value ) ;
556+ }
557+
516558 class MockModel
517559 {
518560 [ Required ]
You can’t perform that action at this time.
0 commit comments