12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061 |
- import highlightFuseMatches, {getFuseMatches} from 'sentry/utils/highlightFuseMatches';
- describe('highlightFuseMatches', function () {
- const 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 () {
- // eslint-disable-next-line sentry/no-to-match-snapshot
- expect(highlightFuseMatches(matchObj)).toMatchSnapshot();
- });
- it('matches whole word', function () {
- // eslint-disable-next-line sentry/no-to-match-snapshot
- expect(highlightFuseMatches({value: 'foo', indices: [[0, 2]]})).toMatchSnapshot();
- });
- });
|