import '../utils/dismiss-local-backup'; describe('Markdown widget', () => { describe('list', () => { before(() => { Cypress.config('defaultCommandTimeout', 4000); cy.task('setupBackend', { backend: 'test' }); cy.loginAndNewPost(); }); beforeEach(() => { cy.clearMarkdownEditorContent(); }); after(() => { cy.task('teardownBackend', { backend: 'test' }); }); describe('toolbar buttons', () => { it('creates and focuses empty list', () => { cy.clickUnorderedListButton() .confirmMarkdownEditorContent(` `); }); it('removes list', () => { cy.clickUnorderedListButton({ times: 2 }) .confirmMarkdownEditorContent(`

`); }); it('creates nested list when selection is collapsed in non-first block of list item', () => { cy.clickUnorderedListButton() .type('foo') .enter() .clickUnorderedListButton() .confirmMarkdownEditorContent(` `) .type('bar') .enter() .clickUnorderedListButton() .confirmMarkdownEditorContent(` `); }); it('converts empty nested list item to empty block in parent list item', () => { cy.clickUnorderedListButton() .type('foo') .enter() .clickUnorderedListButton() .type('bar') .enter() .clickUnorderedListButton() .confirmMarkdownEditorContent(` `) .clickUnorderedListButton() .confirmMarkdownEditorContent(` `) .backspace({ times: 4 }) .clickUnorderedListButton() .confirmMarkdownEditorContent(` `); }); it('moves nested list item content to parent list item when in first block', () => { cy.clickUnorderedListButton() .type('foo') .enter() .clickUnorderedListButton() .type('bar') .enter() .clickUnorderedListButton() .type('baz') .clickUnorderedListButton() .confirmMarkdownEditorContent(` `) .up() .clickUnorderedListButton() .confirmMarkdownEditorContent(` `) .up() .clickUnorderedListButton() .confirmMarkdownEditorContent(`

foo

bar

baz

`); }); it('affects only the current block with collapsed selection', () => { cy.focused() .type('foo') .enter() .type('bar') .enter() .type('baz') .up() .clickUnorderedListButton() .confirmMarkdownEditorContent(`

foo

baz

`); }); it('combines adjacent same-typed lists, not differently typed lists', () => { cy.focused() .type('foo') .enter() .type('bar') .enter() .type('baz') .up() .clickUnorderedListButton() .up() .clickUnorderedListButton() .confirmMarkdownEditorContent(`

baz

`) .down({ times: 2 }) .clickUnorderedListButton() .confirmMarkdownEditorContent(` `) .up() .enter() .type('qux') .clickUnorderedListButton() .confirmMarkdownEditorContent(` `) .up() .enter() .type('quux') .clickUnorderedListButton() .confirmMarkdownEditorContent(` `) .clickOrderedListButton() .confirmMarkdownEditorContent(` `) .setSelection({ anchorQuery: 'ul > li > ol p', anchorOffset: 1, focusQuery: 'ul > li > ul:last-child p', focusOffset: 2, }); }); it('affects only selected list items', () => { cy.clickUnorderedListButton() .type('foo') .enter({ times: 2 }) .type('bar') .enter({ times: 2 }) .type('baz') .setSelection('bar') .clickUnorderedListButton() .confirmMarkdownEditorContent(`

bar

`) .clickUnorderedListButton() .setSelection('bar', 'baz') .clickUnorderedListButton() .confirmMarkdownEditorContent(`

bar

baz

`) .clickUnorderedListButton() .confirmMarkdownEditorContent(` `) .setSelection('baz') .clickUnorderedListButton() .setCursorAfter('baz') .enter() .clickUnorderedListButton() .type('qux') .setSelection('baz') .clickOrderedListButton() .setCursorAfter('qux') .enter({ times: 4 }) .clickUnorderedListButton() .confirmMarkdownEditorContent(` `) }); }); describe('on Enter', () => { it('removes the list item and list if empty', () => { cy.clickUnorderedListButton() .enter() .confirmMarkdownEditorContent(`

`); }); it('creates a new paragraph in a non-empty paragraph within a list item', () => { cy.clickUnorderedListButton() .type('foo') .enter() .confirmMarkdownEditorContent(` `) .type('bar') .enter() .confirmMarkdownEditorContent(` `); }); it('creates a new list item in an empty paragraph within a non-empty list item', () => { cy.clickUnorderedListButton() .type('foo') .enter({ times: 2 }) .confirmMarkdownEditorContent(` `) .type('bar') .enter() .confirmMarkdownEditorContent(` `); }); it('creates a new block below list', () => { cy.clickUnorderedListButton() .type('foo') .enter({ times: 3 }) .confirmMarkdownEditorContent(`

`); }); }); describe('on Backspace', () => { it('removes the list item and list if empty', () => { cy.clickUnorderedListButton() .backspace() .confirmMarkdownEditorContent(`

`); }); it('removes empty block in non-empty list item', () => { cy.clickUnorderedListButton() .type('foo') .enter() .backspace() .confirmMarkdownEditorContent(` `); }); it('removes the list item if list not empty', () => { cy.clickUnorderedListButton() .type('foo') .enter({ times: 2 }) .backspace() .confirmMarkdownEditorContent(` `); }); it('does not remove list item if empty with non-default block', () => { cy.clickUnorderedListButton() .clickHeadingOneButton() .backspace() .confirmMarkdownEditorContent(` `); }); }); describe('on Tab', () => { it('does nothing in top level list', () => { cy.clickUnorderedListButton() .tabkey() .confirmMarkdownEditorContent(` `) .type('foo') .tabkey() .confirmMarkdownEditorContent(` `) }); it('indents nested list items', () => { cy.clickUnorderedListButton() .type('foo') .enter({ times: 2 }) .type('bar') .tabkey() .confirmMarkdownEditorContent(` `) .enter({ times: 2 }) .tabkey() .confirmMarkdownEditorContent(` `) }); it('only nests up to one level down from the parent list', () => { cy.clickUnorderedListButton() .type('foo') .enter({ times: 2 }) .tabkey({ times: 5 }) .confirmMarkdownEditorContent(` `); }); it('unindents nested list items with shift', () => { cy.clickUnorderedListButton() .type('foo') .enter({ times: 2 }) .tabkey() .tabkey({ shift: true }) .confirmMarkdownEditorContent(` `) }); it('indents and unindents from one level below parent back to document root', () => { cy.clickUnorderedListButton() .type('foo') .enter({ times: 2 }) .tabkey() .type('bar') .enter({ times: 2 }) .tabkey() .type('baz') .confirmMarkdownEditorContent(` `) .tabkey({ shift: true }) .confirmMarkdownEditorContent(` `) .tabkey({ shift: true }) .confirmMarkdownEditorContent(` `) }); }); }); });