import { oneLineTrim, stripIndent } from 'common-tags'; import '../utils/dismiss-local-backup'; describe('Markdown widget', () => { before(() => { Cypress.config('defaultCommandTimeout', 4000); cy.task('setupBackend', { backend: 'test' }); cy.loginAndNewPost(); }); beforeEach(() => { cy.clearMarkdownEditorContent(); }); after(() => { cy.task('teardownBackend', { backend: 'test' }); }); describe('code block', () => { it('outputs code', () => { cy.insertCodeBlock() .type('foo') .enter() .type('bar') .confirmMarkdownEditorContent(` ${codeBlock(` foo bar `)} `) .clickModeToggle() .confirmMarkdownEditorContent(` ${codeBlockRaw(` foo bar `)} `) }) }) }) function codeBlockRaw(content) { return ['```', ...stripIndent(content).split('\n'), '```'].map(line => oneLineTrim`
${line}
`).join(''); } function codeBlock(content) { const lines = stripIndent(content).split('\n').map((line, idx) => `
${idx + 1}
${line}
`).join(''); return oneLineTrim`

xxxxxxxxxx
 
${lines}
`; }