highlightFuseMatches.spec.jsx 1.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061
  1. import highlightFuseMatches, {getFuseMatches} from 'sentry/utils/highlightFuseMatches';
  2. describe('highlightFuseMatches', function () {
  3. const matchObj = {
  4. value: 'Authentication tokens allow you to perform actions',
  5. indices: [
  6. [4, 6],
  7. [12, 13],
  8. [15, 16],
  9. ],
  10. };
  11. it('handles no matches', function () {
  12. expect(getFuseMatches({value: 'My long string', indices: []})).toEqual([
  13. {highlight: false, text: 'My long string'},
  14. ]);
  15. });
  16. it('gets the correct tokens', function () {
  17. expect(getFuseMatches(matchObj)).toEqual([
  18. {
  19. highlight: false,
  20. text: 'Auth',
  21. },
  22. {
  23. highlight: true,
  24. text: 'ent',
  25. },
  26. {
  27. highlight: false,
  28. text: 'icati',
  29. },
  30. {
  31. highlight: true,
  32. text: 'on',
  33. },
  34. {
  35. highlight: false,
  36. text: ' ',
  37. },
  38. {
  39. highlight: true,
  40. text: 'to',
  41. },
  42. {
  43. highlight: false,
  44. text: 'kens allow you to perform actions',
  45. },
  46. ]);
  47. });
  48. it('renders a highlighted string', function () {
  49. // eslint-disable-next-line sentry/no-to-match-snapshot
  50. expect(highlightFuseMatches(matchObj)).toMatchSnapshot();
  51. });
  52. it('matches whole word', function () {
  53. // eslint-disable-next-line sentry/no-to-match-snapshot
  54. expect(highlightFuseMatches({value: 'foo', indices: [[0, 2]]})).toMatchSnapshot();
  55. });
  56. });