File tree Expand file tree Collapse file tree 2 files changed +27
-5
lines changed
bunit.testassets/SampleComponents
bunit.tests/EventDispatchExtensions Expand file tree Collapse file tree 2 files changed +27
-5
lines changed Original file line number Diff line number Diff line change 1+ <form @onsubmit =" Callback" id =" form1" >
2+ </form >
3+ <button type =" submit" form =" form1" id =" submitter" >Submit</button >
4+
5+ @code {
6+ public bool SubmitWasCalled { get ; private set ; }
7+
8+ private void Callback ()
9+ {
10+ SubmitWasCalled = true ;
11+ }
12+ }
Original file line number Diff line number Diff line change @@ -6,29 +6,39 @@ public class FormDispatchExtensionTest : BunitContext
66 public void ClickingOnSubmitButtonTriggersOnsubmitOfForm ( )
77 {
88 var cut = Render < FormWithButton > ( p => p . Add ( s => s . HasSubmitType , true ) ) ;
9-
9+
1010 cut . Find ( "#submitter" ) . Click ( ) ;
1111
1212 cut . Instance . SubmitWasCalled . ShouldBeTrue ( ) ;
1313 }
14-
14+
1515 [ Fact ]
1616 public void ButtonWithoutTypeIsConsideredSubmitAndTriggersOnsubmitOfForm ( )
1717 {
1818 var cut = Render < FormWithButton > ( p => p . Add ( s => s . HasSubmitType , false ) ) ;
19-
19+
2020 cut . Find ( "#submitter" ) . Click ( ) ;
2121
2222 cut . Instance . SubmitWasCalled . ShouldBeTrue ( ) ;
2323 }
24-
24+
2525 [ Fact ]
2626 public void ButtonThatIsNotSubmitShouldNotTrigger ( )
2727 {
2828 var cut = Render < FormWithButton > ( p => p . Add ( s => s . HasSubmitType , false ) ) ;
29-
29+
3030 cut . Find ( "#other" ) . Click ( ) ;
3131
3232 cut . Instance . SubmitWasCalled . ShouldBeFalse ( ) ;
3333 }
34+
35+ [ Fact ]
36+ public void ClickingOnSubmitButtonOutsideTriggersOnsubmitOfForm ( )
37+ {
38+ var cut = Render < FormWithButtonOutside > ( ) ;
39+
40+ cut . Find ( "#submitter" ) . Click ( ) ;
41+
42+ cut . Instance . SubmitWasCalled . ShouldBeTrue ( ) ;
43+ }
3444}
You can’t perform that action at this time.
0 commit comments