diff --git a/lib/content-services/search/components/search-control.component.html b/lib/content-services/search/components/search-control.component.html
index 899e739fa8..e403263691 100644
--- a/lib/content-services/search/components/search-control.component.html
+++ b/lib/content-services/search/components/search-control.component.html
@@ -1,5 +1,5 @@
-
+
search
- {
beforeEach(async(() => {
TestBed.configureTestingModule({
imports: [
- MaterialModule
+ MaterialModule,
+ NoopAnimationsModule
],
declarations: [
SearchControlComponent,
@@ -408,31 +410,53 @@ describe('SearchControlComponent', () => {
describe('search button', () => {
- it('should NOT display a autocomplete list control when configured not to', async(() => {
+ it('should NOT display a autocomplete list control when configured not to', fakeAsync(() => {
fixture.detectChanges();
let searchButton: DebugElement = debugElement.query(By.css('#adf-search-button'));
component.subscriptAnimationState = 'active';
fixture.detectChanges();
expect(component.subscriptAnimationState).toBe('active');
+
searchButton.triggerEventHandler('click', null);
- window.setTimeout(() => {
- fixture.detectChanges();
- expect(component.subscriptAnimationState).toBe('inactive');
- }, 100);
+ fixture.detectChanges();
+
+ tick(100);
+ fixture.detectChanges();
+ expect(component.subscriptAnimationState).toBe('inactive');
+ discardPeriodicTasks();
}));
- it('click on the search button should open the input box when is close', (done) => {
+ it('click on the search button should open the input box when is close', fakeAsync(() => {
fixture.detectChanges();
+
let searchButton: DebugElement = debugElement.query(By.css('#adf-search-button'));
searchButton.triggerEventHandler('click', null);
- window.setTimeout(() => {
- fixture.detectChanges();
- expect(component.subscriptAnimationState).toBe('active');
- done();
- }, 100);
- });
- it('Search button should not change the input state too often', async(() => {
+ tick(100);
+ fixture.detectChanges();
+ expect(component.subscriptAnimationState).toBe('active');
+ discardPeriodicTasks();
+ }));
+
+ it('click on the search button should apply focus on input', fakeAsync(() => {
+ fixture = TestBed.createComponent(SearchControlComponent);
+ debugElement = fixture.debugElement;
+ fixture.detectChanges();
+ let searchButton: DebugElement = debugElement.query(By.css('#adf-search-button'));
+ let inputDebugElement = debugElement.query(By.css('#adf-control-input'));
+
+ searchButton.triggerEventHandler('click', null);
+
+ tick(100);
+ fixture.detectChanges();
+
+ tick(300);
+ fixture.detectChanges();
+ expect(document.activeElement.id).toBe(inputDebugElement.nativeElement.id);
+ discardPeriodicTasks();
+ }));
+
+ it('Search button should not change the input state too often', fakeAsync(() => {
fixture.detectChanges();
let searchButton: DebugElement = debugElement.query(By.css('#adf-search-button'));
component.subscriptAnimationState = 'active';
@@ -443,13 +467,13 @@ describe('SearchControlComponent', () => {
searchButton.triggerEventHandler('click', null);
fixture.detectChanges();
- window.setTimeout(() => {
- fixture.detectChanges();
- expect(component.subscriptAnimationState).toBe('inactive');
- }, 100);
+ tick(100);
+ fixture.detectChanges();
+ expect(component.subscriptAnimationState).toBe('inactive');
+ discardPeriodicTasks();
}));
- it('Search bar should close when user press ESC button', async(() => {
+ it('Search bar should close when user press ESC button', fakeAsync(() => {
fixture.detectChanges();
let inputDebugElement = debugElement.query(By.css('#adf-control-input'));
component.subscriptAnimationState = 'active';
@@ -457,10 +481,11 @@ describe('SearchControlComponent', () => {
expect(component.subscriptAnimationState).toBe('active');
inputDebugElement.triggerEventHandler('keyup.escape', {});
- window.setTimeout(() => {
- fixture.detectChanges();
- expect(component.subscriptAnimationState).toBe('inactive');
- }, 100);
+
+ tick(100);
+ fixture.detectChanges();
+ expect(component.subscriptAnimationState).toBe('inactive');
+ discardPeriodicTasks();
}));
});
diff --git a/lib/content-services/search/components/search-control.component.ts b/lib/content-services/search/components/search-control.component.ts
index d279ad5431..30c47fb815 100644
--- a/lib/content-services/search/components/search-control.component.ts
+++ b/lib/content-services/search/components/search-control.component.ts
@@ -78,8 +78,8 @@ export class SearchControlComponent implements OnInit, OnDestroy {
@ViewChild(SearchComponent)
searchAutocomplete: SearchComponent;
- @ViewChild('inputSearch')
- inputSearch: ElementRef;
+ @ViewChild('searchInput')
+ searchInput: ElementRef;
@ViewChildren(MatListItem)
private listResultElement: QueryList;
@@ -100,14 +100,20 @@ export class SearchControlComponent implements OnInit, OnDestroy {
if (this.subscriptAnimationState === 'inactive') {
this.searchTerm = '';
this.searchAutocomplete.resetResults();
- if ( document.activeElement.id === this.inputSearch.nativeElement.id) {
- this.inputSearch.nativeElement.blur();
+ if ( document.activeElement.id === this.searchInput.nativeElement.id) {
+ this.searchInput.nativeElement.blur();
}
}
}
});
}
+ applySearchFocus(animationDoneEvent) {
+ if (animationDoneEvent.toState === 'active') {
+ this.searchInput.nativeElement.focus();
+ }
+ }
+
ngOnInit() {
this.subscriptAnimationState = this.expandable ? 'inactive' : 'no-animation';
this.setupFocusEventHandlers();
@@ -205,7 +211,7 @@ export class SearchControlComponent implements OnInit, OnDestroy {
if (previousElement) {
previousElement.focus();
}else {
- this.inputSearch.nativeElement.focus();
+ this.searchInput.nativeElement.focus();
this.focusSubject.next(new FocusEvent('focus'));
}
}