|
8 | 8 | fire, |
9 | 9 | fixtureSync, |
10 | 10 | focusout, |
| 11 | + keyboardEventFor, |
11 | 12 | keyDownOn, |
12 | 13 | nextFrame |
13 | 14 | } from '@vaadin/testing-helpers'; |
@@ -69,6 +70,23 @@ describe('keyboard', () => { |
69 | 70 |
|
70 | 71 | expect(getFocusedIndex()).to.equal(0); |
71 | 72 | }); |
| 73 | + |
| 74 | + it('should propagate escape key event if dropdown is closed', () => { |
| 75 | + const event = keyboardEventFor('keydown', 27, [], 'Escape'); |
| 76 | + const keyDownSpy = sinon.spy(event, 'stopPropagation'); |
| 77 | + input.dispatchEvent(event); |
| 78 | + expect(keyDownSpy.called).to.be.false; |
| 79 | + }); |
| 80 | + |
| 81 | + it('should not propagate esc keydown event when overlay is closed, clear button is visible and value is not empty', () => { |
| 82 | + comboBox.value = 'bar'; |
| 83 | + comboBox.clearButtonVisible = true; |
| 84 | + |
| 85 | + const event = keyboardEventFor('keydown', 27, [], 'Escape'); |
| 86 | + const keyDownSpy = sinon.spy(event, 'stopPropagation'); |
| 87 | + input.dispatchEvent(event); |
| 88 | + expect(keyDownSpy.called).to.be.true; |
| 89 | + }); |
72 | 90 | }); |
73 | 91 |
|
74 | 92 | describe('navigating after overlay opened', () => { |
@@ -231,7 +249,7 @@ describe('keyboard', () => { |
231 | 249 | expect(input.value).to.equal('foobar'); |
232 | 250 | }); |
233 | 251 |
|
234 | | - it('should revert to the custom value after keyboar navigation', () => { |
| 252 | + it('should revert to the custom value after keyboard navigation', () => { |
235 | 253 | comboBox.allowCustomValue = true; |
236 | 254 | comboBox.value = 'foobar'; |
237 | 255 | arrowDownKeyDown(input); |
@@ -557,5 +575,14 @@ describe('keyboard', () => { |
557 | 575 | escKeyDown(input); |
558 | 576 | expect(comboBox.value).to.equal('bar'); |
559 | 577 | }); |
| 578 | + |
| 579 | + it('should not propagate when input value is not empty', () => { |
| 580 | + inputText('foo'); |
| 581 | + |
| 582 | + const event = keyboardEventFor('keydown', 27, [], 'Escape'); |
| 583 | + const keyDownSpy = sinon.spy(event, 'stopPropagation'); |
| 584 | + input.dispatchEvent(event); |
| 585 | + expect(keyDownSpy.called).to.be.true; |
| 586 | + }); |
560 | 587 | }); |
561 | 588 | }); |
0 commit comments