From 264983662eab082057a147599c00b927580a3815 Mon Sep 17 00:00:00 2001 From: Kristiyan Kostadinov Date: Tue, 18 Jan 2022 19:46:49 +0100 Subject: [PATCH] build: fix autocomplete CI failure Fixes a couple of failures that made it through due to an old PR. --- .../mdc-autocomplete/autocomplete.spec.ts | 29 +++++++++++++++++-- .../autocomplete/autocomplete-trigger.ts | 2 +- .../autocomplete/autocomplete.spec.ts | 11 ++++--- 3 files changed, 35 insertions(+), 7 deletions(-) diff --git a/src/material-experimental/mdc-autocomplete/autocomplete.spec.ts b/src/material-experimental/mdc-autocomplete/autocomplete.spec.ts index c9c71bd7cec8..e5b9b2a73c5d 100644 --- a/src/material-experimental/mdc-autocomplete/autocomplete.spec.ts +++ b/src/material-experimental/mdc-autocomplete/autocomplete.spec.ts @@ -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', () => { @@ -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; + 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); diff --git a/src/material/autocomplete/autocomplete-trigger.ts b/src/material/autocomplete/autocomplete-trigger.ts index dfdd0189b856..fa6f0b15d39e 100644 --- a/src/material/autocomplete/autocomplete-trigger.ts +++ b/src/material/autocomplete/autocomplete-trigger.ts @@ -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))), ); } diff --git a/src/material/autocomplete/autocomplete.spec.ts b/src/material/autocomplete/autocomplete.spec.ts index 611f2c3cd3e0..001e4070e9f0 100644 --- a/src/material/autocomplete/autocomplete.spec.ts +++ b/src/material/autocomplete/autocomplete.spec.ts @@ -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', () => { @@ -2882,8 +2884,9 @@ describe('MatAutocomplete', () => { zone.simulateZoneExit(); fixture.detectChanges(); - const options = - overlayContainerElement.querySelectorAll('mat-option') as NodeListOf; + const options = overlayContainerElement.querySelectorAll( + 'mat-option', + ) as NodeListOf; spyOn(input, 'focus').and.callFake(() => events.push('focus')); fixture.componentInstance.optionSelected.and.callFake(() => events.push('select'));