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