highlightFuseMatches.spec.jsx 1.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253
  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. });
  10. it('gets the correct tokens', function() {
  11. expect(getFuseMatches(matchObj)).toEqual([
  12. {
  13. highlight: false,
  14. text: 'Auth',
  15. },
  16. {
  17. highlight: true,
  18. text: 'ent',
  19. },
  20. {
  21. highlight: false,
  22. text: 'icati',
  23. },
  24. {
  25. highlight: true,
  26. text: 'on',
  27. },
  28. {
  29. highlight: false,
  30. text: ' ',
  31. },
  32. {
  33. highlight: true,
  34. text: 'to',
  35. },
  36. {
  37. highlight: false,
  38. text: 'kens allow you to perform actions',
  39. },
  40. ]);
  41. });
  42. it('renders a highlighted string', function() {
  43. expect(highlightFuseMatches(matchObj)).toMatchSnapshot();
  44. });
  45. it('matches whole word', function() {
  46. expect(highlightFuseMatches({value: 'foo', indices: [[0, 2]]})).toMatchSnapshot();
  47. });
  48. });