diff --git a/aio/src/app/search/search-results/search-results.component.html b/aio/src/app/search/search-results/search-results.component.html index f4209dce2a..b801b1afa9 100644 --- a/aio/src/app/search/search-results/search-results.component.html +++ b/aio/src/app/search/search-results/search-results.component.html @@ -1,4 +1,4 @@ -
+

Search Results

{{area.name}}

@@ -9,4 +9,6 @@
- +
+

No results found.

+
diff --git a/aio/src/app/search/search-results/search-results.component.spec.ts b/aio/src/app/search/search-results/search-results.component.spec.ts index d6beda7214..bc460cdc2a 100644 --- a/aio/src/app/search/search-results/search-results.component.spec.ts +++ b/aio/src/app/search/search-results/search-results.component.spec.ts @@ -13,6 +13,9 @@ describe('SearchResultsComponent', () => { let searchResults: Subject; let currentAreas: SearchArea[]; + /** Get all text from component element */ + function getText() { return fixture.debugElement.nativeElement.innerText; } + beforeEach(async(() => { TestBed.configureTestingModule({ declarations: [ SearchResultsComponent ], @@ -138,7 +141,30 @@ describe('SearchResultsComponent', () => { fixture.detectChanges(); component.hideResults(); fixture.detectChanges(); - expect(fixture.debugElement.queryAll(By.css('a'))).toEqual([]); + expect(getText()).toBe(''); + }); + }); + + describe('when no query results', () => { + + it('should display "not found" message', () => { + searchResults.next({ query: 'something', results: [] }); + fixture.detectChanges(); + expect(getText()).toContain('No results'); + }); + + it('should not display "not found" message after hideResults()', () => { + searchResults.next({ query: 'something', results: [] }); + fixture.detectChanges(); + component.hideResults(); + fixture.detectChanges(); + expect(getText()).toBe(''); + }); + + it('should not display "not found" message when query is empty', () => { + searchResults.next({ query: '', results: [] }); + fixture.detectChanges(); + expect(getText()).toBe(''); }); }); }); diff --git a/aio/src/app/search/search-results/search-results.component.ts b/aio/src/app/search/search-results/search-results.component.ts index 93a64751d3..5736dd2703 100644 --- a/aio/src/app/search/search-results/search-results.component.ts +++ b/aio/src/app/search/search-results/search-results.component.ts @@ -20,7 +20,7 @@ export class SearchResultsComponent implements OnInit { readonly defaultArea = 'other'; - showResults = false; + notFound = false; @Output() resultSelected = new EventEmitter(); @@ -29,6 +29,7 @@ export class SearchResultsComponent implements OnInit { * A mapping of the search results grouped into areas */ searchAreas = new ReplaySubject(1); + hasAreas = this.searchAreas.map(areas => areas.length > 0); constructor(private searchService: SearchService) {} @@ -50,11 +51,12 @@ export class SearchResultsComponent implements OnInit { hideResults() { this.searchAreas.next([]); + this.notFound = false; } // Map the search results into groups by area private processSearchResults(search: SearchResults) { - this.showResults = true; + this.notFound = search.query.trim() && search.results.length === 0; const searchAreaMap = {}; search.results.forEach(result => { if (!result.title) { return; } // bad data; should fix