This repository was archived by the owner on Feb 6, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 2.6k
Expand file tree
/
Copy pathDraftEditorContentsExperimental.react-test.js
More file actions
131 lines (116 loc) · 3.06 KB
/
DraftEditorContentsExperimental.react-test.js
File metadata and controls
131 lines (116 loc) · 3.06 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
/**
* Copyright (c) Facebook, Inc. and its affiliates.
*
* This source code is licensed under the MIT license found in the
* LICENSE file in the root directory of this source tree.
*
* @emails oncall+draft_js
* @format
*/
'use strict';
const ContentBlockNode = require('ContentBlockNode');
const ContentState = require('ContentState');
const DefaultDraftBlockRenderMap = require('DefaultDraftBlockRenderMap');
const DraftEditorContents = require('DraftEditorContentsExperimental.react');
const EditorState = require('EditorState');
const React = require('React');
const SelectionState = require('SelectionState');
const TestHelper = require('_DraftTestHelper');
const Immutable = require('immutable');
const ReactTestRenderer = require('react-test-renderer');
const {List} = Immutable;
const selectionState = new SelectionState({
anchorKey: 'A',
anchorOffset: 0,
focusKey: 'A',
focusOffset: 0,
isBackward: false,
hasFocus: true,
});
const contentState = ContentState.createFromBlockArray([
new ContentBlockNode({
key: 'A',
text: 'Alpha',
type: 'blockquote',
children: List(),
}),
]);
const PROPS = {
blockRenderMap: DefaultDraftBlockRenderMap,
blockRendererFn: block => null,
blockStyleFn: block => '',
contentState,
customStyleFn: (style, block) => null,
editorKey: 'editor',
editorState: EditorState.createWithContent(contentState),
selection: selectionState,
};
const assertDraftEditorContentsRendering = props => {
const childProps = {
...props,
editorState: EditorState.createWithContent(props.contentState),
};
const blockNode = ReactTestRenderer.create(
<DraftEditorContents {...childProps} />,
);
expect(
TestHelper.transformSnapshotProps(blockNode.toJSON()),
).toMatchSnapshot();
};
test('renders ContentBlockNode', () => {
assertDraftEditorContentsRendering(PROPS);
});
test('renders ContentBlockNodes', () => {
const contentState = ContentState.createFromBlockArray([
new ContentBlockNode({
key: 'A',
text: '',
type: 'blockquote',
children: List(['B']),
nextSibling: 'D',
}),
new ContentBlockNode({
parent: 'A',
key: 'B',
text: 'fist list item',
type: 'ordered-list-item',
children: List(['C']),
}),
new ContentBlockNode({
parent: 'B',
key: 'C',
text: 'header inside list',
type: 'header-one',
}),
new ContentBlockNode({
key: 'D',
prevSibling: 'A',
text: 'header two',
type: 'header-two',
}),
]);
assertDraftEditorContentsRendering({
...PROPS,
contentState,
});
});
test('renders ContentBlockNodes with root blocks that have wrapperTemplate', () => {
const contentState = ContentState.createFromBlockArray([
new ContentBlockNode({
key: 'A',
text: 'list one',
type: 'ordered-list-item',
nextSibling: 'B',
}),
new ContentBlockNode({
key: 'B',
text: 'list two',
type: 'ordered-list-item',
prevSibling: 'A',
}),
]);
assertDraftEditorContentsRendering({
...PROPS,
contentState,
});
});