This repository was archived by the owner on May 31, 2020. It is now read-only.
File tree Expand file tree Collapse file tree 1 file changed +57
-2
lines changed
packages/utils/src/__test__ Expand file tree Collapse file tree 1 file changed +57
-2
lines changed Original file line number Diff line number Diff line change 11import { expect } from 'chai'
2- import { EditorState , ContentState } from 'draft-js'
3- import { getCharCount , getWordCount , getLineCount } from '../index'
2+ import {
3+ EditorState ,
4+ ContentState ,
5+ convertFromRaw ,
6+ SelectionState ,
7+ } from 'draft-js'
8+ import { getCharCount , getWordCount , getLineCount , hasEntity } from '../index'
9+
10+ describe ( 'Has Entity' , ( ) => {
11+ const createEditorStateFromRaw = raw => {
12+ const contentState = convertFromRaw ( raw )
13+ return EditorState . createWithContent ( contentState )
14+ }
15+
16+ it ( 'create editorState and check if has Entity' , ( ) => {
17+ const rawContent = {
18+ blocks : [
19+ {
20+ text : 'Hey there duder' ,
21+ } ,
22+ {
23+ type : 'atomic' ,
24+ text : ' ' ,
25+ entityRanges : [
26+ {
27+ key : 0 ,
28+ length : 1 ,
29+ offset : 0 ,
30+ } ,
31+ ] ,
32+ } ,
33+ ] ,
34+ entityMap : {
35+ 0 : {
36+ data : {
37+ title : 'Kitten' ,
38+ src : 'https://placekitten.com/200/200' ,
39+ } ,
40+ mutability : 'IMMUTABLE' ,
41+ type : 'IMAGE' ,
42+ } ,
43+ } ,
44+ }
45+ const editorState = createEditorStateFromRaw ( rawContent )
46+ const blockKey = editorState
47+ . getCurrentContent ( )
48+ . getLastBlock ( )
49+ . getKey ( )
50+ const selectionState = SelectionState . createEmpty ( blockKey )
51+ const updatedEditorState = EditorState . forceSelection (
52+ editorState ,
53+ selectionState
54+ )
55+ const result = hasEntity ( updatedEditorState , 'IMAGE' )
56+ expect ( result ) . to . equal ( true )
57+ } )
58+ } )
459
560describe ( 'Char Counter' , ( ) => {
661 const createEditorStateFromText = text => {
You can’t perform that action at this time.
0 commit comments