Skip to content

Commit 77e3181

Browse files
committed
fixup! test(cdk-experimental/combobox): add unit tests
1 parent 07842ea commit 77e3181

File tree

2 files changed

+135
-39
lines changed

2 files changed

+135
-39
lines changed

src/cdk-experimental/combobox/combobox.spec.ts

Lines changed: 134 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -171,43 +171,6 @@ describe('Combobox', () => {
171171
});
172172
});
173173

174-
describe('Expansion', () => {
175-
beforeEach(() => setupCombobox());
176-
177-
it('should open on click', () => {
178-
click(inputElement);
179-
expect(comboboxInstance.pattern.expanded()).toBe(true);
180-
});
181-
182-
it('should open on ArrowDown', () => {
183-
keydown('ArrowDown');
184-
expect(comboboxInstance.pattern.expanded()).toBe(true);
185-
});
186-
187-
it('should open on ArrowUp', () => {
188-
keydown('ArrowUp');
189-
expect(comboboxInstance.pattern.expanded()).toBe(true);
190-
});
191-
192-
it('should close on Escape', () => {
193-
down();
194-
escape();
195-
expect(comboboxInstance.pattern.expanded()).toBe(false);
196-
});
197-
198-
it('should close on focusout', () => {
199-
focus();
200-
blur();
201-
expect(comboboxInstance.pattern.expanded()).toBe(false);
202-
});
203-
204-
it('should not close on focusout if focus moves to an element inside the container', () => {
205-
down();
206-
blur(getOptions()[0]!);
207-
expect(comboboxInstance.pattern.expanded()).toBe(true);
208-
});
209-
});
210-
211174
describe('Navigation', () => {
212175
beforeEach(() => setupCombobox());
213176

@@ -258,6 +221,73 @@ describe('Combobox', () => {
258221
});
259222
});
260223

224+
describe('Expansion', () => {
225+
beforeEach(() => setupCombobox());
226+
227+
it('should open on click', () => {
228+
focus();
229+
click(inputElement);
230+
expect(inputElement.getAttribute('aria-expanded')).toBe('true');
231+
});
232+
233+
it('should open on ArrowDown', () => {
234+
focus();
235+
keydown('ArrowDown');
236+
expect(inputElement.getAttribute('aria-expanded')).toBe('true');
237+
});
238+
239+
it('should open on ArrowUp', () => {
240+
focus();
241+
keydown('ArrowUp');
242+
expect(inputElement.getAttribute('aria-expanded')).toBe('true');
243+
});
244+
245+
it('should close on Escape', () => {
246+
down();
247+
escape();
248+
expect(inputElement.getAttribute('aria-expanded')).toBe('false');
249+
});
250+
251+
it('should close on focusout', () => {
252+
focus();
253+
blur();
254+
expect(inputElement.getAttribute('aria-expanded')).toBe('false');
255+
});
256+
257+
it('should not close on focusout if focus moves to an element inside the container', () => {
258+
down();
259+
blur(getOption('Apple')!);
260+
expect(inputElement.getAttribute('aria-expanded')).toBe('true');
261+
});
262+
263+
it('should clear the completion string and not close on escape when a completion is present', () => {
264+
fixture.componentInstance.filterMode.set('highlight');
265+
focus();
266+
input('A');
267+
expect(inputElement.value).toBe('Apple');
268+
expect(inputElement.getAttribute('aria-expanded')).toBe('true');
269+
escape();
270+
expect(inputElement.value).toBe('A');
271+
expect(inputElement.getAttribute('aria-expanded')).toBe('true');
272+
escape();
273+
expect(inputElement.value).toBe('A');
274+
expect(inputElement.getAttribute('aria-expanded')).toBe('false');
275+
});
276+
277+
it('should close on enter', () => {
278+
down();
279+
enter();
280+
expect(inputElement.getAttribute('aria-expanded')).toBe('false');
281+
});
282+
283+
it('should close on click to select an item', () => {
284+
down();
285+
const fruitItem = getOption('Apple')!;
286+
click(fruitItem);
287+
expect(inputElement.getAttribute('aria-expanded')).toBe('false');
288+
});
289+
});
290+
261291
describe('Selection', () => {
262292
describe('when filterMode is "manual"', () => {
263293
beforeEach(() => setupCombobox({filterMode: 'manual'}));
@@ -955,6 +985,73 @@ describe('Combobox', () => {
955985
});
956986
});
957987

988+
describe('Expansion', () => {
989+
beforeEach(() => setupCombobox());
990+
991+
it('should open on click', () => {
992+
focus();
993+
click(inputElement);
994+
expect(inputElement.getAttribute('aria-expanded')).toBe('true');
995+
});
996+
997+
it('should open on ArrowDown', () => {
998+
focus();
999+
keydown('ArrowDown');
1000+
expect(inputElement.getAttribute('aria-expanded')).toBe('true');
1001+
});
1002+
1003+
it('should open on ArrowUp', () => {
1004+
focus();
1005+
keydown('ArrowUp');
1006+
expect(inputElement.getAttribute('aria-expanded')).toBe('true');
1007+
});
1008+
1009+
it('should close on Escape', () => {
1010+
down();
1011+
escape();
1012+
expect(inputElement.getAttribute('aria-expanded')).toBe('false');
1013+
});
1014+
1015+
it('should close on focusout', () => {
1016+
focus();
1017+
blur();
1018+
expect(inputElement.getAttribute('aria-expanded')).toBe('false');
1019+
});
1020+
1021+
it('should not close on focusout if focus moves to an element inside the container', () => {
1022+
down();
1023+
blur(getTreeItem('Fruit')!);
1024+
expect(inputElement.getAttribute('aria-expanded')).toBe('true');
1025+
});
1026+
1027+
it('should clear the completion string and not close on escape when a completion is present', () => {
1028+
fixture.componentInstance.filterMode.set('highlight');
1029+
focus();
1030+
input('A');
1031+
expect(inputElement.value).toBe('Apple');
1032+
expect(inputElement.getAttribute('aria-expanded')).toBe('true');
1033+
escape();
1034+
expect(inputElement.value).toBe('A');
1035+
expect(inputElement.getAttribute('aria-expanded')).toBe('true');
1036+
escape();
1037+
expect(inputElement.value).toBe('A');
1038+
expect(inputElement.getAttribute('aria-expanded')).toBe('false');
1039+
});
1040+
1041+
it('should close on enter', () => {
1042+
down();
1043+
enter();
1044+
expect(inputElement.getAttribute('aria-expanded')).toBe('false');
1045+
});
1046+
1047+
it('should close on click to select an item', () => {
1048+
down();
1049+
const fruitItem = getTreeItem('Fruit')!;
1050+
click(fruitItem);
1051+
expect(inputElement.getAttribute('aria-expanded')).toBe('false');
1052+
});
1053+
});
1054+
9581055
describe('with disabled items', () => {
9591056
beforeEach(() => {
9601057
setupCombobox();
@@ -1260,7 +1357,6 @@ class ComboboxListboxExample {
12601357
</ng-template>
12611358
</div>
12621359
`,
1263-
standalone: true,
12641360
imports: [
12651361
CdkCombobox,
12661362
CdkComboboxInput,

src/cdk-experimental/ui-patterns/combobox/combobox.spec.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -683,7 +683,7 @@ describe('Combobox with Tree Pattern', () => {
683683
});
684684

685685
it('should select on focusout if the input text exactly matches an item', () => {
686-
const {combobox, tree, inputEl} = getPatterns({filterMode: 'manual'});
686+
const {combobox, inputEl} = getPatterns({filterMode: 'manual'});
687687
combobox.onPointerup(clickInput(inputEl));
688688
inputEl.value = 'Apple';
689689
combobox.onInput(new InputEvent('input'));

0 commit comments

Comments
 (0)