-
Notifications
You must be signed in to change notification settings - Fork 130
Expand file tree
/
Copy pathTaskItem.spec.js
More file actions
76 lines (71 loc) 路 2.97 KB
/
Copy pathTaskItem.spec.js
File metadata and controls
76 lines (71 loc) 路 2.97 KB
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
/**
* SPDX-FileCopyrightText: 2021-2024 Nextcloud GmbH and Nextcloud contributors
* SPDX-License-Identifier: AGPL-3.0-or-later
*/
import { getExtensionField } from '@tiptap/core'
import createCustomEditor from '../testHelpers/createCustomEditor.ts'
import {
markdownThroughEditor,
markdownThroughEditorHtml,
} from '../testHelpers/markdown.js'
import Markdown from './../../extensions/Markdown.js'
import TaskItem from './../../nodes/TaskItem.ts'
import TaskList from './../../nodes/TaskList.ts'
describe('TaskItem extension', () => {
it('exposes toMarkdown function', () => {
const toMarkdown = getExtensionField(TaskItem, 'toMarkdown', TaskItem)
expect(typeof toMarkdown).toEqual('function')
})
it('exposes the toMarkdown function in the prosemirror schema', () => {
const editor = createCustomEditor('', [Markdown, TaskList, TaskItem])
const taskItem = editor.schema.nodes.taskItem
expect(taskItem.spec.toMarkdown).toBeDefined()
editor.destroy()
})
it('markdown syntax is preserved through editor', () => {
// Invalid ones but should be syntactical unchanged
expect(markdownThroughEditor('- [F] asd')).toBe('- [F] asd')
expect(markdownThroughEditor('- [ [asd](sdf)')).toBe('- [ [asd](sdf)')
// Valid, whitespace is allowed inside the checkbox
expect(markdownThroughEditor('- [\t] asd')).toBe('- [ ] asd')
expect(markdownThroughEditor('- [ ] asd')).toBe('- [ ] asd')
// Valid ones
expect(markdownThroughEditor('* [ ] [asd](sdf)')).toBe('* [ ] [asd](sdf)')
expect(markdownThroughEditor('- [ ] [asd](sdf)')).toBe('- [ ] [asd](sdf)')
expect(markdownThroughEditor('- [x] [asd](sdf)')).toBe('- [x] [asd](sdf)')
expect(markdownThroughEditor('- [ ] foo\n- [x] bar')).toBe(
'- [ ] foo\n- [x] bar',
)
expect(
markdownThroughEditor(
'- [x] foo\n' + ' - [ ] bar\n' + ' - [x] baz\n' + '- [ ] bim',
),
).toBe('- [x] foo\n' + ' - [ ] bar\n' + ' - [x] baz\n' + '- [ ] bim')
expect(markdownThroughEditor('- [X] asd')).toBe('- [x] asd')
expect(markdownThroughEditor('- [X] asd')).toBe('- [x] asd')
})
it('serializes HTML to markdown', () => {
expect(
markdownThroughEditorHtml(
'<ul class="contains-task-list"><li><input type="checkbox" checked /><label>foo</label></li></ul>',
),
).toBe('- [x] foo')
expect(
markdownThroughEditorHtml(
'<ul class="contains-task-list"><li><input type="checkbox" /><label>test</label></li></ul>',
),
).toBe('- [ ] test')
// First text node becomes first paragraph in taskItem
expect(
markdownThroughEditorHtml(
'<ul class="contains-task-list"><li><input type="checkbox" checked />test<h2>Headline</h2><p><strong>content</strong></p></li></ul>',
),
).toBe('- [x] test\n\n ## Headline\n\n **content**')
// Second block element stays indented (stays part of taskItem)
expect(
markdownThroughEditorHtml(
'<ul class="contains-task-list"><li><input type="checkbox" checked /><p>Test</p><h1>Block level headline</h1></li></ul>',
),
).toBe('- [x] Test\n\n # Block level headline')
})
})