diff options
author | Max <max@nextcloud.com> | 2022-02-13 19:49:53 +0300 |
---|---|---|
committer | Max <max@nextcloud.com> | 2022-03-02 15:26:08 +0300 |
commit | 8bc08c7234efaf1746111611c3690a1dc0e7cc1d (patch) | |
tree | 53cf4a5bb2d1a4005016a7ba602525facaea64fe /cypress | |
parent | c54f8fd6eac7a3755ef1e32c644c7526447a33a1 (diff) |
test: todo lists and others
Signed-off-by: Max <max@nextcloud.com>
Diffstat (limited to 'cypress')
-rw-r--r-- | cypress/integration/ListItem.spec.js | 56 |
1 files changed, 27 insertions, 29 deletions
diff --git a/cypress/integration/ListItem.spec.js b/cypress/integration/ListItem.spec.js index 9eb62513f..84c743227 100644 --- a/cypress/integration/ListItem.spec.js +++ b/cypress/integration/ListItem.spec.js @@ -1,61 +1,52 @@ import BulletList from './../../src/nodes/BulletList' import ListItem from './../../src/nodes/ListItem' import Markdown from './../../src/extensions/Markdown'; -import { findChildrenByType } from 'prosemirror-utils' +import { findChildren, findChildrenByType } from 'prosemirror-utils' import createEditor from './../../src/tests/createEditor' describe('ListItem extension integrated in the editor', () => { + const editor = createEditor({ + extensions: [Markdown, BulletList, ListItem] + }) + it('has attrs', () => { - const editor = createEditor({ - content: '<p><ul><li>Test</li></ul></p>', - extensions: [Markdown, BulletList, ListItem] - }) + editor.commands.setContent('<p><ul><li>Test</li></ul></p>') const li = findListItem(editor) expect(li.attrs).to.deep.eq({done: null, type: 0}) }) it('creates todo lists', () => { - const editor = createEditor({ - content: '<p>Test</p>', - extensions: [Markdown, BulletList, ListItem] - }) - editor.chain().todo_item().run() + editor.commands.setContent('Test') + editor.commands.todo_item() const li = findListItem(editor) expect(li.attrs).to.deep.eq({done: false, type: 1}) }) it('removes the list when toggling todo off', () => { - const editor = createEditor({ - content: '<p>Test</p>', - extensions: [Markdown, BulletList, ListItem] - }) - editor.chain().todo_item().run() - editor.chain().todo_item().run() + editor.commands.setContent('Test') + editor.commands.todo_item() + editor.commands.todo_item() expect(findListItem(editor)).to.eq(undefined) }) it('turns a bullet list into a todo list', () => { - const editor = createEditor({ - content: '<p>Test</p>', - extensions: [Markdown, BulletList, ListItem] - }) - editor.chain().bulletListItem().run() - editor.chain().todo_item().run() + editor.commands.setContent('Test') + editor.commands.bulletListItem() + editor.commands.todo_item() const li = findListItem(editor) expect(li.attrs).to.deep.eq({done: false, type: 1}) }) it('only toggles one list item', () => { - const editor = createEditor({ - content: '<p><ul><li>Todo</li><li>Not to do</li></ul></p>', - extensions: [Markdown, BulletList, ListItem] - }) - editor.chain().todo_item().run() + editor.commands.setContent('<p><ul><li>Todo</li><li>Not to do</li></ul></p>') + const { pos } = findTexts(editor, 'Todo')[0] + editor.commands.setTextSelection(pos) + editor.commands.todo_item() const todo = findListItem(editor, 0) const li = findListItem(editor, 1) - expect(todo.attrs).to.deep.eq({done: false, type: 1}) - expect(li.attrs).to.deep.eq({done: null, type: 0}) + expect(todo.attrs).to.deep.eq({done: false, type: 1}, editor.getHTML()) + expect(li.attrs).to.deep.eq({done: null, type: 0}, editor.getHTML()) }) }) @@ -65,3 +56,10 @@ function findListItem(editor, index = 0) { const type = editor.schema.nodes.listItem return findChildrenByType(doc, type)[index]?.node; } + +function findTexts(editor, text) { + const doc = editor.state.doc + return findChildren(doc, child => { + return child.isText && child.text === text + }) +} |