Welcome to mirror list, hosted at ThFree Co, Russian Federation.

github.com/nextcloud/text.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMax <max@nextcloud.com>2022-02-14 10:25:42 +0300
committerMax <max@nextcloud.com>2022-02-14 10:58:08 +0300
commit884b73411dadaa600b9bd3101a29d0599e75da7f (patch)
tree5414459f676ff2e60b7552deb992298b491f0ab4
parent2d723a3442ca7d4d84bf93b81d2d3a1e2c912ec2 (diff)
test: load markdown with commands from .md filetest/todolists
-rw-r--r--cypress/fixtures/ListItem.md62
-rw-r--r--cypress/integration/ListItem.spec.js67
-rw-r--r--cypress/plugins/index.js9
-rw-r--r--package-lock.json43
-rw-r--r--package.json1
5 files changed, 129 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))
}
diff --git a/package-lock.json b/package-lock.json
index 3311829ad..3699e24b9 100644
--- a/package-lock.json
+++ b/package-lock.json
@@ -64,6 +64,7 @@
},
"devDependencies": {
"@cypress/browserify-preprocessor": "^3.0.2",
+ "@cypress/webpack-preprocessor": "^5.11.1",
"@nextcloud/babel-config": "^1.0.0",
"@nextcloud/browserslist-config": "^2.2.0",
"@nextcloud/eslint-config": "^6.1.2",
@@ -1863,6 +1864,29 @@
"node": ">= 6"
}
},
+ "node_modules/@cypress/webpack-preprocessor": {
+ "version": "5.11.1",
+ "resolved": "https://registry.npmjs.org/@cypress/webpack-preprocessor/-/webpack-preprocessor-5.11.1.tgz",
+ "integrity": "sha512-kfdF+W/Tns81rFplnqlgZ+t6V+FJ7vegeQCYolLyhh0nJ8eG3s5HvV/ak/zSlbQnaOmAuYiZIChJFVZLUWuNOA==",
+ "dev": true,
+ "dependencies": {
+ "bluebird": "3.7.1",
+ "debug": "^4.3.2",
+ "lodash": "^4.17.20"
+ },
+ "peerDependencies": {
+ "@babel/core": "^7.0.1",
+ "@babel/preset-env": "^7.0.0",
+ "babel-loader": "^8.0.2",
+ "webpack": "^4 || ^5"
+ }
+ },
+ "node_modules/@cypress/webpack-preprocessor/node_modules/bluebird": {
+ "version": "3.7.1",
+ "resolved": "https://registry.npmjs.org/bluebird/-/bluebird-3.7.1.tgz",
+ "integrity": "sha512-DdmyoGCleJnkbp3nkbxTLJ18rjDsE4yCggEwKNXkeV123sPNfOCYeDoeuOY+F2FrSjO1YXcTU+dsy96KMy+gcg==",
+ "dev": true
+ },
"node_modules/@cypress/xvfb": {
"version": "1.2.4",
"resolved": "https://registry.npmjs.org/@cypress/xvfb/-/xvfb-1.2.4.tgz",
@@ -22615,6 +22639,25 @@
"uuid": "^8.3.2"
}
},
+ "@cypress/webpack-preprocessor": {
+ "version": "5.11.1",
+ "resolved": "https://registry.npmjs.org/@cypress/webpack-preprocessor/-/webpack-preprocessor-5.11.1.tgz",
+ "integrity": "sha512-kfdF+W/Tns81rFplnqlgZ+t6V+FJ7vegeQCYolLyhh0nJ8eG3s5HvV/ak/zSlbQnaOmAuYiZIChJFVZLUWuNOA==",
+ "dev": true,
+ "requires": {
+ "bluebird": "3.7.1",
+ "debug": "^4.3.2",
+ "lodash": "^4.17.20"
+ },
+ "dependencies": {
+ "bluebird": {
+ "version": "3.7.1",
+ "resolved": "https://registry.npmjs.org/bluebird/-/bluebird-3.7.1.tgz",
+ "integrity": "sha512-DdmyoGCleJnkbp3nkbxTLJ18rjDsE4yCggEwKNXkeV123sPNfOCYeDoeuOY+F2FrSjO1YXcTU+dsy96KMy+gcg==",
+ "dev": true
+ }
+ }
+ },
"@cypress/xvfb": {
"version": "1.2.4",
"resolved": "https://registry.npmjs.org/@cypress/xvfb/-/xvfb-1.2.4.tgz",
diff --git a/package.json b/package.json
index 31fd7d61b..b8908de33 100644
--- a/package.json
+++ b/package.json
@@ -85,6 +85,7 @@
},
"devDependencies": {
"@cypress/browserify-preprocessor": "^3.0.2",
+ "@cypress/webpack-preprocessor": "^5.11.1",
"@nextcloud/babel-config": "^1.0.0",
"@nextcloud/browserslist-config": "^2.2.0",
"@nextcloud/eslint-config": "^6.1.2",