advanced-origins.js 5.7 KB

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