Skip to content

Commit bbc6999

Browse files
authored
test: improve test coverage of blur validation (#6240)
1 parent b380caa commit bbc6999

3 files changed

Lines changed: 74 additions & 4 deletions

File tree

‎packages/combo-box/test/validation.test.js‎

Lines changed: 18 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import { expect } from '@esm-bundle/chai';
2-
import { fixtureSync, nextRender } from '@vaadin/testing-helpers';
2+
import { fixtureSync, nextRender, outsideClick } from '@vaadin/testing-helpers';
33
import { sendKeys } from '@web/test-runner-commands';
44
import sinon from 'sinon';
55
import './not-animated-styles.js';
@@ -32,6 +32,23 @@ describe('validation', () => {
3232
expect(validateSpy.calledOnce).to.be.true;
3333
});
3434

35+
it('should validate on outside click', () => {
36+
input.focus();
37+
input.click();
38+
outsideClick();
39+
expect(validateSpy.calledOnce).to.be.true;
40+
});
41+
42+
it('should validate before change event on outside click', async () => {
43+
input.focus();
44+
input.click();
45+
await sendKeys({ type: 'foo' });
46+
outsideClick();
47+
expect(changeSpy.calledOnce).to.be.true;
48+
expect(validateSpy.calledOnce).to.be.true;
49+
expect(validateSpy.calledBefore(changeSpy)).to.be.true;
50+
});
51+
3552
it('should validate before change event on blur', async () => {
3653
input.focus();
3754
await sendKeys({ type: 'foo' });

‎packages/multi-select-combo-box/test/validation.test.js‎

Lines changed: 38 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,12 @@
11
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';
34
import sinon from 'sinon';
45
import './not-animated-styles.js';
56
import '../vaadin-multi-select-combo-box.js';
67

78
describe('validation', () => {
8-
let comboBox, validateSpy;
9+
let comboBox, validateSpy, changeSpy, input;
910

1011
describe('initial', () => {
1112
beforeEach(() => {
@@ -44,7 +45,42 @@ describe('validation', () => {
4445
beforeEach(() => {
4546
comboBox = fixtureSync(`<vaadin-multi-select-combo-box></vaadin-multi-select-combo-box>`);
4647
comboBox.items = ['apple', 'banana'];
48+
input = comboBox.inputElement;
4749
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;
4884
});
4985

5086
it('should not validate on required change when no items are selected', () => {

‎packages/time-picker/test/validation.test.js‎

Lines changed: 18 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import { expect } from '@esm-bundle/chai';
2-
import { enter, fixtureSync, focusout, nextRender } from '@vaadin/testing-helpers';
2+
import { enter, fixtureSync, focusout, nextRender, outsideClick } from '@vaadin/testing-helpers';
33
import sinon from 'sinon';
44
import { TimePicker } from '../src/vaadin-time-picker.js';
55
import { setInputValue } from './helpers.js';
@@ -94,6 +94,23 @@ describe('validation', () => {
9494
expect(validateSpy.calledOnce).to.be.true;
9595
});
9696

97+
it('should validate on outside click', () => {
98+
input.focus();
99+
input.click();
100+
outsideClick();
101+
expect(validateSpy.calledOnce).to.be.true;
102+
});
103+
104+
it('should validate before change event on outside click', async () => {
105+
input.focus();
106+
input.click();
107+
setInputValue(timePicker, '12:00');
108+
outsideClick();
109+
expect(changeSpy.calledOnce).to.be.true;
110+
expect(validateSpy.calledOnce).to.be.true;
111+
expect(validateSpy.calledBefore(changeSpy)).to.be.true;
112+
});
113+
97114
it('should validate before change event on blur', () => {
98115
input.focus();
99116
setInputValue(timePicker, '12:00');

0 commit comments

Comments
 (0)