| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188 |
- var t = require('assert')
- module.exports = ({advanced, content}) => {
- before(async () => {
- await advanced.bringToFront()
- // remove origin
- if (await advanced.evaluate(() => Object.keys(state.origins).length > 1)) {
- // expand origin
- if (!await advanced.evaluate(() =>
- document.querySelector('.m-list li:nth-of-type(2)')
- .classList.contains('m-expanded'))) {
- await advanced.click('.m-list li:nth-of-type(2)')
- }
- await advanced.click('.m-list li:nth-of-type(2) .m-footer .m-button:nth-of-type(2)')
- }
- // add origin
- await advanced.select('.m-select', 'http')
- await advanced.type('[type=text]', 'localhost:3000')
- await advanced.click('button')
- await advanced.waitFor(200)
- })
- describe('add origin', () => {
- it('localhost:3000', async () => {
- t.equal(
- await advanced.evaluate(() =>
- document.querySelectorAll('.m-list li').length
- ),
- 2,
- 'allowed origins count should be 2'
- )
- t.equal(
- await advanced.evaluate(() =>
- document.querySelector('.m-list li:nth-of-type(2) .m-origin').innerText
- ),
- 'http://localhost:3000',
- 'origin name should be http://localhost:3000'
- )
- })
- })
- describe('disabled header detection + disabled path matching', () => {
- before(async () => {
- await advanced.bringToFront()
- // disable header detection
- if (await advanced.evaluate(() => state.header)) {
- await advanced.click('.m-switch')
- }
- // expand origin
- if (!await advanced.evaluate(() =>
- document.querySelector('.m-list li:nth-of-type(2)')
- .classList.contains('m-expanded'))) {
- await advanced.click('.m-list li:nth-of-type(2)')
- }
- // disable path matching
- await advanced.evaluate(() => {
- document.querySelector('.m-list li:nth-of-type(2) input')
- .value = ''
- document.querySelector('.m-list li:nth-of-type(2) input')
- .dispatchEvent(new Event('keyup'))
- })
- // there is debounce timeout of 750ms in the options UI
- await advanced.waitFor(800)
- })
- it('text/markdown', async () => {
- // go to page serving markdown as text/markdown
- await content.goto('http://localhost:3000/correct-content-type')
- await content.bringToFront()
- await content.waitFor(200)
- t.equal(
- await content.evaluate(() =>
- document.querySelector('pre').innerText
- ),
- '**bold**',
- 'markdown should not be rendered'
- )
- })
- })
- describe('enabled header detection + disabled path matching', () => {
- before(async () => {
- await advanced.bringToFront()
- // enable header detection
- if (!await advanced.evaluate(() => state.header)) {
- await advanced.click('.m-switch')
- }
- // expand origin
- if (!await advanced.evaluate(() =>
- document.querySelector('.m-list li:nth-of-type(2)')
- .classList.contains('m-expanded'))) {
- await advanced.click('.m-list li:nth-of-type(2)')
- }
- // disable path matching
- await advanced.evaluate(() => {
- document.querySelector('.m-list li:nth-of-type(2) input')
- .value = ''
- document.querySelector('.m-list li:nth-of-type(2) input')
- .dispatchEvent(new Event('keyup'))
- })
- // there is debounce timeout of 750ms in the options UI
- await advanced.waitFor(800)
- })
- it('text/markdown', async () => {
- // go to page serving markdown as text/markdown
- await content.goto('http://localhost:3000/correct-content-type')
- await content.bringToFront()
- await content.waitFor(200)
- t.equal(
- await content.evaluate(() =>
- document.querySelector('#_html p strong').innerText
- ),
- 'bold',
- 'markdown should be rendered'
- )
- })
- it('text/x-markdown', async () => {
- // go to page serving markdown as text/x-markdown
- await content.goto('http://localhost:3000/correct-content-type-variation')
- await content.bringToFront()
- await content.waitFor(200)
- t.equal(
- await content.evaluate(() =>
- document.querySelector('#_html p strong').innerText
- ),
- 'bold',
- 'markdown should be rendered'
- )
- })
- })
- describe('enabled header detection + enabled path matching', () => {
- before(async () => {
- await advanced.bringToFront()
- // enable header detection
- if (!await advanced.evaluate(() => state.header)) {
- await advanced.click('.m-switch')
- }
- // expand origin
- if (!await advanced.evaluate(() =>
- document.querySelector('.m-list li:nth-of-type(2)')
- .classList.contains('m-expanded'))) {
- await advanced.click('.m-list li:nth-of-type(2)')
- }
- // enable path matching
- await advanced.evaluate(() => {
- document.querySelector('.m-list li:nth-of-type(2) input')
- .value = 'wrong-content-type'
- document.querySelector('.m-list li:nth-of-type(2) input')
- .dispatchEvent(new Event('keyup'))
- })
- // there is debounce timeout of 750ms in the options UI
- await advanced.waitFor(800)
- })
- it('text/plain', async () => {
- // go to page serving markdown as text/plain
- await content.goto('http://localhost:3000/wrong-content-type')
- await content.bringToFront()
- await content.waitFor(200)
- t.equal(
- await content.evaluate(() =>
- document.querySelector('#_html p strong').innerText
- ),
- 'bold',
- 'markdown should be rendered'
- )
- })
- })
- }
|