@pie-lib/editable-html-tip-tap 2.1.18 → 2.1.20-beta.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +0 -126
- package/lib/components/EditableHtml.js +0 -56
- package/lib/components/EditableHtml.js.map +1 -1
- package/lib/components/MenuBar.js +12 -81
- package/lib/components/MenuBar.js.map +1 -1
- package/lib/components/TiptapContainer.js +2 -2
- package/lib/components/TiptapContainer.js.map +1 -1
- package/lib/components/common/toolbar-buttons.js +5 -6
- package/lib/components/common/toolbar-buttons.js.map +1 -1
- package/lib/components/icons/TableIcons.js +1 -3
- package/lib/components/icons/TableIcons.js.map +1 -1
- package/lib/components/icons/TextAlign.js +5 -14
- package/lib/components/icons/TextAlign.js.map +1 -1
- package/lib/components/respArea/MathTemplated.js +8 -14
- package/lib/components/respArea/MathTemplated.js.map +1 -1
- package/lib/extensions/math.js +37 -19
- package/lib/extensions/math.js.map +1 -1
- package/lib/styles/editorContainerStyles.js +2 -2
- package/lib/styles/editorContainerStyles.js.map +1 -1
- package/package.json +9 -9
- package/src/components/EditableHtml.jsx +0 -52
- package/src/components/MenuBar.jsx +9 -91
- package/src/components/TiptapContainer.jsx +2 -2
- package/src/components/common/toolbar-buttons.jsx +4 -6
- package/src/components/icons/TableIcons.jsx +1 -9
- package/src/components/icons/TextAlign.jsx +5 -39
- package/src/components/respArea/MathTemplated.jsx +6 -13
- package/src/extensions/math.js +19 -11
- package/src/styles/editorContainerStyles.js +2 -2
- package/LICENSE.md +0 -5
- package/src/__tests__/EditableHtml.test.jsx +0 -668
- package/src/__tests__/constants.test.js +0 -19
- package/src/__tests__/div-to-paragraph-conversion.test.jsx +0 -125
- package/src/__tests__/editor-attributes.test.jsx +0 -77
- package/src/__tests__/extensions.test.js +0 -208
- package/src/__tests__/index.test.jsx +0 -154
- package/src/__tests__/size-utils.test.js +0 -64
- package/src/__tests__/spellcheck.test.jsx +0 -63
- package/src/__tests__/theme.test.js +0 -17
- package/src/components/__tests__/AltDialog.test.jsx +0 -147
- package/src/components/__tests__/CharacterPicker.test.jsx +0 -270
- package/src/components/__tests__/CssIcon.test.jsx +0 -46
- package/src/components/__tests__/DragInTheBlank.test.jsx +0 -255
- package/src/components/__tests__/ExplicitConstructedResponse.test.jsx +0 -209
- package/src/components/__tests__/ImageToolbar.test.jsx +0 -128
- package/src/components/__tests__/InlineDropdown.test.jsx +0 -557
- package/src/components/__tests__/InsertImageHandler.test.js +0 -161
- package/src/components/__tests__/MediaDialog.test.jsx +0 -293
- package/src/components/__tests__/MediaToolbar.test.jsx +0 -74
- package/src/components/__tests__/MediaWrapper.test.jsx +0 -81
- package/src/components/__tests__/MenuBar.test.jsx +0 -338
- package/src/components/__tests__/RespArea.test.jsx +0 -122
- package/src/components/__tests__/TableIcons.test.jsx +0 -149
- package/src/components/__tests__/TextAlign.test.jsx +0 -167
- package/src/components/__tests__/TiptapContainer.test.jsx +0 -138
- package/src/components/__tests__/characterUtils.test.js +0 -166
- package/src/components/__tests__/choice.test.jsx +0 -171
- package/src/components/__tests__/custom-popper.test.jsx +0 -82
- package/src/components/__tests__/done-button.test.jsx +0 -54
- package/src/components/__tests__/toolbar-buttons.test.jsx +0 -247
- package/src/components/respArea/DragInTheBlank/__tests__/choice.test.jsx +0 -72
- package/src/components/respArea/__tests__/MathTemplated.test.jsx +0 -210
- package/src/extensions/__tests__/css.test.js +0 -196
- package/src/extensions/__tests__/custom-toolbar-wrapper.test.jsx +0 -180
- package/src/extensions/__tests__/divNode.test.js +0 -87
- package/src/extensions/__tests__/ensure-empty-root-div.test.js +0 -57
- package/src/extensions/__tests__/ensure-list-item-content-is-div.test.js +0 -44
- package/src/extensions/__tests__/extended-list-item.test.js +0 -13
- package/src/extensions/__tests__/extended-table-cell.test.js +0 -22
- package/src/extensions/__tests__/extended-table.test.js +0 -183
- package/src/extensions/__tests__/image-component.test.jsx +0 -346
- package/src/extensions/__tests__/image.test.js +0 -237
- package/src/extensions/__tests__/math.test.js +0 -898
- package/src/extensions/__tests__/media-node-view.test.jsx +0 -298
- package/src/extensions/__tests__/media.test.js +0 -271
- package/src/extensions/__tests__/responseArea.test.js +0 -655
- package/src/utils/__tests__/helper.test.js +0 -126
- package/src/utils/__tests__/toolbar.test.js +0 -43
|
@@ -1,655 +0,0 @@
|
|
|
1
|
-
import {
|
|
2
|
-
DragInTheBlankNode,
|
|
3
|
-
ExplicitConstructedResponseNode,
|
|
4
|
-
InlineDropdownNode,
|
|
5
|
-
ResponseAreaExtension,
|
|
6
|
-
} from '../responseArea';
|
|
7
|
-
|
|
8
|
-
jest.mock('@tiptap/core', () => ({
|
|
9
|
-
Extension: { create: jest.fn((config) => config) },
|
|
10
|
-
Node: { create: jest.fn((config) => config) },
|
|
11
|
-
}));
|
|
12
|
-
|
|
13
|
-
jest.mock('@tiptap/react', () => ({
|
|
14
|
-
Node: { create: jest.fn((config) => config) },
|
|
15
|
-
ReactNodeViewRenderer: jest.fn((component) => component),
|
|
16
|
-
}));
|
|
17
|
-
|
|
18
|
-
jest.mock('prosemirror-state', () => ({
|
|
19
|
-
Plugin: jest.fn(function (config) {
|
|
20
|
-
return config;
|
|
21
|
-
}),
|
|
22
|
-
PluginKey: jest.fn(function (key) {
|
|
23
|
-
this.key = key;
|
|
24
|
-
}),
|
|
25
|
-
TextSelection: {
|
|
26
|
-
near: jest.fn((pos, dir) => ({ type: 'text', pos, dir })),
|
|
27
|
-
create: jest.fn((doc, pos) => ({ type: 'text', pos })),
|
|
28
|
-
},
|
|
29
|
-
NodeSelection: {
|
|
30
|
-
create: jest.fn((doc, pos) => ({ type: 'node', pos })),
|
|
31
|
-
},
|
|
32
|
-
}));
|
|
33
|
-
|
|
34
|
-
jest.mock('../../components/respArea/ExplicitConstructedResponse', () => ({
|
|
35
|
-
__esModule: true,
|
|
36
|
-
default: jest.fn(() => <div data-testid="explicit-constructed-response" />),
|
|
37
|
-
}));
|
|
38
|
-
|
|
39
|
-
jest.mock('../../components/respArea/DragInTheBlank/DragInTheBlank', () => ({
|
|
40
|
-
__esModule: true,
|
|
41
|
-
default: jest.fn(() => <div data-testid="drag-in-the-blank" />),
|
|
42
|
-
}));
|
|
43
|
-
|
|
44
|
-
jest.mock('../../components/respArea/InlineDropdown', () => ({
|
|
45
|
-
__esModule: true,
|
|
46
|
-
default: jest.fn(() => <div data-testid="inline-dropdown" />),
|
|
47
|
-
}));
|
|
48
|
-
|
|
49
|
-
describe('ResponseAreaExtension', () => {
|
|
50
|
-
describe('configuration', () => {
|
|
51
|
-
it('has correct name', () => {
|
|
52
|
-
expect(ResponseAreaExtension.name).toBe('responseArea');
|
|
53
|
-
});
|
|
54
|
-
});
|
|
55
|
-
|
|
56
|
-
describe('addOptions', () => {
|
|
57
|
-
it('returns default options', () => {
|
|
58
|
-
const options = ResponseAreaExtension.addOptions();
|
|
59
|
-
|
|
60
|
-
expect(options).toHaveProperty('maxResponseAreas', null);
|
|
61
|
-
expect(options).toHaveProperty('error', null);
|
|
62
|
-
expect(options).toHaveProperty('options', null);
|
|
63
|
-
expect(options).toHaveProperty('respAreaToolbar', null);
|
|
64
|
-
expect(options).toHaveProperty('onHandleAreaChange', null);
|
|
65
|
-
});
|
|
66
|
-
});
|
|
67
|
-
|
|
68
|
-
describe('addProseMirrorPlugins', () => {
|
|
69
|
-
it('returns empty array when no type specified', () => {
|
|
70
|
-
const context = {
|
|
71
|
-
options: {},
|
|
72
|
-
};
|
|
73
|
-
|
|
74
|
-
const plugins = ResponseAreaExtension.addProseMirrorPlugins.call(context);
|
|
75
|
-
|
|
76
|
-
expect(Array.isArray(plugins)).toBe(true);
|
|
77
|
-
expect(plugins).toHaveLength(0);
|
|
78
|
-
});
|
|
79
|
-
|
|
80
|
-
it('returns plugin array when type is specified', () => {
|
|
81
|
-
const context = {
|
|
82
|
-
options: {
|
|
83
|
-
type: 'explicit-constructed-response',
|
|
84
|
-
maxResponseAreas: 5,
|
|
85
|
-
},
|
|
86
|
-
};
|
|
87
|
-
|
|
88
|
-
const plugins = ResponseAreaExtension.addProseMirrorPlugins.call(context);
|
|
89
|
-
|
|
90
|
-
expect(Array.isArray(plugins)).toBe(true);
|
|
91
|
-
expect(plugins).toHaveLength(1);
|
|
92
|
-
expect(plugins[0]).toHaveProperty('key');
|
|
93
|
-
expect(plugins[0]).toHaveProperty('view');
|
|
94
|
-
});
|
|
95
|
-
});
|
|
96
|
-
|
|
97
|
-
describe('addCommands', () => {
|
|
98
|
-
it('returns insertResponseArea command', () => {
|
|
99
|
-
const commands = ResponseAreaExtension.addCommands();
|
|
100
|
-
|
|
101
|
-
expect(commands).toHaveProperty('insertResponseArea');
|
|
102
|
-
expect(typeof commands.insertResponseArea).toBe('function');
|
|
103
|
-
});
|
|
104
|
-
|
|
105
|
-
it('returns refreshResponseArea command', () => {
|
|
106
|
-
const commands = ResponseAreaExtension.addCommands();
|
|
107
|
-
|
|
108
|
-
expect(commands).toHaveProperty('refreshResponseArea');
|
|
109
|
-
expect(typeof commands.refreshResponseArea).toBe('function');
|
|
110
|
-
});
|
|
111
|
-
|
|
112
|
-
it('refreshResponseArea handles node with attrs safely', () => {
|
|
113
|
-
const context = {
|
|
114
|
-
options: {
|
|
115
|
-
type: 'explicit-constructed-response',
|
|
116
|
-
maxResponseAreas: 5,
|
|
117
|
-
},
|
|
118
|
-
};
|
|
119
|
-
|
|
120
|
-
const commands = ResponseAreaExtension.addCommands.call(context);
|
|
121
|
-
const refreshCommand = commands.refreshResponseArea();
|
|
122
|
-
|
|
123
|
-
// Mock transaction and state
|
|
124
|
-
const mockNode = {
|
|
125
|
-
attrs: {
|
|
126
|
-
index: '0',
|
|
127
|
-
value: 'test',
|
|
128
|
-
},
|
|
129
|
-
};
|
|
130
|
-
|
|
131
|
-
const mockTr = {
|
|
132
|
-
setNodeMarkup: jest.fn(),
|
|
133
|
-
setSelection: jest.fn(),
|
|
134
|
-
};
|
|
135
|
-
|
|
136
|
-
const mockState = {
|
|
137
|
-
selection: {
|
|
138
|
-
from: 0,
|
|
139
|
-
$from: {
|
|
140
|
-
nodeAfter: mockNode,
|
|
141
|
-
},
|
|
142
|
-
},
|
|
143
|
-
tr: mockTr,
|
|
144
|
-
};
|
|
145
|
-
|
|
146
|
-
const mockCommands = {
|
|
147
|
-
focus: jest.fn(),
|
|
148
|
-
};
|
|
149
|
-
|
|
150
|
-
const mockDispatch = jest.fn();
|
|
151
|
-
|
|
152
|
-
refreshCommand({
|
|
153
|
-
tr: mockTr,
|
|
154
|
-
state: mockState,
|
|
155
|
-
commands: mockCommands,
|
|
156
|
-
dispatch: mockDispatch,
|
|
157
|
-
});
|
|
158
|
-
|
|
159
|
-
expect(mockTr.setNodeMarkup).toHaveBeenCalled();
|
|
160
|
-
});
|
|
161
|
-
|
|
162
|
-
it('refreshResponseArea handles node without attrs safely (optional chaining)', () => {
|
|
163
|
-
const context = {
|
|
164
|
-
options: {
|
|
165
|
-
type: 'explicit-constructed-response',
|
|
166
|
-
maxResponseAreas: 5,
|
|
167
|
-
},
|
|
168
|
-
};
|
|
169
|
-
|
|
170
|
-
const commands = ResponseAreaExtension.addCommands.call(context);
|
|
171
|
-
const refreshCommand = commands.refreshResponseArea();
|
|
172
|
-
|
|
173
|
-
// Mock transaction and state with node that has no attrs
|
|
174
|
-
const mockNode = null;
|
|
175
|
-
|
|
176
|
-
const mockTr = {
|
|
177
|
-
setNodeMarkup: jest.fn(),
|
|
178
|
-
setSelection: jest.fn(),
|
|
179
|
-
};
|
|
180
|
-
|
|
181
|
-
const mockState = {
|
|
182
|
-
selection: {
|
|
183
|
-
from: 0,
|
|
184
|
-
$from: {
|
|
185
|
-
nodeAfter: mockNode,
|
|
186
|
-
},
|
|
187
|
-
},
|
|
188
|
-
tr: mockTr,
|
|
189
|
-
};
|
|
190
|
-
|
|
191
|
-
const mockCommands = {
|
|
192
|
-
focus: jest.fn(),
|
|
193
|
-
};
|
|
194
|
-
|
|
195
|
-
const mockDispatch = jest.fn();
|
|
196
|
-
|
|
197
|
-
// This should not throw an error due to optional chaining on node?.attrs
|
|
198
|
-
expect(() => {
|
|
199
|
-
refreshCommand({
|
|
200
|
-
tr: mockTr,
|
|
201
|
-
state: mockState,
|
|
202
|
-
commands: mockCommands,
|
|
203
|
-
dispatch: mockDispatch,
|
|
204
|
-
});
|
|
205
|
-
}).not.toThrow();
|
|
206
|
-
});
|
|
207
|
-
|
|
208
|
-
it('refreshResponseArea updates timestamp in node attributes', () => {
|
|
209
|
-
const context = {
|
|
210
|
-
options: {
|
|
211
|
-
type: 'explicit-constructed-response',
|
|
212
|
-
maxResponseAreas: 5,
|
|
213
|
-
},
|
|
214
|
-
};
|
|
215
|
-
|
|
216
|
-
const commands = ResponseAreaExtension.addCommands.call(context);
|
|
217
|
-
const refreshCommand = commands.refreshResponseArea();
|
|
218
|
-
|
|
219
|
-
const mockNode = {
|
|
220
|
-
attrs: {
|
|
221
|
-
index: '0',
|
|
222
|
-
value: 'test',
|
|
223
|
-
updated: '1234567890',
|
|
224
|
-
},
|
|
225
|
-
};
|
|
226
|
-
|
|
227
|
-
const mockTr = {
|
|
228
|
-
setNodeMarkup: jest.fn((pos, type, attrs) => {
|
|
229
|
-
// Verify that updated timestamp is being set
|
|
230
|
-
expect(attrs.updated).toBeDefined();
|
|
231
|
-
expect(attrs.updated).not.toBe('1234567890');
|
|
232
|
-
}),
|
|
233
|
-
setSelection: jest.fn(),
|
|
234
|
-
};
|
|
235
|
-
|
|
236
|
-
const mockState = {
|
|
237
|
-
selection: {
|
|
238
|
-
from: 0,
|
|
239
|
-
$from: {
|
|
240
|
-
nodeAfter: mockNode,
|
|
241
|
-
},
|
|
242
|
-
},
|
|
243
|
-
tr: mockTr,
|
|
244
|
-
};
|
|
245
|
-
|
|
246
|
-
const mockCommands = {
|
|
247
|
-
focus: jest.fn(),
|
|
248
|
-
};
|
|
249
|
-
|
|
250
|
-
const mockDispatch = jest.fn();
|
|
251
|
-
|
|
252
|
-
refreshCommand({
|
|
253
|
-
tr: mockTr,
|
|
254
|
-
state: mockState,
|
|
255
|
-
commands: mockCommands,
|
|
256
|
-
dispatch: mockDispatch,
|
|
257
|
-
});
|
|
258
|
-
|
|
259
|
-
expect(mockTr.setNodeMarkup).toHaveBeenCalled();
|
|
260
|
-
});
|
|
261
|
-
|
|
262
|
-
describe('insertResponseArea', () => {
|
|
263
|
-
beforeEach(() => {
|
|
264
|
-
jest.resetModules();
|
|
265
|
-
});
|
|
266
|
-
|
|
267
|
-
const buildInsertCommand = (type = 'inline-dropdown') => {
|
|
268
|
-
const { ResponseAreaExtension } = require('../responseArea');
|
|
269
|
-
const context = {
|
|
270
|
-
options: {
|
|
271
|
-
type,
|
|
272
|
-
maxResponseAreas: 5,
|
|
273
|
-
},
|
|
274
|
-
};
|
|
275
|
-
const commands = ResponseAreaExtension.addCommands.call(context);
|
|
276
|
-
return commands.insertResponseArea(type);
|
|
277
|
-
};
|
|
278
|
-
|
|
279
|
-
const createDoc = (existingCount, typeName = 'inline_dropdown') => ({
|
|
280
|
-
descendants: jest.fn((callback) => {
|
|
281
|
-
for (let i = 0; i < existingCount; i += 1) {
|
|
282
|
-
callback({ type: { name: typeName } }, i);
|
|
283
|
-
}
|
|
284
|
-
}),
|
|
285
|
-
content: { size: 50 },
|
|
286
|
-
});
|
|
287
|
-
|
|
288
|
-
it('assigns index 1 and id 1 on the first insert', () => {
|
|
289
|
-
const insert = buildInsertCommand();
|
|
290
|
-
const mockInlineNode = { nodeSize: 1 };
|
|
291
|
-
const create = jest.fn(() => mockInlineNode);
|
|
292
|
-
const mockDoc = createDoc(0);
|
|
293
|
-
const mockTr = {
|
|
294
|
-
insert: jest.fn(),
|
|
295
|
-
doc: mockDoc,
|
|
296
|
-
setSelection: jest.fn(),
|
|
297
|
-
};
|
|
298
|
-
const state = {
|
|
299
|
-
schema: {
|
|
300
|
-
nodes: {
|
|
301
|
-
inline_dropdown: { create },
|
|
302
|
-
},
|
|
303
|
-
},
|
|
304
|
-
doc: mockDoc,
|
|
305
|
-
selection: { from: 5 },
|
|
306
|
-
};
|
|
307
|
-
const mockDispatch = jest.fn();
|
|
308
|
-
const mockCommands = { focus: jest.fn() };
|
|
309
|
-
|
|
310
|
-
const result = insert({
|
|
311
|
-
tr: mockTr,
|
|
312
|
-
state,
|
|
313
|
-
dispatch: mockDispatch,
|
|
314
|
-
commands: mockCommands,
|
|
315
|
-
});
|
|
316
|
-
|
|
317
|
-
expect(result).toBe(true);
|
|
318
|
-
expect(create).toHaveBeenCalledWith({
|
|
319
|
-
index: '1',
|
|
320
|
-
id: '1',
|
|
321
|
-
value: '',
|
|
322
|
-
});
|
|
323
|
-
expect(mockTr.insert).toHaveBeenCalledWith(5, mockInlineNode);
|
|
324
|
-
expect(mockDispatch).toHaveBeenCalled();
|
|
325
|
-
});
|
|
326
|
-
|
|
327
|
-
it('assigns consecutive indices on repeated inserts', () => {
|
|
328
|
-
const insert = buildInsertCommand();
|
|
329
|
-
const mockInlineNode = { nodeSize: 1 };
|
|
330
|
-
const create = jest.fn(() => mockInlineNode);
|
|
331
|
-
const mockDoc = createDoc(0);
|
|
332
|
-
|
|
333
|
-
const runOnce = () => {
|
|
334
|
-
const mockTr = {
|
|
335
|
-
insert: jest.fn(),
|
|
336
|
-
doc: mockDoc,
|
|
337
|
-
setSelection: jest.fn(),
|
|
338
|
-
};
|
|
339
|
-
const state = {
|
|
340
|
-
schema: {
|
|
341
|
-
nodes: {
|
|
342
|
-
inline_dropdown: { create },
|
|
343
|
-
},
|
|
344
|
-
},
|
|
345
|
-
doc: mockDoc,
|
|
346
|
-
selection: { from: 1 },
|
|
347
|
-
};
|
|
348
|
-
insert({
|
|
349
|
-
tr: mockTr,
|
|
350
|
-
state,
|
|
351
|
-
dispatch: jest.fn(),
|
|
352
|
-
commands: { focus: jest.fn() },
|
|
353
|
-
});
|
|
354
|
-
};
|
|
355
|
-
|
|
356
|
-
runOnce();
|
|
357
|
-
runOnce();
|
|
358
|
-
|
|
359
|
-
expect(create.mock.calls[0][0]).toEqual({ index: '1', id: '1', value: '' });
|
|
360
|
-
expect(create.mock.calls[1][0]).toEqual({ index: '2', id: '2', value: '' });
|
|
361
|
-
});
|
|
362
|
-
|
|
363
|
-
it('returns false when maxResponseAreas is reached', () => {
|
|
364
|
-
const insert = buildInsertCommand();
|
|
365
|
-
const mockInlineNode = { nodeSize: 1 };
|
|
366
|
-
const create = jest.fn(() => mockInlineNode);
|
|
367
|
-
const mockDoc = createDoc(5);
|
|
368
|
-
const mockTr = {
|
|
369
|
-
insert: jest.fn(),
|
|
370
|
-
doc: mockDoc,
|
|
371
|
-
setSelection: jest.fn(),
|
|
372
|
-
};
|
|
373
|
-
const state = {
|
|
374
|
-
schema: {
|
|
375
|
-
nodes: {
|
|
376
|
-
inline_dropdown: { create },
|
|
377
|
-
},
|
|
378
|
-
},
|
|
379
|
-
doc: mockDoc,
|
|
380
|
-
selection: { from: 5 },
|
|
381
|
-
};
|
|
382
|
-
|
|
383
|
-
const result = insert({
|
|
384
|
-
tr: mockTr,
|
|
385
|
-
state,
|
|
386
|
-
dispatch: jest.fn(),
|
|
387
|
-
commands: { focus: jest.fn() },
|
|
388
|
-
});
|
|
389
|
-
|
|
390
|
-
expect(result).toBe(false);
|
|
391
|
-
expect(create).not.toHaveBeenCalled();
|
|
392
|
-
expect(mockTr.insert).not.toHaveBeenCalled();
|
|
393
|
-
});
|
|
394
|
-
|
|
395
|
-
describe('selection after insert', () => {
|
|
396
|
-
const buildStateAndTr = (typeName, { withResolve = false } = {}) => {
|
|
397
|
-
const mockInlineNode = { nodeSize: 1 };
|
|
398
|
-
const create = jest.fn(() => mockInlineNode);
|
|
399
|
-
const mockDoc = {
|
|
400
|
-
descendants: jest.fn(),
|
|
401
|
-
content: { size: 50 },
|
|
402
|
-
...(withResolve ? { resolve: jest.fn((pos) => ({ resolved: pos })) } : {}),
|
|
403
|
-
};
|
|
404
|
-
const mockTr = {
|
|
405
|
-
insert: jest.fn(),
|
|
406
|
-
doc: mockDoc,
|
|
407
|
-
setSelection: jest.fn(),
|
|
408
|
-
};
|
|
409
|
-
const state = {
|
|
410
|
-
schema: { nodes: { [typeName]: { create } } },
|
|
411
|
-
doc: mockDoc,
|
|
412
|
-
selection: { from: 5 },
|
|
413
|
-
};
|
|
414
|
-
|
|
415
|
-
return { mockTr, state };
|
|
416
|
-
};
|
|
417
|
-
|
|
418
|
-
it.each(['inline-dropdown', 'explicit-constructed-response'])(
|
|
419
|
-
'sets a NodeSelection on the inserted node for %s',
|
|
420
|
-
(type) => {
|
|
421
|
-
const insert = buildInsertCommand(type);
|
|
422
|
-
const typeName = type.replace(/-/g, '_');
|
|
423
|
-
const { mockTr, state } = buildStateAndTr(typeName);
|
|
424
|
-
const { NodeSelection, TextSelection } = require('prosemirror-state');
|
|
425
|
-
|
|
426
|
-
insert({ tr: mockTr, state, dispatch: jest.fn(), commands: { focus: jest.fn() } });
|
|
427
|
-
|
|
428
|
-
expect(NodeSelection.create).toHaveBeenCalledWith(mockTr.doc, 5);
|
|
429
|
-
expect(TextSelection.near).not.toHaveBeenCalled();
|
|
430
|
-
expect(mockTr.setSelection).toHaveBeenCalledWith({ type: 'node', pos: 5 });
|
|
431
|
-
},
|
|
432
|
-
);
|
|
433
|
-
|
|
434
|
-
it('sets a TextSelection just after the inserted node for math-templated (no NodeSelection)', () => {
|
|
435
|
-
const insert = buildInsertCommand('math-templated');
|
|
436
|
-
const { mockTr, state } = buildStateAndTr('math_templated', { withResolve: true });
|
|
437
|
-
const { NodeSelection, TextSelection } = require('prosemirror-state');
|
|
438
|
-
|
|
439
|
-
insert({ tr: mockTr, state, dispatch: jest.fn(), commands: { focus: jest.fn() } });
|
|
440
|
-
|
|
441
|
-
expect(NodeSelection.create).not.toHaveBeenCalled();
|
|
442
|
-
// usedPos (5) + nodeSize (1) === 6
|
|
443
|
-
expect(mockTr.doc.resolve).toHaveBeenCalledWith(6);
|
|
444
|
-
expect(TextSelection.near).toHaveBeenCalledWith({ resolved: 6 }, 1);
|
|
445
|
-
expect(mockTr.setSelection).toHaveBeenCalledWith({ type: 'text', pos: { resolved: 6 }, dir: 1 });
|
|
446
|
-
});
|
|
447
|
-
});
|
|
448
|
-
});
|
|
449
|
-
});
|
|
450
|
-
});
|
|
451
|
-
|
|
452
|
-
describe('ExplicitConstructedResponseNode', () => {
|
|
453
|
-
describe('configuration', () => {
|
|
454
|
-
it('has correct name', () => {
|
|
455
|
-
expect(ExplicitConstructedResponseNode.name).toBe('explicit_constructed_response');
|
|
456
|
-
});
|
|
457
|
-
|
|
458
|
-
it('is inline', () => {
|
|
459
|
-
expect(ExplicitConstructedResponseNode.inline).toBe(true);
|
|
460
|
-
});
|
|
461
|
-
|
|
462
|
-
it('is in inline group', () => {
|
|
463
|
-
expect(ExplicitConstructedResponseNode.group).toBe('inline');
|
|
464
|
-
});
|
|
465
|
-
|
|
466
|
-
it('is atomic', () => {
|
|
467
|
-
expect(ExplicitConstructedResponseNode.atom).toBe(true);
|
|
468
|
-
});
|
|
469
|
-
});
|
|
470
|
-
|
|
471
|
-
describe('addAttributes', () => {
|
|
472
|
-
it('returns required attributes', () => {
|
|
473
|
-
const attributes = ExplicitConstructedResponseNode.addAttributes();
|
|
474
|
-
|
|
475
|
-
expect(attributes).toHaveProperty('index');
|
|
476
|
-
expect(attributes).toHaveProperty('value');
|
|
477
|
-
expect(attributes).toHaveProperty('updated');
|
|
478
|
-
|
|
479
|
-
expect(attributes.index).toEqual({ default: null });
|
|
480
|
-
expect(attributes.value).toEqual({ default: '' });
|
|
481
|
-
expect(attributes.updated).toEqual({ default: '' });
|
|
482
|
-
});
|
|
483
|
-
});
|
|
484
|
-
|
|
485
|
-
describe('parseHTML', () => {
|
|
486
|
-
it('returns parsing rules', () => {
|
|
487
|
-
const rules = ExplicitConstructedResponseNode.parseHTML();
|
|
488
|
-
|
|
489
|
-
expect(Array.isArray(rules)).toBe(true);
|
|
490
|
-
expect(rules).toHaveLength(1);
|
|
491
|
-
expect(rules[0]).toHaveProperty('tag');
|
|
492
|
-
});
|
|
493
|
-
});
|
|
494
|
-
|
|
495
|
-
describe('renderHTML', () => {
|
|
496
|
-
it('renders span with attributes', () => {
|
|
497
|
-
const result = ExplicitConstructedResponseNode.renderHTML({
|
|
498
|
-
HTMLAttributes: {
|
|
499
|
-
index: '1',
|
|
500
|
-
id: '1',
|
|
501
|
-
value: 'test',
|
|
502
|
-
},
|
|
503
|
-
});
|
|
504
|
-
|
|
505
|
-
expect(result[0]).toBe('span');
|
|
506
|
-
expect(result[1]).toHaveProperty('data-type', 'explicit_constructed_response');
|
|
507
|
-
});
|
|
508
|
-
});
|
|
509
|
-
|
|
510
|
-
describe('addNodeView', () => {
|
|
511
|
-
it('returns ReactNodeViewRenderer result', () => {
|
|
512
|
-
const result = ExplicitConstructedResponseNode.addNodeView();
|
|
513
|
-
|
|
514
|
-
expect(result).toBeDefined();
|
|
515
|
-
});
|
|
516
|
-
});
|
|
517
|
-
});
|
|
518
|
-
|
|
519
|
-
describe('DragInTheBlankNode', () => {
|
|
520
|
-
describe('configuration', () => {
|
|
521
|
-
it('has correct name', () => {
|
|
522
|
-
expect(DragInTheBlankNode.name).toBe('drag_in_the_blank');
|
|
523
|
-
});
|
|
524
|
-
|
|
525
|
-
it('is inline', () => {
|
|
526
|
-
expect(DragInTheBlankNode.inline).toBe(true);
|
|
527
|
-
});
|
|
528
|
-
|
|
529
|
-
it('is in inline group', () => {
|
|
530
|
-
expect(DragInTheBlankNode.group).toBe('inline');
|
|
531
|
-
});
|
|
532
|
-
|
|
533
|
-
it('is atomic', () => {
|
|
534
|
-
expect(DragInTheBlankNode.atom).toBe(true);
|
|
535
|
-
});
|
|
536
|
-
});
|
|
537
|
-
|
|
538
|
-
describe('addAttributes', () => {
|
|
539
|
-
it('returns required attributes', () => {
|
|
540
|
-
const attributes = DragInTheBlankNode.addAttributes();
|
|
541
|
-
|
|
542
|
-
expect(attributes).toHaveProperty('index');
|
|
543
|
-
expect(attributes).toHaveProperty('id');
|
|
544
|
-
expect(attributes).toHaveProperty('value');
|
|
545
|
-
expect(attributes).toHaveProperty('inTable');
|
|
546
|
-
expect(attributes).toHaveProperty('updated');
|
|
547
|
-
|
|
548
|
-
expect(attributes.index).toEqual({ default: null });
|
|
549
|
-
expect(attributes.id).toEqual({ default: null });
|
|
550
|
-
expect(attributes.value).toEqual({ default: '' });
|
|
551
|
-
expect(attributes.inTable).toEqual({ default: null });
|
|
552
|
-
expect(attributes.updated).toEqual({ default: '' });
|
|
553
|
-
});
|
|
554
|
-
});
|
|
555
|
-
|
|
556
|
-
describe('parseHTML', () => {
|
|
557
|
-
it('returns parsing rules', () => {
|
|
558
|
-
const rules = DragInTheBlankNode.parseHTML();
|
|
559
|
-
|
|
560
|
-
expect(Array.isArray(rules)).toBe(true);
|
|
561
|
-
expect(rules).toHaveLength(1);
|
|
562
|
-
expect(rules[0]).toHaveProperty('tag');
|
|
563
|
-
});
|
|
564
|
-
});
|
|
565
|
-
|
|
566
|
-
describe('renderHTML', () => {
|
|
567
|
-
it('renders span with attributes', () => {
|
|
568
|
-
const result = DragInTheBlankNode.renderHTML({
|
|
569
|
-
HTMLAttributes: {
|
|
570
|
-
index: '1',
|
|
571
|
-
id: '1',
|
|
572
|
-
value: 'test',
|
|
573
|
-
},
|
|
574
|
-
});
|
|
575
|
-
|
|
576
|
-
expect(result[0]).toBe('span');
|
|
577
|
-
expect(result[1]).toHaveProperty('data-type', 'drag_in_the_blank');
|
|
578
|
-
});
|
|
579
|
-
});
|
|
580
|
-
|
|
581
|
-
describe('addNodeView', () => {
|
|
582
|
-
it('returns ReactNodeViewRenderer result', () => {
|
|
583
|
-
const result = DragInTheBlankNode.addNodeView();
|
|
584
|
-
|
|
585
|
-
expect(result).toBeDefined();
|
|
586
|
-
});
|
|
587
|
-
});
|
|
588
|
-
});
|
|
589
|
-
|
|
590
|
-
describe('InlineDropdownNode', () => {
|
|
591
|
-
describe('configuration', () => {
|
|
592
|
-
it('has correct name', () => {
|
|
593
|
-
expect(InlineDropdownNode.name).toBe('inline_dropdown');
|
|
594
|
-
});
|
|
595
|
-
|
|
596
|
-
it('is inline', () => {
|
|
597
|
-
expect(InlineDropdownNode.inline).toBe(true);
|
|
598
|
-
});
|
|
599
|
-
|
|
600
|
-
it('is in inline group', () => {
|
|
601
|
-
expect(InlineDropdownNode.group).toBe('inline');
|
|
602
|
-
});
|
|
603
|
-
|
|
604
|
-
it('is atomic', () => {
|
|
605
|
-
expect(InlineDropdownNode.atom).toBe(true);
|
|
606
|
-
});
|
|
607
|
-
});
|
|
608
|
-
|
|
609
|
-
describe('addAttributes', () => {
|
|
610
|
-
it('returns required attributes', () => {
|
|
611
|
-
const attributes = InlineDropdownNode.addAttributes();
|
|
612
|
-
|
|
613
|
-
expect(attributes).toHaveProperty('index');
|
|
614
|
-
expect(attributes).toHaveProperty('value');
|
|
615
|
-
expect(attributes).toHaveProperty('updated');
|
|
616
|
-
|
|
617
|
-
expect(attributes.index).toEqual({ default: null });
|
|
618
|
-
expect(attributes.value).toEqual({ default: '' });
|
|
619
|
-
expect(attributes.updated).toEqual({ default: '' });
|
|
620
|
-
});
|
|
621
|
-
});
|
|
622
|
-
|
|
623
|
-
describe('parseHTML', () => {
|
|
624
|
-
it('returns parsing rules', () => {
|
|
625
|
-
const rules = InlineDropdownNode.parseHTML();
|
|
626
|
-
|
|
627
|
-
expect(Array.isArray(rules)).toBe(true);
|
|
628
|
-
expect(rules).toHaveLength(1);
|
|
629
|
-
expect(rules[0]).toHaveProperty('tag');
|
|
630
|
-
});
|
|
631
|
-
});
|
|
632
|
-
|
|
633
|
-
describe('renderHTML', () => {
|
|
634
|
-
it('renders span with attributes', () => {
|
|
635
|
-
const result = InlineDropdownNode.renderHTML({
|
|
636
|
-
HTMLAttributes: {
|
|
637
|
-
index: '1',
|
|
638
|
-
id: '1',
|
|
639
|
-
value: 'test',
|
|
640
|
-
},
|
|
641
|
-
});
|
|
642
|
-
|
|
643
|
-
expect(result[0]).toBe('span');
|
|
644
|
-
expect(result[1]).toHaveProperty('data-type', 'inline_dropdown');
|
|
645
|
-
});
|
|
646
|
-
});
|
|
647
|
-
|
|
648
|
-
describe('addNodeView', () => {
|
|
649
|
-
it('returns ReactNodeViewRenderer result', () => {
|
|
650
|
-
const result = InlineDropdownNode.addNodeView();
|
|
651
|
-
|
|
652
|
-
expect(result).toBeDefined();
|
|
653
|
-
});
|
|
654
|
-
});
|
|
655
|
-
});
|