build(aio): the the captured h1 as the title for the search index

If there is no title already provided, use the one captured from the renderedContent.
This commit is contained in:
Peter Bacon Darwin
2017-05-30 22:24:54 +03:00
committed by Pete Bacon Darwin
parent 89f317915d
commit dfbbbb5e3e
3 changed files with 39 additions and 9 deletions

View File

@ -18,12 +18,12 @@ describe('generateKeywords processor', () => {
it('should run after the correct processor', () => {
const processor = processorFactory(mockLogger, mockReadFilesProcessor);
expect(processor.$runAfter).toEqual(['paths-computed']);
expect(processor.$runAfter).toEqual(['postProcessHtml']);
});
it('should run before the correct processor', () => {
const processor = processorFactory(mockLogger, mockReadFilesProcessor);
expect(processor.$runBefore).toEqual(['rendering-docs']);
expect(processor.$runBefore).toEqual(['writing-files']);
});
it('should ignore internal and private exports', () => {
@ -39,7 +39,24 @@ describe('generateKeywords processor', () => {
]);
});
it('should use `doc.searchTitle` as the title if available', () => {
it('should compute `doc.searchTitle` from the doc properties if not already provided', () => {
const processor = processorFactory(mockLogger, mockReadFilesProcessor);
const docs = [
{ docType: 'class', name: 'A', searchTitle: 'searchTitle A', title: 'title A', vFile: { title: 'vFile A'} },
{ docType: 'class', name: 'B', title: 'title B', vFile: { title: 'vFile B'} },
{ docType: 'class', name: 'C', vFile: { title: 'vFile C'} },
{ docType: 'class', name: 'D' },
];
processor.$process(docs);
expect(docs[docs.length - 1].data).toEqual([
jasmine.objectContaining({ title: 'searchTitle A' }),
jasmine.objectContaining({ title: 'title B' }),
jasmine.objectContaining({ title: 'vFile C' }),
jasmine.objectContaining({ title: 'D' }),
]);
});
it('should use `doc.searchTitle` as the title in the search index', () => {
const processor = processorFactory(mockLogger, mockReadFilesProcessor);
const docs = [
{ docType: 'class', name: 'PublicExport', searchTitle: 'class PublicExport' },
@ -49,4 +66,15 @@ describe('generateKeywords processor', () => {
jasmine.objectContaining({ title: 'class PublicExport', type: 'class'})
]);
});
it('should generate renderedContent property', () => {
const processor = processorFactory(mockLogger, mockReadFilesProcessor);
const docs = [
{ docType: 'class', name: 'SomeClass', description: 'The is the documentation for the SomeClass API.' },
];
processor.$process(docs);
expect(docs[docs.length - 1].renderedContent).toEqual(
'[{"title":"SomeClass","type":"class","titleWords":"SomeClass","keywords":"api class documentation for is someclass the","members":""}]'
);
});
});