diff options
Diffstat (limited to 'cypress')
-rw-r--r-- | cypress/fixtures/ListItem.md | 62 | ||||
-rw-r--r-- | cypress/integration/ListItem.spec.js | 67 | ||||
-rw-r--r-- | cypress/plugins/index.js | 9 |
3 files changed, 85 insertions, 53 deletions
diff --git a/cypress/fixtures/ListItem.md b/cypress/fixtures/ListItem.md new file mode 100644 index 000000000..97ff201f8 --- /dev/null +++ b/cypress/fixtures/ListItem.md @@ -0,0 +1,62 @@ +## creates todo lists + +* todo\_item + +--- + +* [ ] todo\_item + +## removes the list when toggling todo off + +* [ ] todo\_item + +--- + +todo\_item + +## creates a bullet list + +bulletListItem + +--- + +* bulletListItem + +## only toggles one list item + +* todo\_item +* not todo + +--- + +* [ ] todo\_item +* not todo + +## toggles two list items separately + +* todo\_item +* not todo +* todo\_item + +--- + +* [ ] todo\_item +* not todo +* [ ] todo\_item + +## toggle off todo list item should turn it into normal list item + +* not todo +* [ ] todo\_item + +--- + +* not todo + +todo\_item + +--- + +* not todo +* todo\_item + diff --git a/cypress/integration/ListItem.spec.js b/cypress/integration/ListItem.spec.js index 200d1e795..dd0c95a87 100644 --- a/cypress/integration/ListItem.spec.js +++ b/cypress/integration/ListItem.spec.js @@ -5,6 +5,7 @@ import markdownit from './../../src/markdownit' import { createMarkdownSerializer } from './../../src/extensions/Markdown'; import { findChildren, findChildrenByType } from 'prosemirror-utils' import createEditor from './../../src/tests/createEditor' +import testData from '../fixtures/ListItem.md' describe('ListItem extension integrated in the editor', () => { @@ -13,51 +14,21 @@ describe('ListItem extension integrated in the editor', () => { extensions: [Markdown, BulletList, ListItem], }) - it('has attrs', () => { - loadMarkdown(`* Test`) - const li = findListItem() - expect(li.attrs).to.deep.eq({done: null, type: 0},) - expectMarkdown(`* Test`) - }) - - it('creates todo lists', () => { - loadMarkdown(`* todo\\_item`) - runCommands() - const li = findListItem() - expect(li.attrs).to.deep.eq({done: false, type: 1}) - expectMarkdown(`* [ ] todo\\_item`) - }) - - it('removes the list when toggling todo off', () => { - loadMarkdown(`* [ ] todo\\_item`) - runCommands() - expect(findListItem()).to.eq(undefined) - expectMarkdown(`todo\\_item`) - }) - - it('creates a bullet list', () => { - loadMarkdown(`bulletListItem`) - runCommands() - expectMarkdown(`* bulletListItem`) - }) - - it('only toggles one list item', () => { - loadMarkdown(`* todo\\_item - * Not to do`) - runCommands() - expectMarkdown(`* [ ] todo\\_item - * Not to do`) - }) - - it('toggles two separate list item', () => { - loadMarkdown(`* todo\\_item - * Not to do - * todo\\_item`) - runCommands() - expectMarkdown(`* [ ] todo\\_item - * Not to do - * [ ] todo\\_item`) - }) + for (const spec of testData.split(/#+\s+/)){ + const [description, ...rest] = spec.split(/\n/) + const [input, output] = rest.join('\n').split(/\n\n---\n\n/) + if (!description) { + continue + } + it(description, () => { + expect(spec).to.include('\n') + expect(input).to.be.ok + expect(output).to.be.ok + loadMarkdown(input) + runCommands() + expectMarkdown(output.replace(/\n*$/, '')) + }) + } function loadMarkdown(markdown) { const stripped = markdown.replace(/\t*/g, '') @@ -79,12 +50,6 @@ describe('ListItem extension integrated in the editor', () => { }) } - 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) diff --git a/cypress/plugins/index.js b/cypress/plugins/index.js index ca349c771..d9762fcd2 100644 --- a/cypress/plugins/index.js +++ b/cypress/plugins/index.js @@ -12,9 +12,14 @@ // the project's config changing) const browserify = require('@cypress/browserify-preprocessor') +const webpack = require('@cypress/webpack-preprocessor') +const defaults = webpack.defaultOptions module.exports = (on, config) => { - on('file:preprocessor', browserify()) - + defaults.webpackOptions.module.rules.push({ + test: /\.md/, + type: 'asset/source', + }) + on('file:preprocessor', webpack(defaults)) } |