|
1 | 1 | import { expect } from '@esm-bundle/chai'; |
2 | | -import { fixtureSync, nextRender } from '@vaadin/testing-helpers'; |
| 2 | +import { fixtureSync, nextRender, outsideClick } from '@vaadin/testing-helpers'; |
| 3 | +import { sendKeys } from '@web/test-runner-commands'; |
3 | 4 | import sinon from 'sinon'; |
4 | 5 | import './not-animated-styles.js'; |
5 | 6 | import '../vaadin-multi-select-combo-box.js'; |
6 | 7 |
|
7 | 8 | describe('validation', () => { |
8 | | - let comboBox, validateSpy; |
| 9 | + let comboBox, validateSpy, changeSpy, input; |
9 | 10 |
|
10 | 11 | describe('initial', () => { |
11 | 12 | beforeEach(() => { |
@@ -44,7 +45,42 @@ describe('validation', () => { |
44 | 45 | beforeEach(() => { |
45 | 46 | comboBox = fixtureSync(`<vaadin-multi-select-combo-box></vaadin-multi-select-combo-box>`); |
46 | 47 | comboBox.items = ['apple', 'banana']; |
| 48 | + input = comboBox.inputElement; |
47 | 49 | validateSpy = sinon.spy(comboBox, 'validate'); |
| 50 | + changeSpy = sinon.spy(); |
| 51 | + comboBox.addEventListener('change', changeSpy); |
| 52 | + }); |
| 53 | + |
| 54 | + it('should validate on blur', () => { |
| 55 | + input.focus(); |
| 56 | + input.blur(); |
| 57 | + expect(validateSpy.calledOnce).to.be.true; |
| 58 | + }); |
| 59 | + |
| 60 | + it('should validate on outside click', () => { |
| 61 | + input.focus(); |
| 62 | + input.click(); |
| 63 | + outsideClick(); |
| 64 | + expect(validateSpy.calledOnce).to.be.true; |
| 65 | + }); |
| 66 | + |
| 67 | + it('should validate before change event on Enter', async () => { |
| 68 | + input.focus(); |
| 69 | + await sendKeys({ type: 'apple' }); |
| 70 | + await sendKeys({ press: 'Enter' }); |
| 71 | + expect(changeSpy.calledOnce).to.be.true; |
| 72 | + expect(validateSpy.calledOnce).to.be.true; |
| 73 | + expect(validateSpy.calledBefore(changeSpy)).to.be.true; |
| 74 | + }); |
| 75 | + |
| 76 | + it('should validate before change event on clear button click', () => { |
| 77 | + comboBox.clearButtonVisible = true; |
| 78 | + comboBox.value = 'apple'; |
| 79 | + validateSpy.resetHistory(); |
| 80 | + comboBox.$.clearButton.click(); |
| 81 | + expect(changeSpy.calledOnce).to.be.true; |
| 82 | + expect(validateSpy.calledOnce).to.be.true; |
| 83 | + expect(validateSpy.calledBefore(changeSpy)).to.be.true; |
48 | 84 | }); |
49 | 85 |
|
50 | 86 | it('should not validate on required change when no items are selected', () => { |
|
0 commit comments