diff options
author | Max <max@nextcloud.com> | 2022-02-13 23:34:12 +0300 |
---|---|---|
committer | Max <max@nextcloud.com> | 2022-03-02 15:26:10 +0300 |
commit | 1d323fdcdcbb433ec54a56bd33d95b2a6a29f903 (patch) | |
tree | 6263cdaa33954dd0c05ec9733b2adcee67c0ee94 /cypress | |
parent | 7a83446de3ccb90b53ceb01bfce06791f6a9e12b (diff) |
test: runCommands to run all commands included in Markdown
This allows specifying what steps to perform in a test inside the test data.
Signed-off-by: Max <max@nextcloud.com>
Diffstat (limited to 'cypress')
-rw-r--r-- | cypress/integration/ListItem.spec.js | 62 |
1 files changed, 31 insertions, 31 deletions
diff --git a/cypress/integration/ListItem.spec.js b/cypress/integration/ListItem.spec.js index c515f83ac..200d1e795 100644 --- a/cypress/integration/ListItem.spec.js +++ b/cypress/integration/ListItem.spec.js @@ -21,49 +21,42 @@ describe('ListItem extension integrated in the editor', () => { }) it('creates todo lists', () => { - loadMarkdown(`Test`) - editor.commands.todo_item() + loadMarkdown(`* todo\\_item`) + runCommands() const li = findListItem() expect(li.attrs).to.deep.eq({done: false, type: 1}) - expectMarkdown(`* [ ] Test`) + expectMarkdown(`* [ ] todo\\_item`) }) it('removes the list when toggling todo off', () => { - loadMarkdown(`Test`) - editor.commands.todo_item() - editor.commands.todo_item() + loadMarkdown(`* [ ] todo\\_item`) + runCommands() expect(findListItem()).to.eq(undefined) - expectMarkdown(`Test`) + expectMarkdown(`todo\\_item`) }) it('creates a bullet list', () => { - loadMarkdown(`Test`) - editor.commands.bulletListItem() - expectMarkdown(`* Test`) + loadMarkdown(`bulletListItem`) + runCommands() + expectMarkdown(`* bulletListItem`) }) it('only toggles one list item', () => { - loadMarkdown(`* Todo + loadMarkdown(`* todo\\_item * Not to do`) - for (const { pos } of findTexts('Todo')) { - editor.commands.setTextSelection(pos) - editor.commands.todo_item() - } - expectMarkdown(`* [ ] Todo + runCommands() + expectMarkdown(`* [ ] todo\\_item * Not to do`) }) it('toggles two separate list item', () => { - loadMarkdown(`* Todo + loadMarkdown(`* todo\\_item * Not to do - * Todo`) - for (const { pos } of findTexts('Todo')) { - editor.commands.setTextSelection(pos) - editor.commands.todo_item() - } - expectMarkdown(`* [ ] Todo + * todo\\_item`) + runCommands() + expectMarkdown(`* [ ] todo\\_item * Not to do - * [ ] Todo`) + * [ ] todo\\_item`) }) function loadMarkdown(markdown) { @@ -71,19 +64,27 @@ describe('ListItem extension integrated in the editor', () => { editor.commands.setContent(markdownit.render(stripped)) } - function findListItem(index = 0) { - const doc = editor.state.doc - const type = editor.schema.nodes.listItem - return findChildrenByType(doc, type)[index]?.node; + function runCommands() { + for (const { node, pos } of findCommands()) { + const command = node.text + editor.commands.setTextSelection(pos) + editor.commands[command]() + } } - function findTexts(text) { + function findCommands() { const doc = editor.state.doc return findChildren(doc, child => { - return child.isText && child.text === text + return child.isText && editor.commands.hasOwnProperty(child.text) }) } + function findListItem(index = 0) { + const doc = editor.state.doc + const type = editor.schema.nodes.listItem + return findChildrenByType(doc, type)[index]?.node; + } + function expectMarkdown(markdown) { const stripped = markdown.replace(/\t*/g, '') expect(getMarkdown()).to.equal(stripped) @@ -94,4 +95,3 @@ describe('ListItem extension integrated in the editor', () => { return serializer.serialize(editor.state.doc) } }) - |