12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455 |
- import highlightFuseMatches, {getFuseMatches} from 'app/utils/highlightFuseMatches';
- describe('highlightFuseMatches', function() {
- let matchObj = {
- value: 'Authentication tokens allow you to perform actions',
- indices: [[4, 6], [12, 13], [15, 16]],
- };
- it('handles no matches', function() {
- expect(getFuseMatches({value: 'My long string', indices: []})).toEqual([
- {highlight: false, text: 'My long string'},
- ]);
- });
- it('gets the correct tokens', function() {
- expect(getFuseMatches(matchObj)).toEqual([
- {
- highlight: false,
- text: 'Auth',
- },
- {
- highlight: true,
- text: 'ent',
- },
- {
- highlight: false,
- text: 'icati',
- },
- {
- highlight: true,
- text: 'on',
- },
- {
- highlight: false,
- text: ' ',
- },
- {
- highlight: true,
- text: 'to',
- },
- {
- highlight: false,
- text: 'kens allow you to perform actions',
- },
- ]);
- });
- it('renders a highlighted string', function() {
- expect(highlightFuseMatches(matchObj)).toMatchSnapshot();
- });
- it('matches whole word', function() {
- expect(highlightFuseMatches({value: 'foo', indices: [[0, 2]]})).toMatchSnapshot();
- });
- });
|