diff options
author | Max <max@nextcloud.com> | 2022-02-13 22:04:14 +0300 |
---|---|---|
committer | Max <max@nextcloud.com> | 2022-03-02 15:26:09 +0300 |
commit | 7a83446de3ccb90b53ceb01bfce06791f6a9e12b (patch) | |
tree | eb3fa60d21b24faba3cd5993efe1537bee553014 /cypress | |
parent | 9279b45c47d4418224c7a07b59f7437a71d263b9 (diff) |
test: loadMarkdown to initialize editor content
Signed-off-by: Max <max@nextcloud.com>
Diffstat (limited to 'cypress')
-rw-r--r-- | cypress/integration/ListItem.spec.js | 42 |
1 files changed, 21 insertions, 21 deletions
diff --git a/cypress/integration/ListItem.spec.js b/cypress/integration/ListItem.spec.js index a50936d82..c515f83ac 100644 --- a/cypress/integration/ListItem.spec.js +++ b/cypress/integration/ListItem.spec.js @@ -1,6 +1,7 @@ import BulletList from './../../src/nodes/BulletList' import ListItem from './../../src/nodes/ListItem' import Markdown from './../../src/extensions/Markdown' +import markdownit from './../../src/markdownit' import { createMarkdownSerializer } from './../../src/extensions/Markdown'; import { findChildren, findChildrenByType } from 'prosemirror-utils' import createEditor from './../../src/tests/createEditor' @@ -13,15 +14,14 @@ describe('ListItem extension integrated in the editor', () => { }) it('has attrs', () => { - editor.commands.setContent('<p><ul><li>Test</li></ul></p>') + loadMarkdown(`* Test`) const li = findListItem() - expect(li.attrs).to.deep.eq({done: null, type: 0}) - expectMarkdown(` - * Test`) + expect(li.attrs).to.deep.eq({done: null, type: 0},) + expectMarkdown(`* Test`) }) it('creates todo lists', () => { - editor.commands.setContent('Test') + loadMarkdown(`Test`) editor.commands.todo_item() const li = findListItem() expect(li.attrs).to.deep.eq({done: false, type: 1}) @@ -29,7 +29,7 @@ describe('ListItem extension integrated in the editor', () => { }) it('removes the list when toggling todo off', () => { - editor.commands.setContent('Test') + loadMarkdown(`Test`) editor.commands.todo_item() editor.commands.todo_item() expect(findListItem()).to.eq(undefined) @@ -37,41 +37,40 @@ describe('ListItem extension integrated in the editor', () => { }) it('creates a bullet list', () => { - editor.commands.setContent('<p>Test</p>') + loadMarkdown(`Test`) editor.commands.bulletListItem() expectMarkdown(`* Test`) }) - it('turns a bullet list into a todo list', () => { - editor.commands.setContent('<p>Test</p>') - editor.commands.bulletListItem() - editor.commands.todo_item() - expectMarkdown(`* [ ] Test`) - }) - it('only toggles one list item', () => { - editor.commands.setContent('<p><ul><li>Todo</li><li>Not to do</li></ul></p>') + loadMarkdown(`* Todo + * Not to do`) for (const { pos } of findTexts('Todo')) { editor.commands.setTextSelection(pos) editor.commands.todo_item() } - expectMarkdown(` - * [ ] Todo + expectMarkdown(`* [ ] Todo * Not to do`) }) it('toggles two separate list item', () => { - editor.commands.setContent('<p><ul><li>Todo</li><li>Not to do</li><li>Todo</li></ul></p>') + loadMarkdown(`* Todo + * Not to do + * Todo`) for (const { pos } of findTexts('Todo')) { editor.commands.setTextSelection(pos) editor.commands.todo_item() } - expectMarkdown(` - * [ ] Todo + expectMarkdown(`* [ ] Todo * Not to do * [ ] Todo`) }) + function loadMarkdown(markdown) { + const stripped = markdown.replace(/\t*/g, '') + editor.commands.setContent(markdownit.render(stripped)) + } + function findListItem(index = 0) { const doc = editor.state.doc const type = editor.schema.nodes.listItem @@ -86,7 +85,8 @@ describe('ListItem extension integrated in the editor', () => { } function expectMarkdown(markdown) { - expect(getMarkdown()).to.equal(markdown.replace(/\t*/g, '')) + const stripped = markdown.replace(/\t*/g, '') + expect(getMarkdown()).to.equal(stripped) } function getMarkdown() { |