@@ -11,7 +11,7 @@ describe("pat-autosubmit", function () {
1111 } ) ;
1212
1313 describe ( "1 - Triggering of the pattern" , function ( ) {
14- it ( "happens when a form has the pat-autosubmit class" , function ( ) {
14+ it ( "1.1 - happens when a form has the pat-autosubmit class" , function ( ) {
1515 document . body . innerHTML = `
1616 <form class="pat-autosubmit">
1717 <fieldset>
@@ -25,7 +25,7 @@ describe("pat-autosubmit", function () {
2525 expect ( spy_init ) . toHaveBeenCalled ( ) ;
2626 } ) ;
2727
28- it ( "when a grouping of inputs has the pat-autosubmit class" , function ( ) {
28+ it ( "1.2 - when a grouping of inputs has the pat-autosubmit class" , function ( ) {
2929 document . body . innerHTML = `
3030 <form>
3131 <fieldset class="pat-autosubmit">
@@ -39,7 +39,7 @@ describe("pat-autosubmit", function () {
3939 expect ( spy_init ) . toHaveBeenCalled ( ) ;
4040 } ) ;
4141
42- it ( "when a single input has the pat-autosubmit class" , function ( ) {
42+ it ( "1.3 - when a single input has the pat-autosubmit class" , function ( ) {
4343 document . body . innerHTML = `
4444 <form>
4545 <input
@@ -55,7 +55,7 @@ describe("pat-autosubmit", function () {
5555 expect ( spy_init ) . toHaveBeenCalled ( ) ;
5656 } ) ;
5757
58- it ( "calls refreshListeners when pat-clone adds an element" , function ( ) {
58+ it ( "1.4 - calls refreshListeners when pat-clone adds an element" , function ( ) {
5959 document . body . innerHTML = `
6060 <form class="pat-autosubmit">
6161 </form>
@@ -69,7 +69,7 @@ describe("pat-autosubmit", function () {
6969 } ) ;
7070
7171 describe ( "2 - Trigger a submit" , function ( ) {
72- it ( "when a change on a single input happens" , async function ( ) {
72+ it ( "2.1 - when a change on a single input happens" , async function ( ) {
7373 document . body . innerHTML = `
7474 <form>
7575 <input
@@ -81,11 +81,19 @@ describe("pat-autosubmit", function () {
8181 </form>
8282 ` ;
8383 const input = document . querySelector ( ".pat-autosubmit" ) ;
84- const instance = new Pattern ( input ) ;
85- const spy = jest . spyOn ( instance . $el , "submit" ) ;
84+ new Pattern ( input ) ;
85+ let submit_input_dispatched = false ;
86+ let submit_form_dispatched = false ;
87+ input . addEventListener ( "submit" , ( ) => {
88+ submit_input_dispatched = true ;
89+ } ) ;
90+ document . querySelector ( "form" ) . addEventListener ( "submit" , ( ) => {
91+ submit_form_dispatched = true ;
92+ } ) ;
8693 input . dispatchEvent ( events . input_event ( ) ) ;
8794 await utils . timeout ( 1 ) ;
88- expect ( spy ) . toHaveBeenCalled ( ) ;
95+ expect ( submit_input_dispatched ) . toBe ( true ) ;
96+ expect ( submit_form_dispatched ) . toBe ( true ) ;
8997 } ) ;
9098
9199 it ( "2.2 - when pat-clone'd input is changed" , async function ( ) {
@@ -104,19 +112,23 @@ describe("pat-autosubmit", function () {
104112 const el_clone = document . querySelector ( ".pat-clone" ) ;
105113 const button_clone = document . querySelector ( ".add-clone" ) ;
106114
107- const instance = new Pattern ( el ) ;
108- new pattern_clone ( el_clone ) ;
115+ let submit_dispatched = false ;
116+ el . addEventListener ( "submit" , ( ) => {
117+ submit_dispatched = true ;
118+ } ) ;
109119
110- const spy = jest . spyOn ( instance . $el , "submit" ) ;
120+ new Pattern ( el ) ;
121+ new pattern_clone ( el_clone ) ;
111122
112123 button_clone . click ( ) ;
113124
114125 document . querySelector ( "form input" ) . dispatchEvent ( events . input_event ( ) ) ;
115126
116- expect ( spy ) . toHaveBeenCalled ( ) ;
127+ await utils . timeout ( 1 ) ;
128+ expect ( submit_dispatched ) . toBe ( true ) ;
117129 } ) ;
118130
119- it ( "when pat-clone removes an element" , function ( ) {
131+ it ( "2.3 - when pat-clone removes an element" , function ( ) {
120132 document . body . innerHTML = `
121133 <form class="pat-autosubmit">
122134 </form>
@@ -128,7 +140,7 @@ describe("pat-autosubmit", function () {
128140 expect ( spy ) . toHaveBeenCalled ( ) ;
129141 } ) ;
130142
131- it ( "when pat-sortable changes the sorting" , function ( ) {
143+ it ( "2.4 - when pat-sortable changes the sorting" , function ( ) {
132144 document . body . innerHTML = `
133145 <form class="pat-autosubmit">
134146 </form>
@@ -142,7 +154,7 @@ describe("pat-autosubmit", function () {
142154 } ) ;
143155
144156 describe ( "3 - Parsing of the delay option" , function ( ) {
145- it ( "can be done in shorthand notation" , function ( ) {
157+ it ( "3.1 - can be done in shorthand notation" , function ( ) {
146158 let pat = new Pattern ( `<input data-pat-autosubmit="500ms"/>` ) ;
147159 expect ( pat . options . delay ) . toBe ( 500 ) ;
148160 pat = new Pattern ( `<input data-pat-autosubmit="500"/>` ) ;
@@ -151,7 +163,7 @@ describe("pat-autosubmit", function () {
151163 expect ( pat . options . delay ) . toBe ( "defocus" ) ;
152164 } ) ;
153165
154- it ( "can be done in longhand notation" , function ( ) {
166+ it ( "3.2 - can be done in longhand notation" , function ( ) {
155167 let pat = new Pattern ( `<input data-pat-autosubmit="delay: 500ms"/>` ) ;
156168 expect ( pat . options . delay ) . toBe ( 500 ) ;
157169 pat = new Pattern ( `<input data-pat-autosubmit="delay: 500"/>` ) ;
0 commit comments