New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
build(aio): compute `{@link ...} titles more effectively #16813
Merged
Merged
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
51 changes: 51 additions & 0 deletions
51
aio/tools/transforms/links-package/services/getLinkInfo.spec.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,51 @@ | ||
const testPackage = require('../../helpers/test-package'); | ||
const Dgeni = require('dgeni'); | ||
|
||
let getLinkInfo, aliasMap; | ||
|
||
describe('getLinkInfo', () => { | ||
beforeEach(function() { | ||
var dgeni = new Dgeni([testPackage('links-package', true)]); | ||
var injector = dgeni.configureInjector(); | ||
aliasMap = injector.get('aliasMap'); | ||
getLinkInfo = injector.get('getLinkInfo'); | ||
}); | ||
|
||
it('should use the title if specified', () => { | ||
aliasMap.addDoc({ docType: 'guide', title: 'Browser Support', name: 'browser-support', id: 'guide/browser-support', aliases: ['guide/browser-support', 'browser-support'], path: 'guide/browser-support' }); | ||
const currentDoc = { }; | ||
const linkInfo = getLinkInfo('browser-support', '"Browser Support Guide"', currentDoc); | ||
expect(linkInfo.title).toBe('"Browser Support Guide"'); | ||
}); | ||
|
||
it('should set the link to invalid if the title is `undefined`', () => { | ||
aliasMap.addDoc({ docType: 'guide', id: 'guide/browser-support', aliases: ['guide/browser-support', 'browser-support'], path: 'guide/browser-support' }); | ||
const currentDoc = { }; | ||
const linkInfo = getLinkInfo('browser-support', undefined, currentDoc); | ||
expect(linkInfo.valid).toBe(false); | ||
}); | ||
|
||
it('should use the target document title if available and no title is specified', () => { | ||
aliasMap.addDoc({ docType: 'guide', title: 'Browser Support', id: 'guide/browser-support', aliases: ['guide/browser-support', 'browser-support'], path: 'guide/browser-support' }); | ||
const currentDoc = { }; | ||
const linkInfo = getLinkInfo('browser-support', undefined, currentDoc); | ||
expect(linkInfo.valid).toBe(true); | ||
expect(linkInfo.title).toEqual('Browser Support'); | ||
}); | ||
|
||
it('should prefer the target doc title over name if available and no title is specified', () => { | ||
aliasMap.addDoc({ docType: 'guide', title: 'Browser Support', name: 'browser-support', id: 'guide/browser-support', aliases: ['guide/browser-support', 'browser-support'], path: 'guide/browser-support' }); | ||
const currentDoc = { }; | ||
const linkInfo = getLinkInfo('browser-support', undefined, currentDoc); | ||
expect(linkInfo.valid).toBe(true); | ||
expect(linkInfo.title).toEqual('Browser Support'); | ||
}); | ||
|
||
it('should use the target document name as a code block if available and no title is specified', () => { | ||
aliasMap.addDoc({ docType: 'api', name: 'CurrencyPipe', id: 'common/CurrencyPipe', aliases: ['common/CurrencyPipe', 'CurrencyPipe'], path: 'api/common/CurrencyPipe' }); | ||
const currentDoc = { }; | ||
const linkInfo = getLinkInfo('CurrencyPipe', undefined, currentDoc); | ||
expect(linkInfo.valid).toBe(true); | ||
expect(linkInfo.title).toEqual('<code>CurrencyPipe</code>'); | ||
}); | ||
}); | ||
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
No test for preference to
.title
over.name
😞There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
In general docs either have a name OR a title. But I guess I could add a test - just for you @gkalpak :-)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
No test for preference of specified
title
overdoc.title
/doc.name
(last one, I promise 😛)(LGTM already, so fee free to merge without.)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
added :-P