@@ -1044,24 +1044,27 @@ describe("pat-inject", function () {
10441044 } ) ;
10451045
10461046 it ( "9.2.5.2 - use an image submit with a formaction value as action URL" , async function ( ) {
1047- var $submit1 = $ (
1048- '<input type="submit" name="submit" value="default" />'
1049- ) ,
1050- $submit2 = $ (
1051- '<input type="image" name="submit" value="special" formaction="other.html" />'
1052- ) ;
1047+ const $submit = $ ( `
1048+ <input
1049+ type="image"
1050+ name="submit"
1051+ value="special"
1052+ formaction="other.html" />
1053+ ` ) ;
10531054
1054- $form . append ( $submit1 ) . append ( $submit2 ) ;
1055+ $form . append ( $submit ) ;
10551056
10561057 pattern . init ( $form ) ;
10571058 await utils . timeout ( 1 ) ; // wait a tick for async to settle.
10581059
10591060 // Work around jsDOM not submitting with image buttons.
1060- $submit2 [ 0 ] . addEventListener ( "click" , ( ) => {
1061- $submit2 [ 0 ] . form . dispatchEvent ( events . submit_event ( ) ) ;
1061+ $submit [ 0 ] . addEventListener ( "click" , async ( ) => {
1062+ await utils . timeout ( 1 ) ; // wait a tick for click event reaching form before submitting.
1063+ $submit [ 0 ] . form . dispatchEvent ( events . submit_event ( ) ) ;
10621064 } ) ;
10631065
1064- $submit2 [ 0 ] . click ( ) ;
1066+ $submit [ 0 ] . click ( ) ;
1067+ await utils . timeout ( 1 ) ; // wait a tick for click handler
10651068
10661069 var ajaxargs = $ . ajax . mock . calls [ $ . ajax . mock . calls . length - 1 ] [ 0 ] ;
10671070 expect ( $ . ajax ) . toHaveBeenCalled ( ) ;
@@ -1378,6 +1381,29 @@ describe("pat-inject", function () {
13781381 expect ( pattern . onTrigger ) . toHaveBeenCalledTimes ( 1 ) ;
13791382 } ) ;
13801383 } ) ;
1384+
1385+ it ( "9.2.7 - Sends submit button form values even if submit button is added after initialization." , async function ( ) {
1386+ document . body . innerHTML = `
1387+ <form class="pat-inject" action="test.cgi">
1388+ </form>
1389+ ` ;
1390+
1391+ const pat_ajax = ( await import ( "../ajax/ajax.js" ) ) . default ;
1392+ jest . spyOn ( pat_ajax , "onClickSubmit" ) ;
1393+ jest . spyOn ( pattern , "onTrigger" ) ;
1394+
1395+ const form = document . querySelector ( "form" ) ;
1396+
1397+ pattern . init ( $ ( form ) ) ;
1398+ await utils . timeout ( 1 ) ; // wait a tick for async to settle.
1399+
1400+ form . innerHTML = `<button type="submit"/>` ;
1401+ const button = form . querySelector ( "button" ) ;
1402+ button . click ( ) ;
1403+
1404+ expect ( pat_ajax . onClickSubmit ) . toHaveBeenCalledTimes ( 1 ) ;
1405+ expect ( pattern . onTrigger ) . toHaveBeenCalledTimes ( 1 ) ;
1406+ } ) ;
13811407 } ) ;
13821408 } ) ;
13831409
0 commit comments