@@ -11,7 +11,7 @@ describe("pat-autosubmit", function () {
11
11
} ) ;
12
12
13
13
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 ( ) {
15
15
document . body . innerHTML = `
16
16
<form class="pat-autosubmit">
17
17
<fieldset>
@@ -25,7 +25,7 @@ describe("pat-autosubmit", function () {
25
25
expect ( spy_init ) . toHaveBeenCalled ( ) ;
26
26
} ) ;
27
27
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 ( ) {
29
29
document . body . innerHTML = `
30
30
<form>
31
31
<fieldset class="pat-autosubmit">
@@ -39,7 +39,7 @@ describe("pat-autosubmit", function () {
39
39
expect ( spy_init ) . toHaveBeenCalled ( ) ;
40
40
} ) ;
41
41
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 ( ) {
43
43
document . body . innerHTML = `
44
44
<form>
45
45
<input
@@ -55,7 +55,7 @@ describe("pat-autosubmit", function () {
55
55
expect ( spy_init ) . toHaveBeenCalled ( ) ;
56
56
} ) ;
57
57
58
- it ( "calls refreshListeners when pat-clone adds an element" , function ( ) {
58
+ it ( "1.4 - calls refreshListeners when pat-clone adds an element" , function ( ) {
59
59
document . body . innerHTML = `
60
60
<form class="pat-autosubmit">
61
61
</form>
@@ -69,7 +69,7 @@ describe("pat-autosubmit", function () {
69
69
} ) ;
70
70
71
71
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 ( ) {
73
73
document . body . innerHTML = `
74
74
<form>
75
75
<input
@@ -81,11 +81,19 @@ describe("pat-autosubmit", function () {
81
81
</form>
82
82
` ;
83
83
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
+ } ) ;
86
93
input . dispatchEvent ( events . input_event ( ) ) ;
87
94
await utils . timeout ( 1 ) ;
88
- expect ( spy ) . toHaveBeenCalled ( ) ;
95
+ expect ( submit_input_dispatched ) . toBe ( true ) ;
96
+ expect ( submit_form_dispatched ) . toBe ( true ) ;
89
97
} ) ;
90
98
91
99
it ( "2.2 - when pat-clone'd input is changed" , async function ( ) {
@@ -104,19 +112,23 @@ describe("pat-autosubmit", function () {
104
112
const el_clone = document . querySelector ( ".pat-clone" ) ;
105
113
const button_clone = document . querySelector ( ".add-clone" ) ;
106
114
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
+ } ) ;
109
119
110
- const spy = jest . spyOn ( instance . $el , "submit" ) ;
120
+ new Pattern ( el ) ;
121
+ new pattern_clone ( el_clone ) ;
111
122
112
123
button_clone . click ( ) ;
113
124
114
125
document . querySelector ( "form input" ) . dispatchEvent ( events . input_event ( ) ) ;
115
126
116
- expect ( spy ) . toHaveBeenCalled ( ) ;
127
+ await utils . timeout ( 1 ) ;
128
+ expect ( submit_dispatched ) . toBe ( true ) ;
117
129
} ) ;
118
130
119
- it ( "when pat-clone removes an element" , function ( ) {
131
+ it ( "2.3 - when pat-clone removes an element" , function ( ) {
120
132
document . body . innerHTML = `
121
133
<form class="pat-autosubmit">
122
134
</form>
@@ -128,7 +140,7 @@ describe("pat-autosubmit", function () {
128
140
expect ( spy ) . toHaveBeenCalled ( ) ;
129
141
} ) ;
130
142
131
- it ( "when pat-sortable changes the sorting" , function ( ) {
143
+ it ( "2.4 - when pat-sortable changes the sorting" , function ( ) {
132
144
document . body . innerHTML = `
133
145
<form class="pat-autosubmit">
134
146
</form>
@@ -142,7 +154,7 @@ describe("pat-autosubmit", function () {
142
154
} ) ;
143
155
144
156
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 ( ) {
146
158
let pat = new Pattern ( `<input data-pat-autosubmit="500ms"/>` ) ;
147
159
expect ( pat . options . delay ) . toBe ( 500 ) ;
148
160
pat = new Pattern ( `<input data-pat-autosubmit="500"/>` ) ;
@@ -151,7 +163,7 @@ describe("pat-autosubmit", function () {
151
163
expect ( pat . options . delay ) . toBe ( "defocus" ) ;
152
164
} ) ;
153
165
154
- it ( "can be done in longhand notation" , function ( ) {
166
+ it ( "3.2 - can be done in longhand notation" , function ( ) {
155
167
let pat = new Pattern ( `<input data-pat-autosubmit="delay: 500ms"/>` ) ;
156
168
expect ( pat . options . delay ) . toBe ( 500 ) ;
157
169
pat = new Pattern ( `<input data-pat-autosubmit="delay: 500"/>` ) ;
0 commit comments