Skip to content

Commit dbf7b4f

Browse files
committed
insertLink test
1 parent b61a761 commit dbf7b4f

File tree

2 files changed

+62
-4
lines changed

2 files changed

+62
-4
lines changed
Lines changed: 62 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,68 @@
1-
/* eslint-disable no-unused-vars */
2-
31
import { expect } from 'chai';
42
import Draft, { EditorState, SelectionState } from 'draft-js';
53
import insertLink from '../insertLink';
64

75
describe('insertLink', () => {
8-
it('is pending');
6+
const markup = '[bar](http://cultofthepartyparrot.com/ "party")';
7+
const text = `foo ${markup} baz`;
8+
const beforeRawContentState = {
9+
entityMap: {},
10+
blocks: [{
11+
key: 'item1',
12+
text,
13+
type: 'unstyled',
14+
depth: 0,
15+
inlineStyleRanges: [],
16+
entityRanges: [],
17+
data: {}
18+
}]
19+
};
20+
const afterRawContentState = {
21+
entityMap: {
22+
0: {
23+
data: {
24+
href: 'http://cultofthepartyparrot.com/parrots/aussieparrot.gif',
25+
title: 'party'
26+
},
27+
mutability: 'MUTABLE',
28+
type: 'LINK'
29+
}
30+
},
31+
blocks: [{
32+
key: 'item1',
33+
text: 'foo bar baz',
34+
type: 'unstyled',
35+
depth: 0,
36+
inlineStyleRanges: [],
37+
entityRanges: [{
38+
key: 0,
39+
length: 3,
40+
offset: 4
41+
}],
42+
data: {}
43+
}]
44+
};
45+
const selection = new SelectionState({
46+
anchorKey: 'item1',
47+
anchorOffset: 6,
48+
focusKey: 'item1',
49+
focusOffset: 6,
50+
isBackward: false,
51+
hasFocus: true
52+
});
53+
const contentState = Draft.convertFromRaw(beforeRawContentState);
54+
const editorState = EditorState.forceSelection(
55+
EditorState.createWithContent(contentState), selection);
56+
it('converts block type', () => {
57+
const matchArr = [markup, 'bar', 'http://cultofthepartyparrot.com/parrots/aussieparrot.gif', 'party'];
58+
matchArr.index = 4;
59+
matchArr.input = text;
60+
const newEditorState = insertLink(editorState, matchArr);
61+
expect(newEditorState).not.to.equal(editorState);
62+
expect(
63+
Draft.convertToRaw(newEditorState.getCurrentContent())
64+
).to.deep.equal(
65+
afterRawContentState
66+
);
67+
});
968
});

src/modifiers/leaveList.js

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
import { RichUtils } from 'draft-js';
2-
// import insertEmptyBlock from './insertEmptyBlock';
32

43
const leaveList = (editorState) => {
54
const contentState = editorState.getCurrentContent();

0 commit comments

Comments
 (0)