build(aio): ensure that tutorial index arrives in the tutorial search area

Fixes #16457
This commit is contained in:
Peter Bacon Darwin 2017-05-03 23:11:12 +01:00 committed by Pete Bacon Darwin
parent 5bc435eba3
commit 8931e71c5c
2 changed files with 17 additions and 0 deletions

View File

@ -69,6 +69,19 @@ describe('SearchResultsComponent', () => {
]);
});
it('should special case results that are top level folders', () => {
searchResults.next({ query: '', results: [
{ path: 'tutorial', title: 'Tutorial index', type: '', keywords: '', titleWords: '' },
{ path: 'tutorial/toh-pt1', title: 'Tutorial - part 1', type: '', keywords: '', titleWords: '' },
]});
expect(currentAreas).toEqual([
{ name: 'tutorial', pages: [
{ path: 'tutorial/toh-pt1', title: 'Tutorial - part 1', type: '', keywords: '', titleWords: '' },
{ path: 'tutorial', title: 'Tutorial index', type: '', keywords: '', titleWords: '' },
], priorityPages: [] }
]);
});
it('should sort by title within sorted area', () => {
const results = getTestResults(5);
searchResults.next({ query: '', results: results });

View File

@ -20,6 +20,7 @@ export interface SearchArea {
export class SearchResultsComponent implements OnInit {
readonly defaultArea = 'other';
readonly topLevelFolders = ['guide', 'tutorial'];
notFound = false;
@ -76,6 +77,9 @@ export class SearchResultsComponent implements OnInit {
// Split the search result path and use the top level folder, if there is one, as the area name.
private computeAreaName(result: SearchResult) {
if (this.topLevelFolders.indexOf(result.path) !== -1) {
return result.path;
}
const [areaName, rest] = result.path.split('/', 2);
return rest && areaName;
}