1
1
import { expect } from '@vaadin/chai-plugins' ;
2
- import { esc , fixtureSync , focusin , focusout , nextRender , nextUpdate , outsideClick } from '@vaadin/testing-helpers' ;
2
+ import {
3
+ esc ,
4
+ fixtureSync ,
5
+ focusin ,
6
+ focusout ,
7
+ middleOfNode ,
8
+ mousedown ,
9
+ nextRender ,
10
+ nextUpdate ,
11
+ outsideClick ,
12
+ } from '@vaadin/testing-helpers' ;
13
+ import { resetMouse , sendKeys , sendMouse } from '@web/test-runner-commands' ;
3
14
import './not-animated-styles.js' ;
4
15
import '../vaadin-popover.js' ;
5
16
import { mouseenter , mouseleave } from './helpers.js' ;
@@ -14,6 +25,10 @@ describe('trigger', () => {
14
25
popover . renderer = ( root ) => {
15
26
if ( ! root . firstChild ) {
16
27
root . appendChild ( document . createElement ( 'input' ) ) ;
28
+
29
+ const div = document . createElement ( 'div' ) ;
30
+ div . textContent = 'Some text content' ;
31
+ root . appendChild ( div ) ;
17
32
}
18
33
} ;
19
34
await nextRender ( ) ;
@@ -184,6 +199,73 @@ describe('trigger', () => {
184
199
await nextRender ( ) ;
185
200
expect ( overlay . opened ) . to . be . true ;
186
201
} ) ;
202
+
203
+ describe ( 'overlay mousedown' , ( ) => {
204
+ let input ;
205
+
206
+ beforeEach ( async ( ) => {
207
+ input = document . createElement ( 'input' ) ;
208
+ target . parentNode . appendChild ( input ) ;
209
+
210
+ target . focus ( ) ;
211
+ await nextRender ( ) ;
212
+ } ) ;
213
+
214
+ afterEach ( async ( ) => {
215
+ input . remove ( ) ;
216
+ await resetMouse ( ) ;
217
+ } ) ;
218
+
219
+ it ( 'should not close on overlay mousedown when target has focus' , async ( ) => {
220
+ const { x, y } = middleOfNode ( overlay . querySelector ( 'div' ) ) ;
221
+ await sendMouse ( { type : 'click' , position : [ Math . round ( x ) , Math . round ( y ) ] } ) ;
222
+ await nextUpdate ( ) ;
223
+
224
+ expect ( overlay . opened ) . to . be . true ;
225
+ } ) ;
226
+
227
+ it ( 'should not close on overlay mousedown when overlay has focus' , async ( ) => {
228
+ overlay . querySelector ( 'input' ) . focus ( ) ;
229
+
230
+ const { x, y } = middleOfNode ( overlay . querySelector ( 'div' ) ) ;
231
+ await sendMouse ( { type : 'click' , position : [ Math . round ( x ) , Math . round ( y ) ] } ) ;
232
+ await nextUpdate ( ) ;
233
+
234
+ expect ( overlay . opened ) . to . be . true ;
235
+ } ) ;
236
+
237
+ it ( 'should only cancel one target focusout after the overlay mousedown' , async ( ) => {
238
+ // Remove the input so that first Tab would leave popover
239
+ overlay . querySelector ( 'input' ) . remove ( ) ;
240
+
241
+ const { x, y } = middleOfNode ( overlay . querySelector ( 'div' ) ) ;
242
+ await sendMouse ( { type : 'click' , position : [ Math . round ( x ) , Math . round ( y ) ] } ) ;
243
+ await nextUpdate ( ) ;
244
+
245
+ // Tab to focus input next to the target
246
+ await sendKeys ( { press : 'Tab' } ) ;
247
+
248
+ // Ensure the flag for ignoring next focusout was cleared
249
+ expect ( overlay . opened ) . to . be . false ;
250
+ } ) ;
251
+
252
+ it ( 'should only cancel one overlay focusout after the overlay mousedown' , async ( ) => {
253
+ overlay . querySelector ( 'input' ) . focus ( ) ;
254
+
255
+ const { x, y } = middleOfNode ( overlay . querySelector ( 'div' ) ) ;
256
+ await sendMouse ( { type : 'click' , position : [ Math . round ( x ) , Math . round ( y ) ] } ) ;
257
+ await nextUpdate ( ) ;
258
+
259
+ // Tab to focus input inside the popover
260
+ await sendKeys ( { press : 'Tab' } ) ;
261
+
262
+ // Tab to focus input next to the target
263
+ await sendKeys ( { press : 'Tab' } ) ;
264
+
265
+ // Ensure the flag for ignoring next focusout was cleared
266
+ expect ( overlay . opened ) . to . be . false ;
267
+ } ) ;
268
+ } ) ;
187
269
} ) ;
188
270
189
271
describe ( 'hover and focus' , ( ) => {
@@ -285,13 +367,15 @@ describe('trigger', () => {
285
367
} ) ;
286
368
287
369
it ( 'should not immediately close on target click when opened on focusin' , async ( ) => {
370
+ mousedown ( target ) ;
288
371
target . focus ( ) ;
289
372
target . click ( ) ;
290
373
await nextRender ( ) ;
291
374
expect ( overlay . opened ) . to . be . true ;
292
375
} ) ;
293
376
294
377
it ( 'should close on target click after a delay when opened on focusin' , async ( ) => {
378
+ mousedown ( target ) ;
295
379
target . focus ( ) ;
296
380
target . click ( ) ;
297
381
await nextRender ( ) ;
0 commit comments