@@ -3,7 +3,7 @@ import pattern from "./depends";
3
3
import utils from "../../core/utils" ;
4
4
5
5
describe ( "pat-depends" , function ( ) {
6
- describe ( "init" , function ( ) {
6
+ describe ( "1 - init" , function ( ) {
7
7
beforeEach ( function ( ) {
8
8
$ ( "<div/>" , { id : "lab" } ) . appendTo ( document . body ) ;
9
9
} ) ;
@@ -40,7 +40,7 @@ describe("pat-depends", function () {
40
40
} ) ;
41
41
} ) ;
42
42
43
- describe ( "disable" , function ( ) {
43
+ describe ( "2 - disable" , function ( ) {
44
44
beforeEach ( function ( ) {
45
45
$ ( "<div/>" , { id : "lab" } ) . appendTo ( document . body ) ;
46
46
} ) ;
@@ -84,7 +84,7 @@ describe("pat-depends", function () {
84
84
} ) ;
85
85
} ) ;
86
86
87
- describe ( "enable" , function ( ) {
87
+ describe ( "3 - enable" , function ( ) {
88
88
beforeEach ( function ( ) {
89
89
$ ( "<div/>" , { id : "lab" } ) . appendTo ( document . body ) ;
90
90
} ) ;
@@ -128,4 +128,63 @@ describe("pat-depends", function () {
128
128
expect ( $ . _data ( $dependent [ 0 ] ) . events ) . toBe ( undefined ) ;
129
129
} ) ;
130
130
} ) ;
131
+
132
+ describe ( "4 - pat-update" , function ( ) {
133
+ it ( "4.1 - Throw pat-update on enabling" , async function ( ) {
134
+ document . body . innerHTML = `
135
+ <input
136
+ type="checkbox"
137
+ id="control"
138
+ value="yes"
139
+ checked="checked"/>
140
+ <button
141
+ id="dependent"
142
+ type="button"
143
+ class="pat-depends"
144
+ data-pat-depends="condition: control"
145
+ >Click me</button>
146
+ ` ;
147
+ const el = document . querySelector ( ".pat-depends" ) ;
148
+ const instance = new pattern ( el ) ;
149
+ await utils . timeout ( 1 ) ; // wait a tick for async to settle.
150
+
151
+ let data ;
152
+ $ ( el ) . on ( "pat-update" , ( e , d ) => {
153
+ data = d ;
154
+ } ) ;
155
+ instance . enable ( ) ;
156
+ expect ( data . pattern ) . toBe ( "depends" ) ;
157
+ expect ( data . action ) . toBe ( "attribute-changed" ) ;
158
+ expect ( data . dom ) . toBe ( el ) ;
159
+ expect ( data . enabled ) . toBe ( true ) ;
160
+ } ) ;
161
+ it ( "4.2 - Throw pat-update on disabling" , async function ( ) {
162
+ document . body . innerHTML = `
163
+ <input
164
+ type="checkbox"
165
+ id="control"
166
+ value="yes"
167
+ checked="checked"/>
168
+ <button
169
+ id="dependent"
170
+ type="button"
171
+ class="pat-depends"
172
+ data-pat-depends="condition: control"
173
+ >Click me</button>
174
+ ` ;
175
+ const el = document . querySelector ( ".pat-depends" ) ;
176
+ const instance = new pattern ( el ) ;
177
+ await utils . timeout ( 1 ) ; // wait a tick for async to settle.
178
+
179
+ let data ;
180
+ $ ( el ) . on ( "pat-update" , ( e , d ) => {
181
+ data = d ;
182
+ } ) ;
183
+ instance . disable ( ) ;
184
+ expect ( data . pattern ) . toBe ( "depends" ) ;
185
+ expect ( data . action ) . toBe ( "attribute-changed" ) ;
186
+ expect ( data . dom ) . toBe ( el ) ;
187
+ expect ( data . enabled ) . toBe ( false ) ;
188
+ } ) ;
189
+ } ) ;
131
190
} ) ;
0 commit comments