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

Table.spec.js « integration « cypress - github.com/nextcloud/text.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
blob: cbf38f86ddd5150c310e632c17e0dead78372fd6 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
import Table from './../../src/nodes/Table'
import TableCell from './../../src/nodes/TableCell'
import TableHeader from './../../src/nodes/TableHeader'
import TableRow from './../../src/nodes/TableRow'
import TableHeadRow from './../../src/nodes/TableHeadRow'
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'
import testData from '../fixtures/Table.md'

describe('ListItem extension integrated in the editor', () => {

	const editor = createEditor({
		content: '',
		extensions: [
			Markdown,
			Table,
			TableCell,
			TableHeader,
			TableHeadRow,
			TableRow,
		],
	})

	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) {
		editor.commands.setContent(markdownit.render(markdown))
	}

	function runCommands() {
		let found
		while (found = findCommand()) {
			const name = found.node.text
			editor.commands.setTextSelection(found.pos)
			editor.commands[name]()
			const updated = findCommand()
			if (updated) {
				editor.commands.setTextSelection(updated.pos)
				editor.commands.insertContent('did ')
			}
		}
	}

	function findCommand() {
		const doc = editor.state.doc
		return findChildren(doc, child => {
			return child.isText && editor.commands.hasOwnProperty(child.text)
		})[0]
	}

	function expectMarkdown(markdown) {
		expect(getMarkdown().replace(/\n$/, '')).to.equal(markdown)
	}

	function getMarkdown() {
		const serializer = createMarkdownSerializer(editor.schema)
		return serializer.serialize(editor.state.doc)
	}
})