1
- import Draft , {
2
- EditorState ,
3
- SelectionState ,
4
- ContentBlock ,
5
- convertToRaw ,
6
- } from "draft-js" ;
1
+ import Draft , { EditorState , SelectionState , convertToRaw } from "draft-js" ;
7
2
import createMarkdownPlugin from "../" ;
8
3
4
+ const applyMDtoInlineStyleChange = editorState =>
5
+ EditorState . set ( editorState , {
6
+ lastChangeType : "md-to-inline-style" ,
7
+ } ) ;
8
+
9
9
describe ( "markdown" , ( ) => {
10
10
it ( "should convert asteriks to bold text" , ( ) => {
11
11
const { handleBeforeInput } = createMarkdownPlugin ( ) ;
@@ -76,15 +76,14 @@ describe("markdown", () => {
76
76
) ;
77
77
} ) ;
78
78
79
- it ( "should not have sticky inline styles" , ( ) => {
79
+ it ( "should not unstick inline styles if they were not added by md-to-inline-style change " , ( ) => {
80
80
const { handleBeforeInput } = createMarkdownPlugin ( ) ;
81
- const setEditorState = jest . fn ( ) ;
82
81
const boldInlineStyleRange = {
83
82
length : 4 ,
84
83
offset : 5 ,
85
84
style : "BOLD" ,
86
85
} ;
87
- const before = EditorState . moveSelectionToEnd (
86
+ const editorState = EditorState . moveSelectionToEnd (
88
87
EditorState . createWithContent (
89
88
Draft . convertFromRaw ( {
90
89
entityMap : { } ,
@@ -102,7 +101,39 @@ describe("markdown", () => {
102
101
} )
103
102
)
104
103
) ;
105
- expect ( handleBeforeInput ( "a" , before , { setEditorState } ) ) . toEqual (
104
+ expect ( handleBeforeInput ( "a" , editorState , { } ) ) . toEqual ( "not-handled" ) ;
105
+ } ) ;
106
+
107
+ it ( "should not have sticky inline styles" , ( ) => {
108
+ const { handleBeforeInput } = createMarkdownPlugin ( ) ;
109
+ const setEditorState = jest . fn ( ) ;
110
+ const boldInlineStyleRange = {
111
+ length : 4 ,
112
+ offset : 5 ,
113
+ style : "BOLD" ,
114
+ } ;
115
+ const editorState = applyMDtoInlineStyleChange (
116
+ EditorState . moveSelectionToEnd (
117
+ EditorState . createWithContent (
118
+ Draft . convertFromRaw ( {
119
+ entityMap : { } ,
120
+ blocks : [
121
+ {
122
+ key : "item1" ,
123
+ text : "Some text" ,
124
+ type : "unstyled" ,
125
+ depth : 0 ,
126
+ inlineStyleRanges : [ boldInlineStyleRange ] ,
127
+ entityRanges : [ ] ,
128
+ data : { } ,
129
+ } ,
130
+ ] ,
131
+ } )
132
+ )
133
+ )
134
+ ) ;
135
+
136
+ expect ( handleBeforeInput ( "a" , editorState , { setEditorState } ) ) . toEqual (
106
137
"handled"
107
138
) ;
108
139
const raw = convertToRaw (
@@ -120,34 +151,37 @@ describe("markdown", () => {
120
151
offset : 5 ,
121
152
style : "BOLD" ,
122
153
} ;
123
- const before = EditorState . moveSelectionToEnd (
124
- EditorState . createWithContent (
125
- Draft . convertFromRaw ( {
126
- entityMap : { } ,
127
- blocks : [
128
- {
129
- key : "item1" ,
130
- text : "Some text" ,
131
- type : "unstyled" ,
132
- depth : 0 ,
133
- inlineStyleRanges : [ boldInlineStyleRange ] ,
134
- entityRanges : [ ] ,
135
- data : { } ,
136
- } ,
137
- {
138
- key : "item2" ,
139
- text : "" ,
140
- type : "unstyled" ,
141
- depth : 0 ,
142
- inlineStyleRanges : [ ] ,
143
- entityRanges : [ ] ,
144
- data : { } ,
145
- } ,
146
- ] ,
147
- } )
154
+ const editorState = applyMDtoInlineStyleChange (
155
+ EditorState . moveSelectionToEnd (
156
+ EditorState . createWithContent (
157
+ Draft . convertFromRaw ( {
158
+ entityMap : { } ,
159
+ blocks : [
160
+ {
161
+ key : "item1" ,
162
+ text : "Some text" ,
163
+ type : "unstyled" ,
164
+ depth : 0 ,
165
+ inlineStyleRanges : [ boldInlineStyleRange ] ,
166
+ entityRanges : [ ] ,
167
+ data : { } ,
168
+ } ,
169
+ {
170
+ key : "item2" ,
171
+ text : "" ,
172
+ type : "unstyled" ,
173
+ depth : 0 ,
174
+ inlineStyleRanges : [ ] ,
175
+ entityRanges : [ ] ,
176
+ data : { } ,
177
+ } ,
178
+ ] ,
179
+ } )
180
+ )
148
181
)
149
182
) ;
150
- expect ( handleBeforeInput ( "a" , before , { setEditorState } ) ) . toEqual (
183
+
184
+ expect ( handleBeforeInput ( "a" , editorState , { setEditorState } ) ) . toEqual (
151
185
"handled"
152
186
) ;
153
187
const raw = convertToRaw (
0 commit comments