display(highlighting): improve for camel_case
This commit is contained in:
parent
acd00fc1d2
commit
de36e1ca5d
2 changed files with 55 additions and 5 deletions
|
|
@ -195,12 +195,21 @@ let utils = {
|
|||
* @return {string}
|
||||
**/
|
||||
getHighlightedValue(object, property) {
|
||||
if (!object._highlightResult
|
||||
|| !object._highlightResult[property]
|
||||
|| !object._highlightResult[property].value) {
|
||||
return object[property];
|
||||
if (object._highlightResult
|
||||
&& object._highlightResult.hierarchy_camel
|
||||
&& object._highlightResult.hierarchy_camel[property]
|
||||
&& object._highlightResult.hierarchy_camel[property].matchLevel
|
||||
&& object._highlightResult.hierarchy_camel[property].matchLevel !== 'none'
|
||||
&& object._highlightResult.hierarchy_camel[property].value) {
|
||||
return object._highlightResult.hierarchy_camel[property].value;
|
||||
}
|
||||
return object._highlightResult[property].value;
|
||||
if (object._highlightResult
|
||||
&& object._highlightResult
|
||||
&& object._highlightResult[property]
|
||||
&& object._highlightResult[property].value) {
|
||||
return object._highlightResult[property].value;
|
||||
}
|
||||
return object[property];
|
||||
},
|
||||
/*
|
||||
* Returns the snippeted value of the specified key in the specified object.
|
||||
|
|
|
|||
|
|
@ -622,6 +622,47 @@ describe('DocSearch', () => {
|
|||
expect(actual[0].category).toEqual('<mark>Ruby</mark>');
|
||||
expect(actual[0].subcategory).toEqual('<mark>API</mark>');
|
||||
});
|
||||
|
||||
it('should use highlighted camel if exists and matchLevel not none', () => {
|
||||
// Given
|
||||
let input = [{
|
||||
hierarchy: {
|
||||
lvl0: 'Ruby',
|
||||
lvl1: 'API',
|
||||
lvl2: 'Foo',
|
||||
lvl3: null,
|
||||
lvl4: null,
|
||||
lvl5: null
|
||||
},
|
||||
_highlightResult: {
|
||||
hierarchy_camel: {
|
||||
lvl0: {
|
||||
value: '<mark>Python</mark>',
|
||||
matchLevel: 'full'
|
||||
},
|
||||
lvl1: {
|
||||
value: '<mark>API2</mark>',
|
||||
matchLevel: 'full'
|
||||
}
|
||||
},
|
||||
hierarchy: {
|
||||
lvl0: {
|
||||
value: '<mark>Ruby</mark>'
|
||||
},
|
||||
lvl1: {
|
||||
value: '<mark>API</mark>'
|
||||
}
|
||||
}
|
||||
}
|
||||
}];
|
||||
|
||||
// When
|
||||
let actual = DocSearch.formatHits(input);
|
||||
|
||||
// Then
|
||||
expect(actual[0].category).toEqual('<mark>Python</mark>');
|
||||
expect(actual[0].subcategory).toEqual('<mark>API2</mark>');
|
||||
});
|
||||
it('should use lvl2 as title', () => {
|
||||
// Given
|
||||
let input = [{
|
||||
|
|
|
|||
Loading…
Reference in a new issue