Skip to content

Commit bbe4489

Browse files
committed
leaveList test
1 parent dbf7b4f commit bbe4489

File tree

1 file changed

+57
-3
lines changed

1 file changed

+57
-3
lines changed
Lines changed: 57 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,63 @@
1-
/* eslint-disable no-unused-vars */
2-
31
import { expect } from 'chai';
2+
import sinon from 'sinon';
43
import Draft, { EditorState, SelectionState } from 'draft-js';
54
import leaveList from '../leaveList';
65

76
describe('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
});

0 commit comments

Comments
 (0)