11import { expect } from 'chai' ;
22import Draft , { EditorState , SelectionState } from 'draft-js' ;
3- import { addText , replaceText , addEmptyBlock } from '../utils' ;
3+ import insertEmptyBlock from '../modifiers/insertEmptyBlock' ;
4+ import { addText , replaceText } from '../utils' ;
45
56describe ( 'utils test' , ( ) => {
67 it ( 'is loaded' , ( ) => {
78 expect ( addText ) . to . be . a ( 'function' ) ;
89 expect ( replaceText ) . to . be . a ( 'function' ) ;
9- expect ( addEmptyBlock ) . to . be . a ( 'function' ) ;
1010 } ) ;
1111
1212 const newRawContentState = {
@@ -21,25 +21,11 @@ describe('utils test', () => {
2121 data : { }
2222 } ]
2323 } ;
24- it ( 'should add empty block' , ( ) => {
25- let newEditorState = EditorState . createWithContent ( Draft . convertFromRaw ( newRawContentState ) ) ;
26- const initialBlockSize = newEditorState . getCurrentContent ( ) . getBlockMap ( ) . size ;
27- const randomBlockSize = Math . floor ( ( Math . random ( ) * 50 ) + 1 ) ; // random number bettween 1 to 50
28- for ( let i = 0 ; i < randomBlockSize ; i ++ ) { // eslint-disable-line no-plusplus
29- newEditorState = addEmptyBlock ( newEditorState ) ;
30- }
31- const finalBlockSize = newEditorState . getCurrentContent ( ) . getBlockMap ( ) . size ;
32- expect ( finalBlockSize - initialBlockSize ) . to . equal ( randomBlockSize ) ;
33-
34- const lastBlock = newEditorState . getCurrentContent ( ) . getLastBlock ( ) ;
35- expect ( lastBlock . getType ( ) ) . to . equal ( 'unstyled' ) ;
36- expect ( lastBlock . getText ( ) ) . to . have . lengthOf ( 0 ) ;
37- } ) ;
3824
3925 it ( 'should addText' , ( ) => {
4026 let newEditorState = EditorState . createWithContent ( Draft . convertFromRaw ( newRawContentState ) ) ;
4127 const randomText = Date . now ( ) . toString ( 32 ) ;
42- newEditorState = addEmptyBlock ( newEditorState ) ;
28+ newEditorState = insertEmptyBlock ( newEditorState ) ;
4329 newEditorState = addText ( newEditorState , randomText ) ;
4430 const currentContent = newEditorState . getCurrentContent ( ) ;
4531 expect ( currentContent . hasText ( ) ) . to . equal ( true ) ;
0 commit comments