Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Move linkComponents settings to util
- Loading branch information
Showing
3 changed files
with
60 additions
and
10 deletions.
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
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,20 @@ | ||
/** | ||
* @fileoverview Utility functions for propWrapperFunctions setting | ||
*/ | ||
'use strict'; | ||
|
||
const DEFAULT_LINK_COMPONENTS = ['a']; | ||
const DEFAULT_LINK_ATTRIBUTE = 'href'; | ||
|
||
function getLinkComponents(context) { | ||
const settings = context.settings || {}; | ||
return new Map((DEFAULT_LINK_COMPONENTS.concat(settings.linkComponents || [])).map(value => { | ||
const name = typeof value === 'string' ? value : value.name; | ||
const linkAttribute = typeof value === 'string' ? DEFAULT_LINK_ATTRIBUTE : value.linkAttribute; | ||
return [name, linkAttribute]; | ||
})); | ||
} | ||
|
||
module.exports = { | ||
getLinkComponents: getLinkComponents | ||
}; |
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,36 @@ | ||
/* eslint-env mocha */ | ||
'use strict'; | ||
|
||
const assert = require('assert'); | ||
const linkComponentsUtil = require('../../lib/util/linkComponents'); | ||
|
||
describe('linkComponentsFunctions', () => { | ||
describe('getLinkComponents', () => { | ||
it('returns a default map of components', () => { | ||
const context = {}; | ||
assert.deepStrictEqual(linkComponentsUtil.getLinkComponents(context), new Map([ | ||
['a', 'href'] | ||
])); | ||
}); | ||
|
||
it('returns a map of components', () => { | ||
const linkComponents = [ | ||
'Hyperlink', | ||
{ | ||
name: 'Link', | ||
linkAttribute: 'to' | ||
} | ||
]; | ||
const context = { | ||
settings: { | ||
linkComponents: linkComponents | ||
} | ||
}; | ||
assert.deepStrictEqual(linkComponentsUtil.getLinkComponents(context), new Map([ | ||
['a', 'href'], | ||
['Hyperlink', 'href'], | ||
['Link', 'to'] | ||
])); | ||
}); | ||
}); | ||
}); |