1
1
import { newE2EPage } from "@stencil/core/testing" ;
2
2
import { focusable , renders , slots , hidden , t9n } from "../../tests/commonTests" ;
3
3
import { html } from "../../../support/formatting" ;
4
- import { CSS , SLOTS , DURATIONS } from "./resources" ;
5
- import { isElementFocused , newProgrammaticE2EPage , skipAnimations } from "../../tests/utils" ;
4
+ import { CSS , SLOTS } from "./resources" ;
5
+ import { GlobalTestProps , isElementFocused , newProgrammaticE2EPage , skipAnimations } from "../../tests/utils" ;
6
6
7
7
describe ( "calcite-modal properties" , ( ) => {
8
8
describe ( "renders" , ( ) => {
@@ -132,29 +132,24 @@ describe("calcite-modal properties", () => {
132
132
} ) ;
133
133
134
134
describe ( "opening and closing behavior" , ( ) => {
135
- function getTransitionTransform (
136
- modalSelector : string ,
137
- modalContainerSelector : string ,
138
- type : "none" | "matrix"
139
- ) : boolean {
140
- const modalContainer = document
141
- . querySelector ( modalSelector )
142
- . shadowRoot . querySelector < HTMLElement > ( modalContainerSelector ) ;
143
- return getComputedStyle ( modalContainer ) . transform . startsWith ( type ) ;
144
- }
145
-
146
- const getTransitionDuration = ( ) : { duration : string } => {
147
- const modal = document . querySelector ( "calcite-modal" ) ;
148
- const { transitionDuration } = window . getComputedStyle ( modal ) ;
149
- return {
150
- duration : transitionDuration ,
151
- } ;
152
- } ;
153
-
154
- it . skip ( "opens and closes" , async ( ) => {
135
+ it ( "opens and closes" , async ( ) => {
155
136
const page = await newE2EPage ( ) ;
156
- await page . setContent ( html `< calcite-modal style =" transition: opacity ${ DURATIONS . test } s " > </ calcite-modal > ` ) ;
137
+ await page . setContent ( html `< calcite-modal > </ calcite-modal > ` ) ;
157
138
const modal = await page . find ( "calcite-modal" ) ;
139
+
140
+ type ModalEventOrderWindow = GlobalTestProps < { events : string [ ] } > ;
141
+
142
+ await page . $eval ( "calcite-modal" , ( modal : HTMLCalciteModalElement ) => {
143
+ const receivedEvents : string [ ] = [ ] ;
144
+ ( window as ModalEventOrderWindow ) . events = receivedEvents ;
145
+
146
+ [ "calciteModalBeforeOpen" , "calciteModalOpen" , "calciteModalBeforeClose" , "calciteModalClose" ] . forEach (
147
+ ( eventType ) => {
148
+ modal . addEventListener ( eventType , ( event ) => receivedEvents . push ( event . type ) ) ;
149
+ }
150
+ ) ;
151
+ } ) ;
152
+
158
153
const beforeOpenSpy = await modal . spyOnEvent ( "calciteModalBeforeOpen" ) ;
159
154
const openSpy = await modal . spyOnEvent ( "calciteModalOpen" ) ;
160
155
const beforeCloseSpy = await modal . spyOnEvent ( "calciteModalBeforeClose" ) ;
@@ -164,54 +159,45 @@ describe("opening and closing behavior", () => {
164
159
expect ( openSpy ) . toHaveReceivedEventTimes ( 0 ) ;
165
160
expect ( beforeCloseSpy ) . toHaveReceivedEventTimes ( 0 ) ;
166
161
expect ( closeSpy ) . toHaveReceivedEventTimes ( 0 ) ;
167
- await page . waitForFunction ( getTransitionTransform , { } , "calcite-modal" , `.${ CSS . modal } ` , "none" ) ;
168
162
163
+ expect ( await modal . isVisible ( ) ) . toBe ( false ) ;
164
+
165
+ const modalBeforeOpen = page . waitForEvent ( "calciteModalBeforeOpen" ) ;
166
+ const modalOpen = page . waitForEvent ( "calciteModalOpen" ) ;
169
167
await modal . setProperty ( "open" , true ) ;
170
- let waitForEvent = page . waitForEvent ( "calciteModalBeforeOpen" ) ;
171
168
await page . waitForChanges ( ) ;
172
- await waitForEvent ;
173
-
174
- expect ( beforeOpenSpy ) . toHaveReceivedEventTimes ( 1 ) ;
175
- expect ( openSpy ) . toHaveReceivedEventTimes ( 0 ) ;
176
- expect ( beforeCloseSpy ) . toHaveReceivedEventTimes ( 0 ) ;
177
- expect ( closeSpy ) . toHaveReceivedEventTimes ( 0 ) ;
178
- await page . waitForFunction ( getTransitionTransform , { } , "calcite-modal" , `.${ CSS . modal } ` , "matrix" ) ;
179
169
180
- waitForEvent = page . waitForEvent ( "calciteModalOpen" ) ;
181
- await waitForEvent ;
170
+ await modalBeforeOpen ;
171
+ await modalOpen ;
182
172
183
173
expect ( beforeOpenSpy ) . toHaveReceivedEventTimes ( 1 ) ;
184
174
expect ( openSpy ) . toHaveReceivedEventTimes ( 1 ) ;
185
175
expect ( beforeCloseSpy ) . toHaveReceivedEventTimes ( 0 ) ;
186
176
expect ( closeSpy ) . toHaveReceivedEventTimes ( 0 ) ;
187
- expect ( await modal . getProperty ( "open" ) ) . toBe ( true ) ;
188
- await page . waitForFunction ( getTransitionTransform , { } , "calcite-modal" , `.${ CSS . modal } ` , "matrix" ) ;
189
- await page . waitForFunction ( getTransitionTransform , { } , "calcite-modal" , `.${ CSS . modal } ` , "none" ) ;
190
177
178
+ expect ( await modal . isVisible ( ) ) . toBe ( true ) ;
179
+
180
+ const modalBeforeClose = page . waitForEvent ( "calciteModalBeforeClose" ) ;
181
+ const modalClose = page . waitForEvent ( "calciteModalClose" ) ;
191
182
await modal . setProperty ( "open" , false ) ;
192
- waitForEvent = page . waitForEvent ( "calciteModalBeforeClose" ) ;
193
183
await page . waitForChanges ( ) ;
194
- await waitForEvent ;
195
184
196
- const opacityTransition = await page . evaluate ( getTransitionDuration ) ;
197
- expect ( opacityTransition . duration ) . toEqual ( ` ${ DURATIONS . test } s` ) ;
185
+ await modalBeforeClose ;
186
+ await modalClose ;
198
187
199
188
expect ( beforeOpenSpy ) . toHaveReceivedEventTimes ( 1 ) ;
200
189
expect ( openSpy ) . toHaveReceivedEventTimes ( 1 ) ;
201
190
expect ( beforeCloseSpy ) . toHaveReceivedEventTimes ( 1 ) ;
202
- expect ( closeSpy ) . toHaveReceivedEventTimes ( 0 ) ;
203
- await page . waitForFunction ( getTransitionTransform , { } , "calcite-modal" , `.${ CSS . modal } ` , "matrix" ) ;
191
+ expect ( closeSpy ) . toHaveReceivedEventTimes ( 1 ) ;
204
192
205
- waitForEvent = page . waitForEvent ( "calciteModalClose" ) ;
206
- await waitForEvent ;
193
+ expect ( await modal . isVisible ( ) ) . toBe ( false ) ;
207
194
208
- expect ( beforeOpenSpy ) . toHaveReceivedEventTimes ( 1 ) ;
209
- expect ( openSpy ) . toHaveReceivedEventTimes ( 1 ) ;
210
- expect ( beforeCloseSpy ) . toHaveReceivedEventTimes ( 1 ) ;
211
- expect ( closeSpy ) . toHaveReceivedEventTimes ( 1 ) ;
212
- await page . waitForFunction ( getTransitionTransform , { } , "calcite-modal" , `.${ CSS . modal } ` , "matrix" ) ;
213
- await page . waitForFunction ( getTransitionTransform , { } , "calcite-modal" , `.${ CSS . modal } ` , "none" ) ;
214
- expect ( await modal . getProperty ( "open" ) ) . toBe ( false ) ;
195
+ expect ( await page . evaluate ( ( ) => ( window as ModalEventOrderWindow ) . events ) ) . toEqual ( [
196
+ "calciteModalBeforeOpen" ,
197
+ "calciteModalOpen" ,
198
+ "calciteModalBeforeClose" ,
199
+ "calciteModalClose" ,
200
+ ] ) ;
215
201
} ) ;
216
202
217
203
it ( "emits when set to open on initial render" , async ( ) => {
@@ -220,18 +206,16 @@ describe("opening and closing behavior", () => {
220
206
const beforeOpenSpy = await page . spyOnEvent ( "calciteModalBeforeOpen" ) ;
221
207
const openSpy = await page . spyOnEvent ( "calciteModalOpen" ) ;
222
208
223
- await page . evaluate ( ( transitionDuration : string ) : void => {
209
+ const waitForBeforeOpenEvent = page . waitForEvent ( "calciteModalBeforeOpen" ) ;
210
+ const waitForOpenEvent = page . waitForEvent ( "calciteModalOpen" ) ;
211
+
212
+ await page . evaluate ( ( ) : void => {
224
213
const modal = document . createElement ( "calcite-modal" ) ;
225
214
modal . open = true ;
226
- modal . style . transition = `opacity ${ transitionDuration } s` ;
227
215
document . body . append ( modal ) ;
228
- } , `${ DURATIONS . test } ` ) ;
229
-
230
- await page . waitForTimeout ( DURATIONS . test ) ;
231
-
232
- const waitForBeforeOpenEvent = page . waitForEvent ( "calciteModalBeforeOpen" ) ;
233
- const waitForOpenEvent = page . waitForEvent ( "calciteModalOpen" ) ;
216
+ } ) ;
234
217
218
+ await page . waitForChanges ( ) ;
235
219
await waitForBeforeOpenEvent ;
236
220
await waitForOpenEvent ;
237
221
@@ -246,28 +230,24 @@ describe("opening and closing behavior", () => {
246
230
const beforeOpenSpy = await page . spyOnEvent ( "calciteModalBeforeOpen" ) ;
247
231
const openSpy = await page . spyOnEvent ( "calciteModalOpen" ) ;
248
232
233
+ const waitForOpenEvent = page . waitForEvent ( "calciteModalOpen" ) ;
234
+ const waitForBeforeOpenEvent = page . waitForEvent ( "calciteModalBeforeOpen" ) ;
235
+
249
236
await page . evaluate ( ( ) : void => {
250
237
const modal = document . createElement ( "calcite-modal" ) ;
251
238
modal . open = true ;
252
239
document . body . append ( modal ) ;
253
240
} ) ;
254
241
255
- const opacityTransition = await page . evaluate ( getTransitionDuration ) ;
256
- expect ( opacityTransition . duration ) . toEqual ( "0s" ) ;
257
-
258
- await page . waitForChanges ;
259
-
260
- const waitForOpenEvent = page . waitForEvent ( "calciteModalOpen" ) ;
261
- const waitForBeforeOpenEvent = page . waitForEvent ( "calciteModalBeforeOpen" ) ;
262
-
242
+ await page . waitForChanges ( ) ;
263
243
await waitForBeforeOpenEvent ;
264
244
await waitForOpenEvent ;
265
245
266
246
expect ( beforeOpenSpy ) . toHaveReceivedEventTimes ( 1 ) ;
267
247
expect ( openSpy ) . toHaveReceivedEventTimes ( 1 ) ;
268
248
} ) ;
269
249
270
- it . skip ( "emits when duration is set to 0" , async ( ) => {
250
+ it ( "emits when duration is set to 0" , async ( ) => {
271
251
const page = await newProgrammaticE2EPage ( ) ;
272
252
await skipAnimations ( page ) ;
273
253
@@ -283,9 +263,6 @@ describe("opening and closing behavior", () => {
283
263
document . body . append ( modal ) ;
284
264
} ) ;
285
265
286
- const opacityTransition = await page . evaluate ( getTransitionDuration ) ;
287
- expect ( opacityTransition . duration ) . toEqual ( "0s" ) ;
288
-
289
266
await page . waitForChanges ( ) ;
290
267
await beforeOpenSpy ;
291
268
await openSpy ;
@@ -320,11 +297,11 @@ describe("calcite-modal accessibility checks", () => {
320
297
</ div >
321
298
</ calcite-modal > `
322
299
) ;
323
- await skipAnimations ( page ) ;
324
- await page . waitForChanges ( ) ;
325
300
const modal = await page . find ( "calcite-modal" ) ;
301
+ const opened = page . waitForEvent ( "calciteModalOpen" ) ;
326
302
modal . setProperty ( "open" , true ) ;
327
303
await page . waitForChanges ( ) ;
304
+ await opened ;
328
305
329
306
expect ( await isElementFocused ( page , `.${ CSS . close } ` , { shadowed : true } ) ) . toBe ( true ) ;
330
307
await page . keyboard . press ( "Tab" ) ;
0 commit comments