parseHtmlMarks.spec.jsx 1.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253
  1. import parseHtmlMarks from 'sentry/utils/parseHtmlMarks';
  2. const MARK_TAGS = {
  3. highlightPreTag: '<mark>',
  4. highlightPostTag: '</mark>',
  5. };
  6. describe('parseHtmlMarks', function () {
  7. it('does nothing to a normal string', function () {
  8. const data = {
  9. key: 'title',
  10. htmlString: 'A string without any marking tags',
  11. markTags: MARK_TAGS,
  12. };
  13. expect(parseHtmlMarks(data)).toEqual({
  14. key: 'title',
  15. value: data.htmlString,
  16. indices: [],
  17. });
  18. });
  19. it('parses a marked html string', function () {
  20. const data = {
  21. key: 'title',
  22. htmlString: 'A string <mark>with</mark>out any <mark>marking</mark> tags',
  23. markTags: MARK_TAGS,
  24. };
  25. expect(parseHtmlMarks(data)).toEqual({
  26. key: 'title',
  27. value: 'A string without any marking tags',
  28. indices: [
  29. [9, 12],
  30. [21, 27],
  31. ],
  32. });
  33. });
  34. it('soft-fails on a invalid string', function () {
  35. const data = {
  36. key: 'title',
  37. htmlString: 'A string <mark>with</mark>out any <mark>marking tags',
  38. markTags: MARK_TAGS,
  39. };
  40. expect(parseHtmlMarks(data)).toEqual({
  41. key: 'title',
  42. value: 'A string without any <mark>marking tags',
  43. indices: [[9, 12]],
  44. });
  45. });
  46. });