advanced-origins.js 5.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188
  1. var t = require('assert')
  2. module.exports = ({advanced, content}) => {
  3. before(async () => {
  4. await advanced.bringToFront()
  5. // remove origin
  6. if (await advanced.evaluate(() => Object.keys(state.origins).length > 1)) {
  7. // expand origin
  8. if (!await advanced.evaluate(() =>
  9. document.querySelector('.m-list li:nth-of-type(2)')
  10. .classList.contains('m-expanded'))) {
  11. await advanced.click('.m-list li:nth-of-type(2)')
  12. }
  13. await advanced.click('.m-list li:nth-of-type(2) .m-footer .m-button:nth-of-type(2)')
  14. }
  15. // add origin
  16. await advanced.select('.m-select', 'http')
  17. await advanced.type('[type=text]', 'localhost:3000')
  18. await advanced.click('button')
  19. await advanced.waitFor(200)
  20. })
  21. describe('add origin', () => {
  22. it('localhost:3000', async () => {
  23. t.equal(
  24. await advanced.evaluate(() =>
  25. document.querySelectorAll('.m-list li').length
  26. ),
  27. 2,
  28. 'allowed origins count should be 2'
  29. )
  30. t.equal(
  31. await advanced.evaluate(() =>
  32. document.querySelector('.m-list li:nth-of-type(2) .m-origin').innerText
  33. ),
  34. 'http://localhost:3000',
  35. 'origin name should be http://localhost:3000'
  36. )
  37. })
  38. })
  39. describe('disabled header detection + disabled path matching', () => {
  40. before(async () => {
  41. await advanced.bringToFront()
  42. // disable header detection
  43. if (await advanced.evaluate(() => state.header)) {
  44. await advanced.click('.m-switch')
  45. }
  46. // expand origin
  47. if (!await advanced.evaluate(() =>
  48. document.querySelector('.m-list li:nth-of-type(2)')
  49. .classList.contains('m-expanded'))) {
  50. await advanced.click('.m-list li:nth-of-type(2)')
  51. }
  52. // disable path matching
  53. await advanced.evaluate(() => {
  54. document.querySelector('.m-list li:nth-of-type(2) input')
  55. .value = ''
  56. document.querySelector('.m-list li:nth-of-type(2) input')
  57. .dispatchEvent(new Event('keyup'))
  58. })
  59. // there is debounce timeout of 750ms in the options UI
  60. await advanced.waitFor(800)
  61. })
  62. it('text/markdown', async () => {
  63. // go to page serving markdown as text/markdown
  64. await content.goto('http://localhost:3000/correct-content-type')
  65. await content.bringToFront()
  66. await content.waitFor(200)
  67. t.equal(
  68. await content.evaluate(() =>
  69. document.querySelector('pre').innerText
  70. ),
  71. '**bold**',
  72. 'markdown should not be rendered'
  73. )
  74. })
  75. })
  76. describe('enabled header detection + disabled path matching', () => {
  77. before(async () => {
  78. await advanced.bringToFront()
  79. // enable header detection
  80. if (!await advanced.evaluate(() => state.header)) {
  81. await advanced.click('.m-switch')
  82. }
  83. // expand origin
  84. if (!await advanced.evaluate(() =>
  85. document.querySelector('.m-list li:nth-of-type(2)')
  86. .classList.contains('m-expanded'))) {
  87. await advanced.click('.m-list li:nth-of-type(2)')
  88. }
  89. // disable path matching
  90. await advanced.evaluate(() => {
  91. document.querySelector('.m-list li:nth-of-type(2) input')
  92. .value = ''
  93. document.querySelector('.m-list li:nth-of-type(2) input')
  94. .dispatchEvent(new Event('keyup'))
  95. })
  96. // there is debounce timeout of 750ms in the options UI
  97. await advanced.waitFor(800)
  98. })
  99. it('text/markdown', async () => {
  100. // go to page serving markdown as text/markdown
  101. await content.goto('http://localhost:3000/correct-content-type')
  102. await content.bringToFront()
  103. await content.waitFor(200)
  104. t.equal(
  105. await content.evaluate(() =>
  106. document.querySelector('#_html p strong').innerText
  107. ),
  108. 'bold',
  109. 'markdown should be rendered'
  110. )
  111. })
  112. it('text/x-markdown', async () => {
  113. // go to page serving markdown as text/x-markdown
  114. await content.goto('http://localhost:3000/correct-content-type-variation')
  115. await content.bringToFront()
  116. await content.waitFor(200)
  117. t.equal(
  118. await content.evaluate(() =>
  119. document.querySelector('#_html p strong').innerText
  120. ),
  121. 'bold',
  122. 'markdown should be rendered'
  123. )
  124. })
  125. })
  126. describe('enabled header detection + enabled path matching', () => {
  127. before(async () => {
  128. await advanced.bringToFront()
  129. // enable header detection
  130. if (!await advanced.evaluate(() => state.header)) {
  131. await advanced.click('.m-switch')
  132. }
  133. // expand origin
  134. if (!await advanced.evaluate(() =>
  135. document.querySelector('.m-list li:nth-of-type(2)')
  136. .classList.contains('m-expanded'))) {
  137. await advanced.click('.m-list li:nth-of-type(2)')
  138. }
  139. // enable path matching
  140. await advanced.evaluate(() => {
  141. document.querySelector('.m-list li:nth-of-type(2) input')
  142. .value = 'wrong-content-type'
  143. document.querySelector('.m-list li:nth-of-type(2) input')
  144. .dispatchEvent(new Event('keyup'))
  145. })
  146. // there is debounce timeout of 750ms in the options UI
  147. await advanced.waitFor(800)
  148. })
  149. it('text/plain', async () => {
  150. // go to page serving markdown as text/plain
  151. await content.goto('http://localhost:3000/wrong-content-type')
  152. await content.bringToFront()
  153. await content.waitFor(200)
  154. t.equal(
  155. await content.evaluate(() =>
  156. document.querySelector('#_html p strong').innerText
  157. ),
  158. 'bold',
  159. 'markdown should be rendered'
  160. )
  161. })
  162. })
  163. }