| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530 |
- var t = require('assert')
- module.exports = ({popup, 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)
- // enable header detection
- if (!await advanced.evaluate(() => state.header)) {
- await advanced.click('.m-switch')
- }
- })
- describe('button - raw/markdown', () => {
- before(async () => {
- // popup
- await popup.bringToFront()
- // defaults button
- await popup.click('button:nth-of-type(2)')
- })
- it('render markdown as html', 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'
- )
- // popup
- await popup.bringToFront()
- t.strictEqual(
- await popup.evaluate(() =>
- state.raw
- ),
- false,
- 'state.raw should equal false'
- )
- t.equal(
- await popup.evaluate(() =>
- document.querySelector('.m-button:first-child').innerText.toLowerCase()
- ),
- 'markdown',
- 'button text should equal markdown'
- )
- })
- it('display raw markdown', async () => {
- // raw button
- await content.bringToFront()
- await popup.click('button:nth-of-type(1)')
- // content auto reloads
- await content.waitFor(200)
- t.equal(
- await content.evaluate(() =>
- document.querySelector('#_markdown').innerText
- ),
- '**bold**',
- 'markdown should not be rendered'
- )
- // popup
- await popup.bringToFront()
- t.strictEqual(
- await popup.evaluate(() =>
- state.raw
- ),
- true,
- 'state.raw should equal true'
- )
- t.equal(
- await popup.evaluate(() =>
- document.querySelector('.m-button:first-child').innerText.toLowerCase()
- ),
- 'html',
- 'button text should equal html'
- )
- })
- })
- describe('set theme', () => {
- before(async () => {
- // popup
- await popup.bringToFront()
- // defaults button
- await popup.click('button:nth-of-type(2)')
- // theme tab
- await popup.click('.m-tabs a:nth-of-type(1)')
- })
- it('github theme should be set by default', 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.strictEqual(
- await content.evaluate(() =>
- /github\.css$/.test(
- document.querySelector('#_theme').getAttribute('href')
- )
- ),
- true,
- 'github theme styles should be included'
- )
- })
- it('set github-dark theme', async () => {
- // select github-dark theme
- await content.bringToFront()
- await popup.select('.m-panel:nth-of-type(1) select', 'github-dark')
- // content auto reloads
- await content.waitFor(200)
- t.strictEqual(
- await content.evaluate(() =>
- /github-dark\.css$/.test(
- document.querySelector('#_theme').getAttribute('href')
- )
- ),
- true,
- 'github-dark theme styles should be included'
- )
- })
- it('popup should preserve state', async () => {
- // reload popup
- await popup.bringToFront()
- await popup.reload()
- await popup.waitFor(200)
- t.equal(
- await popup.evaluate(() =>
- state.theme
- ),
- 'github-dark',
- 'state.theme should equal github-dark'
- )
- t.equal(
- await popup.evaluate(() =>
- document.querySelectorAll('.m-panel:nth-of-type(1) select option')[
- document.querySelector('.m-panel:nth-of-type(1) select').selectedIndex
- ].innerText
- ),
- 'github-dark',
- 'dom select option should be github-dark'
- )
- })
- })
- describe('set compiler options - marked', () => {
- before(async () => {
- // popup
- await popup.bringToFront()
- // defaults button
- await popup.click('button:nth-of-type(2)')
- // compiler tab
- await popup.click('.m-tabs a:nth-of-type(2)')
- })
- it('gfm is enabled by default', async () => {
- // go to page serving markdown as text/markdown
- await content.goto('http://localhost:3000/compiler-options-marked')
- await content.bringToFront()
- await content.waitFor(200)
- t.equal(
- await content.evaluate(() =>
- document.querySelector('#_html p del').innerText
- ),
- 'strikethrough',
- 'gfm should be rendered'
- )
- })
- it('gfm is disabled', async () => {
- // disable gfm
- await content.bringToFront()
- // gfm switch
- await popup.click('.m-panel:nth-of-type(2) .m-switch:nth-of-type(2)')
- // content auto reloads
- await content.waitFor(200)
- t.equal(
- await content.evaluate(() =>
- document.querySelector('#_html p').innerText
- ),
- '~~strikethrough~~',
- 'gfm should not be rendered'
- )
- })
- it('popup should preserve state', async () => {
- // reload popup
- await popup.bringToFront()
- await popup.reload()
- await popup.waitFor(200)
- t.equal(
- await popup.evaluate(() =>
- document.querySelectorAll('.m-panel:nth-of-type(2) .m-select option')[
- document.querySelector('.m-panel:nth-of-type(2) .m-select').selectedIndex
- ].innerText
- ),
- 'marked',
- 'dom select option should be marked'
- )
- t.strictEqual(
- await popup.evaluate(() =>
- state.options.gfm
- ),
- false,
- 'state.options.gfm should be false'
- )
- t.strictEqual(
- await popup.evaluate(() =>
- document.querySelector('.m-panel:nth-of-type(2) .m-switch:nth-of-type(2)')
- .classList.contains('is-checked')
- ),
- false,
- 'dom gfm checkbox should be disabled'
- )
- })
- })
- describe('set compiler options - remark', () => {
- before(async () => {
- // popup
- await popup.bringToFront()
- // defaults button
- await popup.click('button:nth-of-type(2)')
- // compiler tab
- await popup.click('.m-tabs a:nth-of-type(2)')
- })
- it('marked should not render gfm task lists', async () => {
- // go to page serving markdown as text/markdown
- await content.goto('http://localhost:3000/compiler-options-remark')
- await content.bringToFront()
- await content.waitFor(200)
- t.equal(
- await content.evaluate(() =>
- document.querySelector('#_html ul li').innerText
- ),
- '[ ] task',
- 'gfm task lists should not be rendered'
- )
- })
- it('remark should render gfm task lists by default', async () => {
- // select remark compiler
- await content.bringToFront()
- await popup.select('.m-panel:nth-of-type(2) select', 'remark')
- // content auto reloads
- await content.waitFor(200)
- t.equal(
- await content.evaluate(() =>
- document.querySelector('#_html ul li').getAttribute('class')
- ),
- 'task-list-item',
- 'dom li should have a class set'
- )
- t.strictEqual(
- await content.evaluate(() =>
- document.querySelector('#_html ul li [type=checkbox]')
- .hasAttribute('disabled')
- ),
- true,
- 'dom li should contain checkbox in it'
- )
- t.equal(
- await content.evaluate(() =>
- document.querySelector('#_html ul li').innerText
- ),
- ' task',
- 'dom li should contain the task text'
- )
- })
- it('remark disable gfm', async () => {
- // redraw popup
- await popup.bringToFront()
- await popup.reload()
- await popup.waitFor(200)
- // disable gfm
- await content.bringToFront()
- // gfm switch
- await popup.click('.m-panel:nth-of-type(2) .m-switch:nth-of-type(4)')
- // content auto reloads
- await content.waitFor(200)
- t.equal(
- await content.evaluate(() =>
- document.querySelector('#_html ul li').innerText
- ),
- '[ ] task',
- 'gfm task lists should not be rendered'
- )
- })
- it('popup should preserve state', async () => {
- // reload popup
- await popup.bringToFront()
- await popup.reload()
- await popup.waitFor(200)
- t.equal(
- await popup.evaluate(() =>
- document.querySelectorAll('.m-panel:nth-of-type(2) .m-select option')[
- document.querySelector('.m-panel:nth-of-type(2) .m-select').selectedIndex
- ].innerText
- ),
- 'remark',
- 'dom select option should be remark'
- )
- t.strictEqual(
- await popup.evaluate(() =>
- state.options.gfm
- ),
- false,
- 'state.options.gfm should be false'
- )
- t.strictEqual(
- await popup.evaluate(() =>
- document.querySelector('.m-panel:nth-of-type(2) .m-switch:nth-of-type(4)')
- .classList.contains('is-checked')
- ),
- false,
- 'dom gfm checkbox should be disabled'
- )
- })
- })
- describe('set content options - toc', () => {
- before(async () => {
- // popup
- await popup.bringToFront()
- // defaults button
- await popup.click('button:nth-of-type(2)')
- // content tab
- await popup.click('.m-tabs a:nth-of-type(3)')
- })
- it('toc is disabled by default', async () => {
- // go to page serving markdown as text/markdown
- await content.goto('http://localhost:3000/content-options-toc')
- await content.bringToFront()
- await content.waitFor(200)
- t.strictEqual(
- await content.evaluate(() =>
- document.querySelector('#_toc')
- ),
- null,
- 'toc should be disabled'
- )
- })
- it('enable toc', async () => {
- // enable toc
- await content.bringToFront()
- // toc switch
- await popup.click('.m-panel:nth-of-type(3) .m-switch:nth-of-type(3)')
- // content auto reloads
- await content.waitFor(200)
- t.deepStrictEqual(
- await content.evaluate(() =>
- Array.from(document.querySelectorAll('#_toc #_ul a'))
- .map((a) => ({href: a.getAttribute('href'), text: a.innerText}))
- ),
- [
- {href: '#h1', text: 'h1'},
- {href: '#h2', text: 'h2'},
- {href: '#h3', text: 'h3'},
- ],
- 'toc should be rendered'
- )
- })
- })
- describe('set content options - scroll', () => {
- before(async () => {
- // popup
- await popup.bringToFront()
- // defaults button
- await popup.click('button:nth-of-type(2)')
- // content tab
- await popup.click('.m-tabs a:nth-of-type(3)')
- })
- it('preserve scroll position by default', async () => {
- // go to page serving markdown as text/markdown
- await content.goto('http://localhost:3000/content-options-scroll')
- await content.bringToFront()
- await content.waitFor(200)
- // scroll down 200px
- await content.evaluate(() =>
- document.querySelector('body').scrollTop = 200
- )
- await content.waitFor(200)
- // reload page
- await content.reload()
- await content.waitFor(200)
- t.strictEqual(
- await content.evaluate(() =>
- document.querySelector('body').scrollTop,
- ),
- 200,
- 'scrollTop should be 200px'
- )
- })
- it('scroll to top', async () => {
- // disable scroll option
- await content.bringToFront()
- // scroll switch
- await popup.click('.m-panel:nth-of-type(3) .m-switch:nth-of-type(2)')
- // content auto reloads
- await content.waitFor(200)
- t.strictEqual(
- await content.evaluate(() =>
- document.querySelector('body').scrollTop,
- ),
- 0,
- 'scrollTop should be 0px'
- )
- // scroll down 200px
- await content.evaluate(() =>
- document.querySelector('body').scrollTop = 200
- )
- await content.waitFor(200)
- // reload page
- await content.reload()
- await content.waitFor(200)
- t.strictEqual(
- await content.evaluate(() =>
- document.querySelector('body').scrollTop,
- ),
- 0,
- 'scrollTop should be 0px'
- )
- })
- it('scroll to anchor', async () => {
- // click on header link
- await content.click('h2 a')
- await content.waitFor(200)
- t.strictEqual(
- await content.evaluate(() =>
- document.querySelector('body').scrollTop + 1
- ),
- await content.evaluate(() =>
- document.querySelector('h2').offsetTop
- ),
- 'page should be scrolled to the anchor'
- )
- // scroll down 200px
- await content.evaluate(() =>
- document.querySelector('body').scrollTop += 200
- )
- await content.waitFor(200)
- t.strictEqual(
- await content.evaluate(() =>
- document.querySelector('body').scrollTop + 1
- ),
- await content.evaluate(() =>
- document.querySelector('h2').offsetTop + 200
- ),
- 'page should be scrolled below the anchor'
- )
- // reload page
- await content.reload()
- await content.waitFor(200)
- t.strictEqual(
- await content.evaluate(() =>
- document.querySelector('body').scrollTop
- ),
- await content.evaluate(() =>
- document.querySelector('h2').offsetTop
- ),
- 'page should be scrolled back to the anchor'
- )
- })
- })
- }
|