highlightFuseMatches.spec.jsx 1.3 KB

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