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