File tree Expand file tree Collapse file tree 1 file changed +57
-3
lines changed Expand file tree Collapse file tree 1 file changed +57
-3
lines changed Original file line number Diff line number Diff line change 1- /* eslint-disable no-unused-vars */
2-
31import { expect } from 'chai' ;
2+ import sinon from 'sinon' ;
43import Draft , { EditorState , SelectionState } from 'draft-js' ;
54import leaveList from '../leaveList' ;
65
76describe ( 'leaveList' , ( ) => {
8- it ( 'is pending' ) ;
7+ before ( ( ) => {
8+ sinon . stub ( Draft , 'genKey' ) . returns ( 'item2' ) ;
9+ } ) ;
10+ after ( ( ) => {
11+ Draft . genKey . restore ( ) ;
12+ } ) ;
13+ [
14+ 'unordered-list-item' ,
15+ 'ordered-list-item' ,
16+ 'checkable-list-item'
17+ ] . forEach ( ( type ) => {
18+ const beforeRawContentState = {
19+ entityMap : { } ,
20+ blocks : [ {
21+ key : 'item1' ,
22+ text : 'piyo' ,
23+ type,
24+ depth : 0 ,
25+ inlineStyleRanges : [ ] ,
26+ entityRanges : [ ] ,
27+ data : { }
28+ } ]
29+ } ;
30+ const afterRawContentState = {
31+ entityMap : { } ,
32+ blocks : [ {
33+ key : 'item1' ,
34+ text : 'piyo' ,
35+ type : 'unstyled' ,
36+ depth : 0 ,
37+ inlineStyleRanges : [ ] ,
38+ entityRanges : [ ] ,
39+ data : { }
40+ } ]
41+ } ;
42+ const selection = new SelectionState ( {
43+ anchorKey : 'item1' ,
44+ anchorOffset : 6 ,
45+ focusKey : 'item1' ,
46+ focusOffset : 6 ,
47+ isBackward : false ,
48+ hasFocus : true
49+ } ) ;
50+ const contentState = Draft . convertFromRaw ( beforeRawContentState ) ;
51+ const editorState = EditorState . forceSelection (
52+ EditorState . createWithContent ( contentState ) , selection ) ;
53+ it ( 'converts block type' , ( ) => {
54+ const newEditorState = leaveList ( editorState ) ;
55+ expect ( newEditorState ) . not . to . equal ( editorState ) ;
56+ expect (
57+ Draft . convertToRaw ( newEditorState . getCurrentContent ( ) )
58+ ) . to . deep . equal (
59+ afterRawContentState
60+ ) ;
61+ } ) ;
62+ } ) ;
963} ) ;
You can’t perform that action at this time.
0 commit comments