logo

pleroma-fe

My custom branche(s) on git.pleroma.social/pleroma/pleroma-fe git clone https://hacktivis.me/git/pleroma-fe.git

tiny_post_html_processor.spec.js (4383B)


  1. import { processHtml } from 'src/services/tiny_post_html_processor/tiny_post_html_processor.service.js'
  2. describe('TinyPostHTMLProcessor', () => {
  3. describe('with processor that keeps original line should not make any changes to HTML when', () => {
  4. const processorKeep = (line) => line
  5. it('fed with regular HTML with newlines', () => {
  6. const inputOutput = '1<br/>2<p class="lol">3 4</p> 5 \n 6 <p > 7 <br> 8 </p> <br>\n<br/>'
  7. expect(processHtml(inputOutput, processorKeep)).to.eql(inputOutput)
  8. })
  9. it('fed with possibly broken HTML with invalid tags/composition', () => {
  10. const inputOutput = '<feeee dwdwddddddw> <i>ayy<b>lm</i>ao</b> </section>'
  11. expect(processHtml(inputOutput, processorKeep)).to.eql(inputOutput)
  12. })
  13. it('fed with very broken HTML with broken composition', () => {
  14. const inputOutput = '</p> lmao what </div> whats going on <div> wha <p>'
  15. expect(processHtml(inputOutput, processorKeep)).to.eql(inputOutput)
  16. })
  17. it('fed with sorta valid HTML but tags aren\'t closed', () => {
  18. const inputOutput = 'just leaving a <div> hanging'
  19. expect(processHtml(inputOutput, processorKeep)).to.eql(inputOutput)
  20. })
  21. it('fed with not really HTML at this point... tags that aren\'t finished', () => {
  22. const inputOutput = 'do you expect me to finish this <div class='
  23. expect(processHtml(inputOutput, processorKeep)).to.eql(inputOutput)
  24. })
  25. it('fed with dubiously valid HTML (p within p and also div inside p)', () => {
  26. const inputOutput = 'look ma <p> p \nwithin <p> p! </p> and a <br/><div>div!</div></p>'
  27. expect(processHtml(inputOutput, processorKeep)).to.eql(inputOutput)
  28. })
  29. it('fed with maybe valid HTML? self-closing divs and ps', () => {
  30. const inputOutput = 'a <div class="what"/> what now <p aria-label="wtf"/> ?'
  31. expect(processHtml(inputOutput, processorKeep)).to.eql(inputOutput)
  32. })
  33. it('fed with valid XHTML containing a CDATA', () => {
  34. const inputOutput = 'Yes, it is me, <![CDATA[DIO]]>'
  35. expect(processHtml(inputOutput, processorKeep)).to.eql(inputOutput)
  36. })
  37. })
  38. describe('with processor that replaces lines with word "_" should match expected line when', () => {
  39. const processorReplace = (line) => '_'
  40. it('fed with regular HTML with newlines', () => {
  41. const input = '1<br/>2<p class="lol">3 4</p> 5 \n 6 <p > 7 <br> 8 </p> <br>\n<br/>'
  42. const output = '_<br/>_<p class="lol">_</p>_\n_<p >_<br>_</p> <br>\n<br/>'
  43. expect(processHtml(input, processorReplace)).to.eql(output)
  44. })
  45. it('fed with possibly broken HTML with invalid tags/composition', () => {
  46. const input = '<feeee dwdwddddddw> <i>ayy<b>lm</i>ao</b> </section>'
  47. const output = '_'
  48. expect(processHtml(input, processorReplace)).to.eql(output)
  49. })
  50. it('fed with very broken HTML with broken composition', () => {
  51. const input = '</p> lmao what </div> whats going on <div> wha <p>'
  52. const output = '</p>_</div>_<div>_<p>'
  53. expect(processHtml(input, processorReplace)).to.eql(output)
  54. })
  55. it('fed with sorta valid HTML but tags aren\'t closed', () => {
  56. const input = 'just leaving a <div> hanging'
  57. const output = '_<div>_'
  58. expect(processHtml(input, processorReplace)).to.eql(output)
  59. })
  60. it('fed with not really HTML at this point... tags that aren\'t finished', () => {
  61. const input = 'do you expect me to finish this <div class='
  62. const output = '_'
  63. expect(processHtml(input, processorReplace)).to.eql(output)
  64. })
  65. it('fed with dubiously valid HTML (p within p and also div inside p)', () => {
  66. const input = 'look ma <p> p \nwithin <p> p! </p> and a <br/><div>div!</div></p>'
  67. const output = '_<p>_\n_<p>_</p>_<br/><div>_</div></p>'
  68. expect(processHtml(input, processorReplace)).to.eql(output)
  69. })
  70. it('fed with maybe valid HTML? self-closing divs and ps', () => {
  71. const input = 'a <div class="what"/> what now <p aria-label="wtf"/> ?'
  72. const output = '_<div class="what"/>_<p aria-label="wtf"/>_'
  73. expect(processHtml(input, processorReplace)).to.eql(output)
  74. })
  75. it('fed with valid XHTML containing a CDATA', () => {
  76. const input = 'Yes, it is me, <![CDATA[DIO]]>'
  77. const output = '_'
  78. expect(processHtml(input, processorReplace)).to.eql(output)
  79. })
  80. })
  81. })