Skip to content

Commit e6a7fc1

Browse files
authored
test: move the custom-value-set event tests to a separate file (#5634)
1 parent 9b07c08 commit e6a7fc1

2 files changed

Lines changed: 146 additions & 133 deletions

File tree

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

Lines changed: 0 additions & 133 deletions
Original file line numberDiff line numberDiff line change
@@ -149,139 +149,6 @@ describe('Properties', () => {
149149
expect(comboBox.value).to.eql('foo');
150150
expect(input.value).to.eql('foo');
151151
});
152-
153-
describe('custom-value-set event', () => {
154-
beforeEach(() => {
155-
comboBox.items = ['a', 'b'];
156-
});
157-
158-
it('should be fired when custom value is set', () => {
159-
const spy = sinon.spy();
160-
comboBox.addEventListener('custom-value-set', spy);
161-
162-
comboBox.open();
163-
setInputValue(comboBox, 'foo');
164-
outsideClick();
165-
166-
expect(spy.callCount).to.eql(1);
167-
});
168-
169-
it('should not be fired when custom values are not allowed', () => {
170-
comboBox.allowCustomValue = false;
171-
172-
const spy = sinon.spy();
173-
comboBox.addEventListener('custom-value-set', spy);
174-
175-
comboBox.open();
176-
setInputValue(comboBox, 'foo');
177-
outsideClick();
178-
179-
expect(spy.callCount).to.eql(0);
180-
});
181-
182-
it('should not be fired when combo-box is read-only', () => {
183-
const spy = sinon.spy();
184-
comboBox.addEventListener('custom-value-set', spy);
185-
186-
comboBox.readonly = true;
187-
setInputValue(comboBox, 'foo');
188-
comboBox.focus();
189-
focusout(comboBox);
190-
191-
expect(spy.called).to.be.false;
192-
});
193-
194-
it('should be cancelable', () => {
195-
comboBox.addEventListener('custom-value-set', (e) => e.preventDefault());
196-
197-
comboBox.open();
198-
setInputValue(comboBox, 'foo');
199-
outsideClick();
200-
expect(comboBox.value).to.be.empty;
201-
});
202-
203-
it('should not be fired when clicking an item', () => {
204-
const spy = sinon.spy();
205-
comboBox.addEventListener('custom-value-set', spy);
206-
207-
comboBox.open();
208-
setInputValue(comboBox, 'a');
209-
clickItem(comboBox, 0);
210-
expect(spy.called).to.be.false;
211-
});
212-
213-
it('should not be fired when existing item is entered and overlay is closed', () => {
214-
const spy = sinon.spy();
215-
comboBox.addEventListener('custom-value-set', spy);
216-
217-
comboBox.open();
218-
setInputValue(comboBox, 'a');
219-
outsideClick();
220-
expect(spy.called).to.be.false;
221-
});
222-
223-
it('should not fire when the custom value equals the label of the selected item', () => {
224-
const spy = sinon.spy();
225-
comboBox.addEventListener('custom-value-set', spy);
226-
comboBox.selectedItem = {
227-
label: 'foo',
228-
value: 'bar',
229-
};
230-
231-
comboBox.open();
232-
setInputValue(comboBox, 'foo');
233-
outsideClick();
234-
235-
expect(spy.called).to.be.false;
236-
});
237-
238-
it('should fire when the custom value equals the value of the selected item', () => {
239-
const spy = sinon.spy();
240-
comboBox.addEventListener('custom-value-set', spy);
241-
comboBox.selectedItem = {
242-
label: 'foo',
243-
value: 'bar',
244-
};
245-
246-
comboBox.open();
247-
setInputValue(comboBox, 'bar');
248-
outsideClick();
249-
250-
expect(spy.calledOnce).to.be.true;
251-
});
252-
253-
it('should not fire twice when the custom value set listener causes blur', () => {
254-
const spy = sinon.spy();
255-
comboBox.addEventListener('custom-value-set', spy);
256-
257-
// Emulate opening the overlay that causes blur
258-
comboBox.addEventListener('custom-value-set', () => {
259-
comboBox.blur();
260-
});
261-
262-
comboBox.open();
263-
setInputValue(comboBox, 'foo');
264-
outsideClick();
265-
266-
expect(spy.calledOnce).to.be.true;
267-
});
268-
269-
it('should fire twice when another custom value is committed by the user', () => {
270-
const spy = sinon.spy();
271-
comboBox.addEventListener('custom-value-set', spy);
272-
273-
comboBox.open();
274-
setInputValue(comboBox, 'foo');
275-
outsideClick();
276-
277-
input.focus();
278-
setInputValue(comboBox, 'bar');
279-
outsideClick();
280-
focusout(input);
281-
282-
expect(spy.calledTwice).to.be.true;
283-
});
284-
});
285152
});
286153

287154
describe('label property', () => {
Lines changed: 146 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,146 @@
1+
import { expect } from '@esm-bundle/chai';
2+
import { fixtureSync, focusout } from '@vaadin/testing-helpers';
3+
import sinon from 'sinon';
4+
import './not-animated-styles.js';
5+
import '../vaadin-combo-box.js';
6+
import { clickItem, outsideClick, setInputValue } from './helpers.js';
7+
8+
describe('events', () => {
9+
let comboBox;
10+
11+
describe('custom-value-set event', () => {
12+
beforeEach(() => {
13+
comboBox = fixtureSync('<vaadin-combo-box></vaadin-combo-box>');
14+
comboBox.allowCustomValue = true;
15+
comboBox.items = ['a', 'b'];
16+
comboBox.inputElement.focus();
17+
});
18+
19+
it('should be fired when custom value is set', () => {
20+
const spy = sinon.spy();
21+
comboBox.addEventListener('custom-value-set', spy);
22+
23+
comboBox.open();
24+
setInputValue(comboBox, 'foo');
25+
outsideClick();
26+
27+
expect(spy.callCount).to.eql(1);
28+
});
29+
30+
it('should not be fired when custom values are not allowed', () => {
31+
comboBox.allowCustomValue = false;
32+
33+
const spy = sinon.spy();
34+
comboBox.addEventListener('custom-value-set', spy);
35+
36+
comboBox.open();
37+
setInputValue(comboBox, 'foo');
38+
outsideClick();
39+
40+
expect(spy.callCount).to.eql(0);
41+
});
42+
43+
it('should not be fired when combo-box is read-only', () => {
44+
const spy = sinon.spy();
45+
comboBox.addEventListener('custom-value-set', spy);
46+
47+
comboBox.readonly = true;
48+
setInputValue(comboBox, 'foo');
49+
comboBox.focus();
50+
focusout(comboBox);
51+
52+
expect(spy.called).to.be.false;
53+
});
54+
55+
it('should be cancelable', () => {
56+
comboBox.addEventListener('custom-value-set', (e) => e.preventDefault());
57+
58+
comboBox.open();
59+
setInputValue(comboBox, 'foo');
60+
outsideClick();
61+
expect(comboBox.value).to.be.empty;
62+
});
63+
64+
it('should not be fired when clicking an item', () => {
65+
const spy = sinon.spy();
66+
comboBox.addEventListener('custom-value-set', spy);
67+
68+
comboBox.open();
69+
setInputValue(comboBox, 'a');
70+
clickItem(comboBox, 0);
71+
expect(spy.called).to.be.false;
72+
});
73+
74+
it('should not be fired when existing item is entered and overlay is closed', () => {
75+
const spy = sinon.spy();
76+
comboBox.addEventListener('custom-value-set', spy);
77+
78+
comboBox.open();
79+
setInputValue(comboBox, 'a');
80+
outsideClick();
81+
expect(spy.called).to.be.false;
82+
});
83+
84+
it('should not be fired when the custom value equals the label of the selected item', () => {
85+
const spy = sinon.spy();
86+
comboBox.addEventListener('custom-value-set', spy);
87+
comboBox.selectedItem = {
88+
label: 'foo',
89+
value: 'bar',
90+
};
91+
92+
comboBox.open();
93+
setInputValue(comboBox, 'foo');
94+
outsideClick();
95+
96+
expect(spy.called).to.be.false;
97+
});
98+
99+
it('should be fired when the custom value equals the value of the selected item', () => {
100+
const spy = sinon.spy();
101+
comboBox.addEventListener('custom-value-set', spy);
102+
comboBox.selectedItem = {
103+
label: 'foo',
104+
value: 'bar',
105+
};
106+
107+
comboBox.open();
108+
setInputValue(comboBox, 'bar');
109+
outsideClick();
110+
111+
expect(spy.calledOnce).to.be.true;
112+
});
113+
114+
it('should not be fired twice when the custom value set listener causes blur', () => {
115+
const spy = sinon.spy();
116+
comboBox.addEventListener('custom-value-set', spy);
117+
118+
// Emulate opening the overlay that causes blur
119+
comboBox.addEventListener('custom-value-set', () => {
120+
comboBox.blur();
121+
});
122+
123+
comboBox.open();
124+
setInputValue(comboBox, 'foo');
125+
outsideClick();
126+
127+
expect(spy.calledOnce).to.be.true;
128+
});
129+
130+
it('should be fired twice when another custom value is committed by the user', () => {
131+
const spy = sinon.spy();
132+
comboBox.addEventListener('custom-value-set', spy);
133+
134+
comboBox.open();
135+
setInputValue(comboBox, 'foo');
136+
outsideClick();
137+
138+
comboBox.inputElement.focus();
139+
setInputValue(comboBox, 'bar');
140+
outsideClick();
141+
focusout(comboBox.inputElement);
142+
143+
expect(spy.calledTwice).to.be.true;
144+
});
145+
});
146+
});

0 commit comments

Comments
 (0)