1
1
import { expect } from '@vaadin/chai-plugins' ;
2
- import {
3
- aTimeout ,
4
- click ,
5
- esc ,
6
- fixtureSync ,
7
- listenOnce ,
8
- nextRender ,
9
- nextUpdate ,
10
- oneEvent ,
11
- } from '@vaadin/testing-helpers' ;
2
+ import { sendKeys } from '@vaadin/test-runner-commands' ;
3
+ import { aTimeout , click , fixtureSync , listenOnce , nextRender , nextUpdate , oneEvent } from '@vaadin/testing-helpers' ;
12
4
import sinon from 'sinon' ;
13
5
import '../src/vaadin-dialog.js' ;
14
6
import { getDeepActiveElement } from '@vaadin/a11y-base/src/focus-utils.js' ;
@@ -61,14 +53,22 @@ describe('vaadin-dialog', () => {
61
53
} ) ;
62
54
63
55
describe ( 'opened' , ( ) => {
64
- let dialog , backdrop , overlay ;
56
+ let dialog , focusable , backdrop , overlay ;
65
57
66
58
beforeEach ( async ( ) => {
67
- dialog = fixtureSync ( '<vaadin-dialog opened></vaadin-dialog>' ) ;
59
+ [ dialog , focusable ] = fixtureSync ( `
60
+ <div>
61
+ <vaadin-dialog opened></vaadin-dialog>
62
+ <input />
63
+ </div>
64
+ ` ) . children ;
68
65
await nextRender ( ) ;
69
66
70
67
dialog . renderer = ( root ) => {
71
- root . innerHTML = '<div>Simple dialog</div>' ;
68
+ root . innerHTML = `
69
+ <div>Simple dialog</div>
70
+ <input />
71
+ ` ;
72
72
} ;
73
73
await nextUpdate ( dialog ) ;
74
74
@@ -83,15 +83,35 @@ describe('vaadin-dialog', () => {
83
83
84
84
describe ( 'no-close-on-esc' , ( ) => {
85
85
it ( 'should close itself on ESC press by default' , async ( ) => {
86
- esc ( document . body ) ;
86
+ await sendKeys ( { press : 'Escape' } ) ;
87
87
await nextUpdate ( dialog ) ;
88
88
expect ( dialog . opened ) . to . be . false ;
89
89
} ) ;
90
90
91
91
it ( 'should not close itself on ESC press when no-close-on-esc is true' , async ( ) => {
92
92
dialog . noCloseOnEsc = true ;
93
- await nextUpdate ( dialog ) ;
94
- esc ( document . body ) ;
93
+ await sendKeys ( { press : 'Escape' } ) ;
94
+ expect ( dialog . opened ) . to . be . true ;
95
+ } ) ;
96
+
97
+ it ( 'should close on Escape press when modeless and dialog itself is focused' , async ( ) => {
98
+ dialog . modeless = true ;
99
+ dialog . focus ( ) ;
100
+ await sendKeys ( { press : 'Escape' } ) ;
101
+ expect ( dialog . opened ) . to . be . false ;
102
+ } ) ;
103
+
104
+ it ( 'should close on Escape press when modeless and content element is focused' , async ( ) => {
105
+ dialog . modeless = true ;
106
+ dialog . querySelector ( 'input' ) . focus ( ) ;
107
+ await sendKeys ( { press : 'Escape' } ) ;
108
+ expect ( dialog . opened ) . to . be . false ;
109
+ } ) ;
110
+
111
+ it ( 'should not close on Escape press when modeless and not focused' , async ( ) => {
112
+ dialog . modeless = true ;
113
+ focusable . focus ( ) ;
114
+ await sendKeys ( { press : 'Escape' } ) ;
95
115
expect ( dialog . opened ) . to . be . true ;
96
116
} ) ;
97
117
} ) ;
0 commit comments