|
1 | 1 | import { expect } from '@esm-bundle/chai'; |
2 | | -import { fixtureSync, nextRender } from '@vaadin/testing-helpers'; |
| 2 | +import { fixtureSync, keyboardEventFor, nextRender } from '@vaadin/testing-helpers'; |
3 | 3 | import { sendKeys } from '@web/test-runner-commands'; |
4 | 4 | import sinon from 'sinon'; |
5 | 5 | import './not-animated-styles.js'; |
@@ -132,4 +132,33 @@ describe('selecting items', () => { |
132 | 132 | expect(comboBox.selectedItems).to.deep.equal(['orange']); |
133 | 133 | }); |
134 | 134 | }); |
| 135 | + |
| 136 | + describe('enter key propagation', () => { |
| 137 | + const verifyEnterKeyPropagation = (allowPropagation) => { |
| 138 | + const enterEvent = keyboardEventFor('keydown', 13, [], 'Enter'); |
| 139 | + const stopPropagationSpy = sinon.spy(enterEvent, 'stopPropagation'); |
| 140 | + inputElement.dispatchEvent(enterEvent); |
| 141 | + expect(stopPropagationSpy.called).to.equal(!allowPropagation); |
| 142 | + }; |
| 143 | + |
| 144 | + beforeEach(async () => { |
| 145 | + comboBox.items = ['apple', 'banana', 'lemon', 'orange']; |
| 146 | + }); |
| 147 | + |
| 148 | + it('should stop propagation of the keyboard Enter event when dropdown is opened', async () => { |
| 149 | + await sendKeys({ press: 'ArrowDown' }); |
| 150 | + verifyEnterKeyPropagation(false); |
| 151 | + }); |
| 152 | + |
| 153 | + it('should stop propagation of the keyboard Enter event when input value is invalid', async () => { |
| 154 | + await sendKeys({ type: 'lime' }); |
| 155 | + verifyEnterKeyPropagation(false); |
| 156 | + }); |
| 157 | + |
| 158 | + it('should stop propagation of the keyboard Enter event when input is invalid and not opened', async () => { |
| 159 | + comboBox.autoOpenDisabled = true; |
| 160 | + await sendKeys({ type: 'lime' }); |
| 161 | + verifyEnterKeyPropagation(false); |
| 162 | + }); |
| 163 | + }); |
135 | 164 | }); |
0 commit comments