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('converts a list item to a paragraph block which is a sibling of the parent list', () => { cy.clickUnorderedListButton() .type('foo') .enter() .clickUnorderedListButton() .confirmMarkdownEditorContent(`

`) }); it('converts empty nested list item to empty paragraph block in parent list item', () => { cy.clickUnorderedListButton() .type('foo') .enter() .tabkey() .type('bar') .enter() .tabkey() .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() .tabkey() .type('bar') .enter() .tabkey() .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('wrap each bottom-most block in a selection with a list item block', () => { cy.focused() .type('foo') .enter() .type('bar') .enter() .type('baz') .setSelection('foo', 'baz') .clickUnorderedListButton() .confirmMarkdownEditorContent(` `) }) it('unwraps list item block from each selected list item and unwraps all of them from the outer list block', () => { cy.clickUnorderedListButton() .type('foo') .enter() .type('bar') .enter() .type('baz') .setSelection('foo', 'baz') .clickUnorderedListButton() .confirmMarkdownEditorContent(`

foo

bar

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') .tabkey() .confirmMarkdownEditorContent(` `) .up() .enter() .type('quux') .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() .type('bar') .enter() .type('baz') .setSelection('bar') .clickUnorderedListButton() .confirmMarkdownEditorContent(`

bar

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

bar

baz

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

baz

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

`); }); it('creates a new list item in a non-empty list', () => { cy.clickUnorderedListButton() .type('foo') .enter() .confirmMarkdownEditorContent(` `) .type('bar') .enter() .confirmMarkdownEditorContent(` `); }); it('creates a new default block below a list when hitting Enter twice on an empty list item of the list', () => { cy.clickUnorderedListButton() .type('foo') .enter({ times: 2 }) .confirmMarkdownEditorContent(`

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

`); }); it('removes the list item if list not empty', () => { cy.clickUnorderedListButton() .type('foo') .enter() .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() .type('bar') .tabkey() .confirmMarkdownEditorContent(` `) .enter() .tabkey() .confirmMarkdownEditorContent(` `) }); it('only nests up to one level down from the parent list', () => { cy.clickUnorderedListButton() .type('foo') .enter() .tabkey() .confirmMarkdownEditorContent(` `); }); it('unindents nested list items with shift', () => { cy.clickUnorderedListButton() .type('foo') .enter() .tabkey() .tabkey({ shift: true }) .confirmMarkdownEditorContent(` `) }); it('indents and unindents from one level below parent back to document root', () => { cy.clickUnorderedListButton() .type('foo') .enter() .tabkey() .type('bar') .enter() .tabkey() .type('baz') .confirmMarkdownEditorContent(` `) .tabkey({ shift: true }) .confirmMarkdownEditorContent(` `) .tabkey({ shift: true }) .confirmMarkdownEditorContent(` `) }); }); }); });