1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253 |
- 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([]);
- });
- 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();
- });
- });
|