Skip to content

Commit

Permalink
build: fix autocomplete CI failure (#24226)
Browse files Browse the repository at this point in the history
Fixes a couple of failures that made it through due to an old PR.

(cherry picked from commit 63d4b73)
  • Loading branch information
crisbeto authored and andrewseguin committed Jan 18, 2022
1 parent 402c07b commit 31c8fc1
Show file tree
Hide file tree
Showing 3 changed files with 35 additions and 7 deletions.
29 changes: 27 additions & 2 deletions src/material-experimental/mdc-autocomplete/autocomplete.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1101,8 +1101,10 @@ describe('MDC-based MatAutocomplete', () => {

expect(trigger.panelOpen).toBe(true, 'Expected panel to remain open.');
expect(input.value).toBeFalsy('Expected input to remain blank.');
expect(ENTER_EVENT.defaultPrevented)
.toBe(false, 'Expected the default ENTER action not to have been prevented.');
expect(ENTER_EVENT.defaultPrevented).toBe(
false,
'Expected the default ENTER action not to have been prevented.',
);
}));

it('should fill the text field, not select an option, when SPACE is entered', () => {
Expand Down Expand Up @@ -2868,6 +2870,29 @@ describe('MDC-based MatAutocomplete', () => {
expect(event.option.value).toBe('Washington');
}));

it('should refocus the input after the selection event is emitted', fakeAsync(() => {
const events: string[] = [];
const fixture = createComponent(AutocompleteWithSelectEvent);
fixture.detectChanges();
const input = fixture.nativeElement.querySelector('input');

fixture.componentInstance.trigger.openPanel();
zone.simulateZoneExit();
fixture.detectChanges();

const options = overlayContainerElement.querySelectorAll(
'mat-option',
) as NodeListOf<HTMLElement>;
spyOn(input, 'focus').and.callFake(() => events.push('focus'));
fixture.componentInstance.optionSelected.and.callFake(() => events.push('select'));

options[1].click();
tick();
fixture.detectChanges();

expect(events).toEqual(['select', 'focus']);
}));

it('should emit an event when a newly-added option is selected', fakeAsync(() => {
let fixture = createComponent(AutocompleteWithSelectEvent);

Expand Down
2 changes: 1 addition & 1 deletion src/material/autocomplete/autocomplete-trigger.ts
Original file line number Diff line number Diff line change
Expand Up @@ -316,7 +316,7 @@ export abstract class _MatAutocompleteTriggerBase
if (options) {
return options.changes.pipe(
startWith(options),
switchMap(() => merge(...options.map(option => option.onSelectionChange)))
switchMap(() => merge(...options.map(option => option.onSelectionChange))),
);
}

Expand Down
11 changes: 7 additions & 4 deletions src/material/autocomplete/autocomplete.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1097,8 +1097,10 @@ describe('MatAutocomplete', () => {

expect(trigger.panelOpen).toBe(true, 'Expected panel to remain open.');
expect(input.value).toBeFalsy('Expected input to remain blank.');
expect(ENTER_EVENT.defaultPrevented)
.toBe(false, 'Expected the default ENTER action not to have been prevented.');
expect(ENTER_EVENT.defaultPrevented).toBe(
false,
'Expected the default ENTER action not to have been prevented.',
);
}));

it('should fill the text field, not select an option, when SPACE is entered', () => {
Expand Down Expand Up @@ -2882,8 +2884,9 @@ describe('MatAutocomplete', () => {
zone.simulateZoneExit();
fixture.detectChanges();

const options =
overlayContainerElement.querySelectorAll('mat-option') as NodeListOf<HTMLElement>;
const options = overlayContainerElement.querySelectorAll(
'mat-option',
) as NodeListOf<HTMLElement>;
spyOn(input, 'focus').and.callFake(() => events.push('focus'));
fixture.componentInstance.optionSelected.and.callFake(() => events.push('select'));

Expand Down

0 comments on commit 31c8fc1

Please sign in to comment.