33 * SPDX-License-Identifier: AGPL-3.0-or-later
44 */
55
6+ import { ListItem } from '@tiptap/extension-list'
67import { describe , expect , it } from 'vitest'
7- import { createRichEditor } from '../../EditorFactory.ts'
88import { createMarkdownSerializer } from '../../extensions/Markdown.js'
9+ import Markdown from '../../extensions/Markdown.js'
910import markdownit from '../../markdownit/index.js'
11+ import BulletList from '../../nodes/BulletList.ts'
12+ import OrderedList from '../../nodes/OrderedList.ts'
13+ import TaskItem from '../../nodes/TaskItem.ts'
14+ import TaskList from '../../nodes/TaskList.ts'
15+ import createCustomEditor from '../testHelpers/createCustomEditor.ts'
1016import { markdownThroughEditor } from '../testHelpers/markdown.js'
1117
18+ function createListEditor ( ) {
19+ return createCustomEditor ( '' , [
20+ BulletList ,
21+ ListItem ,
22+ Markdown ,
23+ OrderedList ,
24+ TaskItem ,
25+ TaskList ,
26+ ] )
27+ }
28+
1229describe ( 'List type conversion' , ( ) => {
1330 describe ( 'editor.can() — menubar enabled state' , ( ) => {
1431 it ( 'toggleTaskList() returns true when cursor is inside a bulletList' , ( ) => {
15- const editor = createRichEditor ( )
32+ const editor = createListEditor ( )
1633 editor . commands . setContent ( markdownit . render ( '- item\n' ) )
1734 editor . commands . focus ( 'start' )
1835 expect ( editor . can ( ) . toggleTaskList ( ) ) . to . equal ( true )
1936 editor . destroy ( )
2037 } )
2138 it ( 'toggleTaskList() returns true when cursor is inside an orderedList' , ( ) => {
22- const editor = createRichEditor ( )
39+ const editor = createListEditor ( )
2340 editor . commands . setContent ( markdownit . render ( '1. item\n' ) )
2441 editor . commands . focus ( 'start' )
2542 expect ( editor . can ( ) . toggleTaskList ( ) ) . to . equal ( true )
2643 editor . destroy ( )
2744 } )
2845 it ( 'toggleBulletList() returns true when cursor is inside a taskList' , ( ) => {
29- const editor = createRichEditor ( )
46+ const editor = createListEditor ( )
3047 editor . commands . setContent ( markdownit . render ( '- [ ] item\n' ) )
3148 editor . commands . focus ( 'start' )
3249 expect ( editor . can ( ) . toggleBulletList ( ) ) . to . equal ( true )
3350 editor . destroy ( )
3451 } )
3552 it ( 'toggleOrderedList() returns true when cursor is inside a taskList' , ( ) => {
36- const editor = createRichEditor ( )
53+ const editor = createListEditor ( )
3754 editor . commands . setContent ( markdownit . render ( '- [ ] item\n' ) )
3855 editor . commands . focus ( 'start' )
3956 expect ( editor . can ( ) . toggleOrderedList ( ) ) . to . equal ( true )
@@ -42,7 +59,7 @@ describe('List type conversion', () => {
4259 } )
4360 describe ( 'conversion at top level' , ( ) => {
4461 it ( 'converts all items when toggling bulletList → taskList' , ( ) => {
45- const editor = createRichEditor ( )
62+ const editor = createListEditor ( )
4663 editor . commands . setContent ( markdownit . render ( '- item 1\n- item 2\n' ) )
4764 editor . commands . focus ( 'start' )
4865 editor . commands . toggleTaskList ( )
@@ -56,7 +73,7 @@ describe('List type conversion', () => {
5673 editor . destroy ( )
5774 } )
5875 it ( 'converts all items when toggling taskList → bulletList' , ( ) => {
59- const editor = createRichEditor ( )
76+ const editor = createListEditor ( )
6077 editor . commands . setContent ( markdownit . render ( '- [ ] item 1\n- [x] item 2\n' ) )
6178 editor . commands . focus ( 'start' )
6279 editor . commands . toggleBulletList ( )
@@ -68,7 +85,7 @@ describe('List type conversion', () => {
6885 editor . destroy ( )
6986 } )
7087 it ( 'converts all items when toggling orderedList → taskList' , ( ) => {
71- const editor = createRichEditor ( )
88+ const editor = createListEditor ( )
7289 editor . commands . setContent ( markdownit . render ( '1. item 1\n2. item 2\n' ) )
7390 editor . commands . focus ( 'start' )
7491 editor . commands . toggleTaskList ( )
@@ -80,7 +97,7 @@ describe('List type conversion', () => {
8097 } )
8198 describe ( 'conversion at nested level' , ( ) => {
8299 it ( 'converts only the innermost list when cursor is in a nested item' , ( ) => {
83- const editor = createRichEditor ( )
100+ const editor = createListEditor ( )
84101 editor . commands . setContent ( markdownit . render ( '- outer\n - inner\n' ) )
85102 // Position cursor inside the nested "inner" paragraph
86103 let innerPos = - 1
@@ -101,7 +118,7 @@ describe('List type conversion', () => {
101118 editor . destroy ( )
102119 } )
103120 it ( 'can().toggleTaskList() returns true for a nested item inside a bulletList' , ( ) => {
104- const editor = createRichEditor ( )
121+ const editor = createListEditor ( )
105122 editor . commands . setContent ( markdownit . render ( '- outer\n - inner\n' ) )
106123 let innerPos = - 1
107124 editor . state . doc . descendants ( ( node , pos ) => {
@@ -115,7 +132,7 @@ describe('List type conversion', () => {
115132 } )
116133 } )
117134 it ( 'preserves cursor position when converting bulletList → taskList' , ( ) => {
118- const editor = createRichEditor ( )
135+ const editor = createListEditor ( )
119136 editor . commands . setContent ( markdownit . render ( '- item 1\n- item 2\n' ) )
120137 editor . commands . focus ( 'start' )
121138 const posBefore = editor . state . selection . from
@@ -136,7 +153,7 @@ describe('markdown serialization of mixed list types', () => {
136153
137154 // Post-conversion serialization — verifies convertListType preserves bullet attr
138155 it ( 'serializes correctly after converting nested bulletList → taskList' , ( ) => {
139- const editor = createRichEditor ( )
156+ const editor = createListEditor ( )
140157 editor . commands . setContent ( markdownit . render ( '- outer\n * inner\n' ) )
141158 // find inner paragraph
142159 let innerPos = - 1
0 commit comments