Skip to content

Commit

Permalink
Fix autocomplete highlighting edge case (#237)
Browse files Browse the repository at this point in the history
  • Loading branch information
Julian Delerme committed Sep 18, 2019
1 parent 0abae17 commit 8864894
Show file tree
Hide file tree
Showing 2 changed files with 37 additions and 0 deletions.
4 changes: 4 additions & 0 deletions src/core/models/autocompletedata.js
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,10 @@ export class AutoCompleteResult {
let highlightedValue = '';
let nextStart = 0;

if (invertedSubstrings.length === 0) {
return val;
}

for (let j = 0; j < invertedSubstrings.length; j++) {
let start = Number(invertedSubstrings[j].offset);
let end = start + invertedSubstrings[j].length;
Expand Down
33 changes: 33 additions & 0 deletions tests/core/models/autocompletedata.js
Original file line number Diff line number Diff line change
Expand Up @@ -110,4 +110,37 @@ describe('constructing from a response', () => {
expect(actualResults).toHaveLength(1);
expect(actualResults).toEqual(expectedResults);
});

it('properly handles full length match', () => {
const response = {
sections: [
{
label: 'Team Watson',
results: [
{
key: 'jesse',
value: 'Jesse',
matchedSubstrings: [ { offset: 0, length: 5 } ]
}
]
}
]
};

const expectedResults = [
{
key: 'jesse',
value: 'Jesse',
shortValue: 'Jesse',
filter: {},
matchedSubstrings: [ { offset: 0, length: 5 } ],
highlightedValue: 'Jesse'
}
];

const data = AutoCompleteData.from(response);
const actualResults = data.sections[0].results;
expect(actualResults).toHaveLength(1);
expect(actualResults).toEqual(expectedResults);
});
});

0 comments on commit 8864894

Please sign in to comment.