@pie-lib/mask-markup 3.1.3 → 4.0.0-next.37
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/dist/_virtual/_rolldown/runtime.js +4 -0
- package/dist/choices/choice.d.ts +28 -0
- package/dist/choices/choice.js +92 -0
- package/dist/choices/index.d.ts +29 -0
- package/dist/choices/index.js +59 -0
- package/dist/componentize.d.ts +12 -0
- package/dist/componentize.js +4 -0
- package/dist/components/blank.d.ts +45 -0
- package/dist/components/blank.js +273 -0
- package/dist/components/correct-input.d.ts +11 -0
- package/dist/components/dropdown.d.ts +37 -0
- package/dist/components/dropdown.js +311 -0
- package/dist/components/input.d.ts +37 -0
- package/dist/constructed-response.d.ts +44 -0
- package/dist/constructed-response.js +56 -0
- package/dist/customizable.d.ts +43 -0
- package/dist/customizable.js +8 -0
- package/dist/drag-in-the-blank.d.ts +47 -0
- package/dist/drag-in-the-blank.js +220 -0
- package/dist/index.d.ts +15 -0
- package/dist/index.js +7 -0
- package/dist/inline-dropdown.d.ts +44 -0
- package/dist/inline-dropdown.js +24 -0
- package/dist/keyboard-coordinates.d.ts +25 -0
- package/dist/keyboard-coordinates.js +49 -0
- package/dist/mask.d.ts +30 -0
- package/dist/mask.js +95 -0
- package/dist/node_modules/.bun/clsx@2.1.1/node_modules/clsx/dist/clsx.js +16 -0
- package/dist/node_modules/.bun/to-style@1.3.3/node_modules/to-style/index.js +17 -0
- package/dist/node_modules/.bun/to-style@1.3.3/node_modules/to-style/src/cssPrefix.js +9 -0
- package/dist/node_modules/.bun/to-style@1.3.3/node_modules/to-style/src/cssUnitless.js +26 -0
- package/dist/node_modules/.bun/to-style@1.3.3/node_modules/to-style/src/hasOwn.js +11 -0
- package/dist/node_modules/.bun/to-style@1.3.3/node_modules/to-style/src/isFunction.js +11 -0
- package/dist/node_modules/.bun/to-style@1.3.3/node_modules/to-style/src/isObject.js +11 -0
- package/dist/node_modules/.bun/to-style@1.3.3/node_modules/to-style/src/prefixInfo.js +24 -0
- package/dist/node_modules/.bun/to-style@1.3.3/node_modules/to-style/src/prefixProperties.js +32 -0
- package/dist/node_modules/.bun/to-style@1.3.3/node_modules/to-style/src/prefixer.js +29 -0
- package/dist/node_modules/.bun/to-style@1.3.3/node_modules/to-style/src/stringUtils/camelize.js +14 -0
- package/dist/node_modules/.bun/to-style@1.3.3/node_modules/to-style/src/stringUtils/hyphenRe.js +8 -0
- package/dist/node_modules/.bun/to-style@1.3.3/node_modules/to-style/src/stringUtils/hyphenate.js +12 -0
- package/dist/node_modules/.bun/to-style@1.3.3/node_modules/to-style/src/stringUtils/separate.js +11 -0
- package/dist/node_modules/.bun/to-style@1.3.3/node_modules/to-style/src/stringUtils/toLowerFirst.js +10 -0
- package/dist/node_modules/.bun/to-style@1.3.3/node_modules/to-style/src/stringUtils/toUpperFirst.js +10 -0
- package/dist/node_modules/.bun/to-style@1.3.3/node_modules/to-style/src/toStyleObject.js +55 -0
- package/dist/node_modules/.bun/to-style@1.3.3/node_modules/to-style/src/toStyleString.js +16 -0
- package/dist/serialization.d.ts +34 -0
- package/dist/serialization.js +132 -0
- package/dist/with-mask.d.ts +55 -0
- package/dist/with-mask.js +45 -0
- package/package.json +35 -19
- package/CHANGELOG.json +0 -17
- package/CHANGELOG.md +0 -1353
- package/LICENSE.md +0 -5
- package/lib/choices/choice.js +0 -138
- package/lib/choices/choice.js.map +0 -1
- package/lib/choices/index.js +0 -126
- package/lib/choices/index.js.map +0 -1
- package/lib/componentize.js +0 -21
- package/lib/componentize.js.map +0 -1
- package/lib/components/blank.js +0 -489
- package/lib/components/blank.js.map +0 -1
- package/lib/components/correct-input.js +0 -94
- package/lib/components/correct-input.js.map +0 -1
- package/lib/components/dropdown.js +0 -480
- package/lib/components/dropdown.js.map +0 -1
- package/lib/components/input.js +0 -50
- package/lib/components/input.js.map +0 -1
- package/lib/constructed-response.js +0 -101
- package/lib/constructed-response.js.map +0 -1
- package/lib/customizable.js +0 -42
- package/lib/customizable.js.map +0 -1
- package/lib/drag-in-the-blank.js +0 -363
- package/lib/drag-in-the-blank.js.map +0 -1
- package/lib/index.js +0 -55
- package/lib/index.js.map +0 -1
- package/lib/inline-dropdown.js +0 -40
- package/lib/inline-dropdown.js.map +0 -1
- package/lib/keyboard-coordinates.js +0 -156
- package/lib/keyboard-coordinates.js.map +0 -1
- package/lib/mask.js +0 -203
- package/lib/mask.js.map +0 -1
- package/lib/serialization.js +0 -261
- package/lib/serialization.js.map +0 -1
- package/lib/with-mask.js +0 -97
- package/lib/with-mask.js.map +0 -1
- package/src/__tests__/drag-in-the-blank.test.js +0 -256
- package/src/__tests__/index.test.js +0 -38
- package/src/__tests__/keyboard-coordinates.test.js +0 -202
- package/src/__tests__/mask.test.js +0 -479
- package/src/__tests__/serialization.test.js +0 -54
- package/src/__tests__/utils.js +0 -1
- package/src/__tests__/with-mask.test.js +0 -76
- package/src/choices/__tests__/index.test.js +0 -212
- package/src/choices/choice.jsx +0 -113
- package/src/choices/index.jsx +0 -88
- package/src/componentize.js +0 -13
- package/src/components/__tests__/blank.test.js +0 -413
- package/src/components/__tests__/correct-input.test.js +0 -90
- package/src/components/__tests__/dropdown.test.js +0 -129
- package/src/components/__tests__/input.test.js +0 -102
- package/src/components/blank.jsx +0 -504
- package/src/components/correct-input.jsx +0 -82
- package/src/components/dropdown.jsx +0 -421
- package/src/components/input.jsx +0 -48
- package/src/constructed-response.jsx +0 -87
- package/src/customizable.jsx +0 -34
- package/src/drag-in-the-blank.jsx +0 -351
- package/src/index.js +0 -16
- package/src/inline-dropdown.jsx +0 -29
- package/src/keyboard-coordinates.js +0 -147
- package/src/mask.jsx +0 -174
- package/src/serialization.js +0 -260
- package/src/with-mask.jsx +0 -75
|
@@ -1,479 +0,0 @@
|
|
|
1
|
-
import * as React from 'react';
|
|
2
|
-
import { render, screen } from '@testing-library/react';
|
|
3
|
-
import Mask from '../mask';
|
|
4
|
-
|
|
5
|
-
describe('Mask', () => {
|
|
6
|
-
// Don't mock renderChildren - let the component render naturally
|
|
7
|
-
const onChange = jest.fn();
|
|
8
|
-
const defaultProps = {
|
|
9
|
-
onChange,
|
|
10
|
-
layout: {
|
|
11
|
-
nodes: [
|
|
12
|
-
{
|
|
13
|
-
object: 'text',
|
|
14
|
-
leaves: [
|
|
15
|
-
{
|
|
16
|
-
text: 'Foo',
|
|
17
|
-
},
|
|
18
|
-
],
|
|
19
|
-
},
|
|
20
|
-
],
|
|
21
|
-
},
|
|
22
|
-
value: {},
|
|
23
|
-
};
|
|
24
|
-
|
|
25
|
-
beforeEach(() => {
|
|
26
|
-
onChange.mockClear();
|
|
27
|
-
});
|
|
28
|
-
|
|
29
|
-
describe('rendering', () => {
|
|
30
|
-
it('renders with default props', () => {
|
|
31
|
-
const { container } = render(<Mask {...defaultProps} />);
|
|
32
|
-
expect(container.firstChild).toBeInTheDocument();
|
|
33
|
-
});
|
|
34
|
-
|
|
35
|
-
it('renders text content', () => {
|
|
36
|
-
render(<Mask {...defaultProps} />);
|
|
37
|
-
expect(screen.getByText('Foo')).toBeInTheDocument();
|
|
38
|
-
});
|
|
39
|
-
|
|
40
|
-
it('renders a paragraph element', () => {
|
|
41
|
-
const { container } = render(
|
|
42
|
-
<Mask
|
|
43
|
-
{...defaultProps}
|
|
44
|
-
layout={{
|
|
45
|
-
nodes: [
|
|
46
|
-
{
|
|
47
|
-
type: 'p',
|
|
48
|
-
nodes: [
|
|
49
|
-
{
|
|
50
|
-
object: 'text',
|
|
51
|
-
leaves: [
|
|
52
|
-
{
|
|
53
|
-
text: 'Foo',
|
|
54
|
-
},
|
|
55
|
-
],
|
|
56
|
-
},
|
|
57
|
-
],
|
|
58
|
-
},
|
|
59
|
-
],
|
|
60
|
-
}}
|
|
61
|
-
/>,
|
|
62
|
-
);
|
|
63
|
-
|
|
64
|
-
// Paragraph is rendered as a styled div, not a <p> tag
|
|
65
|
-
expect(screen.getByText('Foo')).toBeInTheDocument();
|
|
66
|
-
});
|
|
67
|
-
|
|
68
|
-
it('renders nested div and paragraph', () => {
|
|
69
|
-
const { container } = render(
|
|
70
|
-
<Mask
|
|
71
|
-
{...defaultProps}
|
|
72
|
-
layout={{
|
|
73
|
-
nodes: [
|
|
74
|
-
{
|
|
75
|
-
type: 'div',
|
|
76
|
-
data: {
|
|
77
|
-
attributes: {},
|
|
78
|
-
},
|
|
79
|
-
nodes: [
|
|
80
|
-
{
|
|
81
|
-
type: 'p',
|
|
82
|
-
data: {
|
|
83
|
-
attributes: {},
|
|
84
|
-
},
|
|
85
|
-
nodes: [
|
|
86
|
-
{
|
|
87
|
-
object: 'text',
|
|
88
|
-
leaves: [
|
|
89
|
-
{
|
|
90
|
-
text: 'Foo',
|
|
91
|
-
},
|
|
92
|
-
],
|
|
93
|
-
},
|
|
94
|
-
],
|
|
95
|
-
},
|
|
96
|
-
],
|
|
97
|
-
},
|
|
98
|
-
],
|
|
99
|
-
}}
|
|
100
|
-
/>,
|
|
101
|
-
);
|
|
102
|
-
|
|
103
|
-
expect(container.querySelector('div')).toBeInTheDocument();
|
|
104
|
-
// Paragraph is rendered as a styled div, not a <p> tag
|
|
105
|
-
expect(screen.getByText('Foo')).toBeInTheDocument();
|
|
106
|
-
});
|
|
107
|
-
|
|
108
|
-
it('renders text with italic marks', () => {
|
|
109
|
-
const { container } = render(
|
|
110
|
-
<Mask
|
|
111
|
-
{...defaultProps}
|
|
112
|
-
layout={{
|
|
113
|
-
nodes: [
|
|
114
|
-
{
|
|
115
|
-
leaves: [{ text: 'Foo ' }],
|
|
116
|
-
object: 'text',
|
|
117
|
-
},
|
|
118
|
-
{
|
|
119
|
-
leaves: [
|
|
120
|
-
{
|
|
121
|
-
marks: [
|
|
122
|
-
{
|
|
123
|
-
data: undefined,
|
|
124
|
-
type: 'italic',
|
|
125
|
-
},
|
|
126
|
-
],
|
|
127
|
-
text: 'x',
|
|
128
|
-
},
|
|
129
|
-
],
|
|
130
|
-
object: 'text',
|
|
131
|
-
},
|
|
132
|
-
{
|
|
133
|
-
leaves: [{ text: ' bar' }],
|
|
134
|
-
object: 'text',
|
|
135
|
-
},
|
|
136
|
-
],
|
|
137
|
-
object: 'block',
|
|
138
|
-
type: 'div',
|
|
139
|
-
}}
|
|
140
|
-
/>,
|
|
141
|
-
);
|
|
142
|
-
|
|
143
|
-
// Text "Foo " is split with spaces, use regex
|
|
144
|
-
expect(screen.getByText(/Foo/)).toBeInTheDocument();
|
|
145
|
-
expect(screen.getByText('x')).toBeInTheDocument();
|
|
146
|
-
expect(screen.getByText(/bar/)).toBeInTheDocument();
|
|
147
|
-
// Check for italic/em element
|
|
148
|
-
const em = container.querySelector('em, i');
|
|
149
|
-
expect(em).toBeInTheDocument();
|
|
150
|
-
expect(em.textContent).toBe('x');
|
|
151
|
-
});
|
|
152
|
-
|
|
153
|
-
it('renders tbody without extra space', () => {
|
|
154
|
-
const da = () => ({ data: { attributes: {} } });
|
|
155
|
-
const { container } = render(
|
|
156
|
-
<Mask
|
|
157
|
-
{...defaultProps}
|
|
158
|
-
layout={{
|
|
159
|
-
nodes: [
|
|
160
|
-
{
|
|
161
|
-
type: 'table',
|
|
162
|
-
...da(),
|
|
163
|
-
nodes: [
|
|
164
|
-
{
|
|
165
|
-
type: 'tbody',
|
|
166
|
-
...da(),
|
|
167
|
-
nodes: [
|
|
168
|
-
{
|
|
169
|
-
object: 'text',
|
|
170
|
-
leaves: [{ text: ' ' }],
|
|
171
|
-
},
|
|
172
|
-
{ type: 'tr', ...da(), nodes: [] },
|
|
173
|
-
],
|
|
174
|
-
},
|
|
175
|
-
],
|
|
176
|
-
},
|
|
177
|
-
],
|
|
178
|
-
}}
|
|
179
|
-
/>,
|
|
180
|
-
);
|
|
181
|
-
|
|
182
|
-
expect(container.querySelector('table')).toBeInTheDocument();
|
|
183
|
-
expect(container.querySelector('tbody')).toBeInTheDocument();
|
|
184
|
-
expect(container.querySelector('tr')).toBeInTheDocument();
|
|
185
|
-
});
|
|
186
|
-
});
|
|
187
|
-
|
|
188
|
-
describe('mark rendering', () => {
|
|
189
|
-
const markedLayout = (marks, text = 'x') => ({
|
|
190
|
-
nodes: [
|
|
191
|
-
{
|
|
192
|
-
object: 'text',
|
|
193
|
-
leaves: [{ marks, text }],
|
|
194
|
-
},
|
|
195
|
-
],
|
|
196
|
-
});
|
|
197
|
-
|
|
198
|
-
it('renders a mark as an element, not as escaped html text', () => {
|
|
199
|
-
const { container } = render(<Mask {...defaultProps} layout={markedLayout([{ type: 'bold' }])} />);
|
|
200
|
-
|
|
201
|
-
const b = container.querySelector('b');
|
|
202
|
-
expect(b).toBeInTheDocument();
|
|
203
|
-
expect(b.textContent).toBe('x');
|
|
204
|
-
// the tag must not leak into the text content
|
|
205
|
-
expect(container.textContent).toBe('x');
|
|
206
|
-
});
|
|
207
|
-
|
|
208
|
-
it.each([
|
|
209
|
-
['bold', 'b'],
|
|
210
|
-
['italic', 'em'],
|
|
211
|
-
['underline', 'u'],
|
|
212
|
-
['strikethrough', 's'],
|
|
213
|
-
['code', 'code'],
|
|
214
|
-
['strong', 'strong'],
|
|
215
|
-
])('maps the %s mark to a <%s> element', (markType, tag) => {
|
|
216
|
-
const { container } = render(<Mask {...defaultProps} layout={markedLayout([{ type: markType }])} />);
|
|
217
|
-
|
|
218
|
-
const el = container.querySelector(tag);
|
|
219
|
-
expect(el).toBeInTheDocument();
|
|
220
|
-
expect(el.textContent).toBe('x');
|
|
221
|
-
});
|
|
222
|
-
|
|
223
|
-
it('nests multiple marks, keeping the first mark as the outermost tag', () => {
|
|
224
|
-
const { container } = render(
|
|
225
|
-
<Mask {...defaultProps} layout={markedLayout([{ type: 'bold' }, { type: 'italic' }])} />,
|
|
226
|
-
);
|
|
227
|
-
|
|
228
|
-
const nested = container.querySelector('b > em');
|
|
229
|
-
expect(nested).toBeInTheDocument();
|
|
230
|
-
expect(nested.textContent).toBe('x');
|
|
231
|
-
expect(container.textContent).toBe('x');
|
|
232
|
-
});
|
|
233
|
-
|
|
234
|
-
it('nests three marks in mark order', () => {
|
|
235
|
-
const { container } = render(
|
|
236
|
-
<Mask
|
|
237
|
-
{...defaultProps}
|
|
238
|
-
layout={markedLayout([{ type: 'underline' }, { type: 'strikethrough' }, { type: 'italic' }])}
|
|
239
|
-
/>,
|
|
240
|
-
);
|
|
241
|
-
|
|
242
|
-
const nested = container.querySelector('u > s > em');
|
|
243
|
-
expect(nested).toBeInTheDocument();
|
|
244
|
-
expect(nested.textContent).toBe('x');
|
|
245
|
-
});
|
|
246
|
-
|
|
247
|
-
it('renders plain text when no mark maps to a tag', () => {
|
|
248
|
-
const { container } = render(<Mask {...defaultProps} layout={markedLayout([{ type: 'unknown-mark' }])} />);
|
|
249
|
-
|
|
250
|
-
expect(container.textContent).toBe('x');
|
|
251
|
-
expect(container.firstChild.childNodes[0].nodeType).toBe(Node.TEXT_NODE);
|
|
252
|
-
});
|
|
253
|
-
|
|
254
|
-
it('wraps only the marks that map to a tag', () => {
|
|
255
|
-
const { container } = render(
|
|
256
|
-
<Mask {...defaultProps} layout={markedLayout([{ type: 'unknown-mark' }, { type: 'bold' }])} />,
|
|
257
|
-
);
|
|
258
|
-
|
|
259
|
-
const b = container.querySelector('b');
|
|
260
|
-
expect(b).toBeInTheDocument();
|
|
261
|
-
expect(b.textContent).toBe('x');
|
|
262
|
-
expect(container.textContent).toBe('x');
|
|
263
|
-
});
|
|
264
|
-
|
|
265
|
-
it('renders marked text inline alongside unmarked text', () => {
|
|
266
|
-
const { container } = render(
|
|
267
|
-
<Mask
|
|
268
|
-
{...defaultProps}
|
|
269
|
-
layout={{
|
|
270
|
-
nodes: [
|
|
271
|
-
{ object: 'text', leaves: [{ text: 'Foo ' }] },
|
|
272
|
-
{ object: 'text', leaves: [{ marks: [{ type: 'bold' }, { type: 'italic' }], text: 'x' }] },
|
|
273
|
-
{ object: 'text', leaves: [{ text: ' bar' }] },
|
|
274
|
-
],
|
|
275
|
-
object: 'block',
|
|
276
|
-
type: 'div',
|
|
277
|
-
}}
|
|
278
|
-
/>,
|
|
279
|
-
);
|
|
280
|
-
|
|
281
|
-
expect(container.querySelector('b > em').textContent).toBe('x');
|
|
282
|
-
expect(container.textContent).toBe('Foo x bar');
|
|
283
|
-
});
|
|
284
|
-
});
|
|
285
|
-
|
|
286
|
-
describe('spacer rendering for DnD components', () => {
|
|
287
|
-
it('adds spacers before and after DnD blank components', () => {
|
|
288
|
-
const mockRenderChildren = jest.fn((n) => {
|
|
289
|
-
if (n.data?.dataset?.component === 'blank') {
|
|
290
|
-
return <span data-testid="blank-component">Blank</span>;
|
|
291
|
-
}
|
|
292
|
-
return null;
|
|
293
|
-
});
|
|
294
|
-
|
|
295
|
-
const { container } = render(
|
|
296
|
-
<Mask
|
|
297
|
-
{...defaultProps}
|
|
298
|
-
renderChildren={mockRenderChildren}
|
|
299
|
-
layout={{
|
|
300
|
-
nodes: [
|
|
301
|
-
{
|
|
302
|
-
type: 'div',
|
|
303
|
-
data: {
|
|
304
|
-
dataset: { component: 'blank' },
|
|
305
|
-
attributes: {},
|
|
306
|
-
},
|
|
307
|
-
nodes: [],
|
|
308
|
-
},
|
|
309
|
-
],
|
|
310
|
-
}}
|
|
311
|
-
/>,
|
|
312
|
-
);
|
|
313
|
-
|
|
314
|
-
// Check that renderChildren was called and spacers are present
|
|
315
|
-
// Count all children in the container - should be: spacer + blank + spacer = 3 elements
|
|
316
|
-
const maskContainer = container.firstChild;
|
|
317
|
-
expect(maskContainer.childNodes.length).toBe(3);
|
|
318
|
-
expect(screen.getByTestId('blank-component')).toBeInTheDocument();
|
|
319
|
-
});
|
|
320
|
-
|
|
321
|
-
it('does not add spacers for non-DnD components', () => {
|
|
322
|
-
const mockRenderChildren = jest.fn((n) => {
|
|
323
|
-
return <span data-testid="regular-component">Regular</span>;
|
|
324
|
-
});
|
|
325
|
-
|
|
326
|
-
const { container } = render(
|
|
327
|
-
<Mask
|
|
328
|
-
{...defaultProps}
|
|
329
|
-
renderChildren={mockRenderChildren}
|
|
330
|
-
layout={{
|
|
331
|
-
nodes: [
|
|
332
|
-
{
|
|
333
|
-
type: 'div',
|
|
334
|
-
data: {
|
|
335
|
-
attributes: {},
|
|
336
|
-
},
|
|
337
|
-
nodes: [],
|
|
338
|
-
},
|
|
339
|
-
],
|
|
340
|
-
}}
|
|
341
|
-
/>,
|
|
342
|
-
);
|
|
343
|
-
|
|
344
|
-
// Should not have spacers - only the regular component
|
|
345
|
-
const maskContainer = container.firstChild;
|
|
346
|
-
expect(maskContainer.childNodes.length).toBe(1);
|
|
347
|
-
expect(screen.getByTestId('regular-component')).toBeInTheDocument();
|
|
348
|
-
});
|
|
349
|
-
|
|
350
|
-
it('adds spacers regardless of parent node type', () => {
|
|
351
|
-
const mockRenderChildren = jest.fn((n) => {
|
|
352
|
-
if (n.data?.dataset?.component === 'blank') {
|
|
353
|
-
return <span data-testid="blank-in-td">Blank in TD</span>;
|
|
354
|
-
}
|
|
355
|
-
return null;
|
|
356
|
-
});
|
|
357
|
-
|
|
358
|
-
const { container } = render(
|
|
359
|
-
<Mask
|
|
360
|
-
{...defaultProps}
|
|
361
|
-
renderChildren={mockRenderChildren}
|
|
362
|
-
elementType="drag-in-the-blank"
|
|
363
|
-
layout={{
|
|
364
|
-
nodes: [
|
|
365
|
-
{
|
|
366
|
-
type: 'table',
|
|
367
|
-
data: { attributes: {} },
|
|
368
|
-
nodes: [
|
|
369
|
-
{
|
|
370
|
-
type: 'tbody',
|
|
371
|
-
data: { attributes: {} },
|
|
372
|
-
nodes: [
|
|
373
|
-
{
|
|
374
|
-
type: 'tr',
|
|
375
|
-
data: { attributes: {} },
|
|
376
|
-
nodes: [
|
|
377
|
-
{
|
|
378
|
-
type: 'td',
|
|
379
|
-
data: { attributes: {} },
|
|
380
|
-
nodes: [
|
|
381
|
-
{
|
|
382
|
-
type: 'div',
|
|
383
|
-
data: {
|
|
384
|
-
dataset: { component: 'blank' },
|
|
385
|
-
attributes: {},
|
|
386
|
-
},
|
|
387
|
-
nodes: [],
|
|
388
|
-
},
|
|
389
|
-
],
|
|
390
|
-
},
|
|
391
|
-
],
|
|
392
|
-
},
|
|
393
|
-
],
|
|
394
|
-
},
|
|
395
|
-
],
|
|
396
|
-
},
|
|
397
|
-
],
|
|
398
|
-
}}
|
|
399
|
-
/>,
|
|
400
|
-
);
|
|
401
|
-
|
|
402
|
-
// Should have spacers even inside td element
|
|
403
|
-
const td = container.querySelector('td');
|
|
404
|
-
expect(td.childNodes.length).toBe(3); // spacer + blank + spacer
|
|
405
|
-
expect(screen.getByTestId('blank-in-td')).toBeInTheDocument();
|
|
406
|
-
});
|
|
407
|
-
|
|
408
|
-
it('does not add spacers for text content', () => {
|
|
409
|
-
const { container } = render(
|
|
410
|
-
<Mask
|
|
411
|
-
{...defaultProps}
|
|
412
|
-
elementType="drag-in-the-blank"
|
|
413
|
-
layout={{
|
|
414
|
-
nodes: [
|
|
415
|
-
{
|
|
416
|
-
object: 'text',
|
|
417
|
-
leaves: [
|
|
418
|
-
{
|
|
419
|
-
text: 'Some text',
|
|
420
|
-
},
|
|
421
|
-
],
|
|
422
|
-
},
|
|
423
|
-
],
|
|
424
|
-
}}
|
|
425
|
-
/>,
|
|
426
|
-
);
|
|
427
|
-
|
|
428
|
-
// Should not have spacers for plain text - just text node
|
|
429
|
-
const maskContainer = container.firstChild;
|
|
430
|
-
expect(maskContainer.childNodes.length).toBe(1);
|
|
431
|
-
expect(maskContainer.childNodes[0].nodeType).toBe(Node.TEXT_NODE);
|
|
432
|
-
expect(screen.getByText('Some text')).toBeInTheDocument();
|
|
433
|
-
});
|
|
434
|
-
|
|
435
|
-
it('handles multiple DnD components with correct spacer placement', () => {
|
|
436
|
-
const mockRenderChildren = jest.fn((n) => {
|
|
437
|
-
if (n.data?.dataset?.component === 'blank') {
|
|
438
|
-
return <span data-testid={`blank-${n.data.testId}`}>Blank</span>;
|
|
439
|
-
}
|
|
440
|
-
return null;
|
|
441
|
-
});
|
|
442
|
-
|
|
443
|
-
const { container } = render(
|
|
444
|
-
<Mask
|
|
445
|
-
{...defaultProps}
|
|
446
|
-
renderChildren={mockRenderChildren}
|
|
447
|
-
layout={{
|
|
448
|
-
nodes: [
|
|
449
|
-
{
|
|
450
|
-
type: 'div',
|
|
451
|
-
data: {
|
|
452
|
-
dataset: { component: 'blank' },
|
|
453
|
-
attributes: {},
|
|
454
|
-
testId: '1',
|
|
455
|
-
},
|
|
456
|
-
nodes: [],
|
|
457
|
-
},
|
|
458
|
-
{
|
|
459
|
-
type: 'div',
|
|
460
|
-
data: {
|
|
461
|
-
dataset: { component: 'blank' },
|
|
462
|
-
attributes: {},
|
|
463
|
-
testId: '2',
|
|
464
|
-
},
|
|
465
|
-
nodes: [],
|
|
466
|
-
},
|
|
467
|
-
],
|
|
468
|
-
}}
|
|
469
|
-
/>,
|
|
470
|
-
);
|
|
471
|
-
|
|
472
|
-
// Should have 2 spacers per component = 4 spacers + 2 blanks = 6 total children
|
|
473
|
-
const maskContainer = container.firstChild;
|
|
474
|
-
expect(maskContainer.childNodes.length).toBe(6);
|
|
475
|
-
expect(screen.getByTestId('blank-1')).toBeInTheDocument();
|
|
476
|
-
expect(screen.getByTestId('blank-2')).toBeInTheDocument();
|
|
477
|
-
});
|
|
478
|
-
});
|
|
479
|
-
});
|
|
@@ -1,54 +0,0 @@
|
|
|
1
|
-
import { deserialize } from '../serialization';
|
|
2
|
-
|
|
3
|
-
describe('serialization', () => {
|
|
4
|
-
it('ignores comments', () => {
|
|
5
|
-
const out = deserialize(`<!-- hi -->`);
|
|
6
|
-
expect(out.document.nodes[0]).toEqual(expect.objectContaining({ type: 'span' }));
|
|
7
|
-
});
|
|
8
|
-
|
|
9
|
-
it('ignores comments', () => {
|
|
10
|
-
const out = deserialize(`<!-- hi --><div>foo</div>`);
|
|
11
|
-
expect(out.document.nodes[0]).toEqual(
|
|
12
|
-
expect.objectContaining({
|
|
13
|
-
type: 'div',
|
|
14
|
-
nodes: [
|
|
15
|
-
expect.objectContaining({
|
|
16
|
-
object: 'text',
|
|
17
|
-
leaves: [{ text: 'foo' }],
|
|
18
|
-
}),
|
|
19
|
-
],
|
|
20
|
-
}),
|
|
21
|
-
);
|
|
22
|
-
});
|
|
23
|
-
|
|
24
|
-
it('deserializes an em', () => {
|
|
25
|
-
const out = deserialize(`<!-- hi --><div> <em>x</em> </div>`);
|
|
26
|
-
expect(out.document.nodes[0]).toEqual(
|
|
27
|
-
expect.objectContaining({
|
|
28
|
-
type: 'div',
|
|
29
|
-
nodes: [
|
|
30
|
-
expect.objectContaining({
|
|
31
|
-
object: 'text',
|
|
32
|
-
}),
|
|
33
|
-
expect.objectContaining({
|
|
34
|
-
leaves: [
|
|
35
|
-
{
|
|
36
|
-
marks: [
|
|
37
|
-
{
|
|
38
|
-
data: undefined,
|
|
39
|
-
type: 'italic',
|
|
40
|
-
},
|
|
41
|
-
],
|
|
42
|
-
text: 'x',
|
|
43
|
-
},
|
|
44
|
-
],
|
|
45
|
-
object: 'text',
|
|
46
|
-
}),
|
|
47
|
-
expect.objectContaining({
|
|
48
|
-
object: 'text',
|
|
49
|
-
}),
|
|
50
|
-
],
|
|
51
|
-
}),
|
|
52
|
-
);
|
|
53
|
-
});
|
|
54
|
-
});
|
package/src/__tests__/utils.js
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export const choice = (v, id) => ({ label: v, value: v, id });
|
|
@@ -1,76 +0,0 @@
|
|
|
1
|
-
import * as React from 'react';
|
|
2
|
-
import { render, screen } from '@testing-library/react';
|
|
3
|
-
import userEvent from '@testing-library/user-event';
|
|
4
|
-
import { withMask } from '../with-mask';
|
|
5
|
-
|
|
6
|
-
describe('WithMask', () => {
|
|
7
|
-
const onChange = jest.fn();
|
|
8
|
-
const defaultProps = {
|
|
9
|
-
markup: '<p>Foo bar {{0}} over the moon;</p>',
|
|
10
|
-
value: {
|
|
11
|
-
0: 'blank',
|
|
12
|
-
},
|
|
13
|
-
onChange,
|
|
14
|
-
};
|
|
15
|
-
|
|
16
|
-
const Masked = withMask('foo', (props) => (node) => {
|
|
17
|
-
const dataset = node.data ? node.data.dataset || {} : {};
|
|
18
|
-
|
|
19
|
-
if (dataset.component === 'foo') {
|
|
20
|
-
return <input type="text" data-testid="masked-input" defaultValue="Foo" onChange={props.onChange} />;
|
|
21
|
-
}
|
|
22
|
-
});
|
|
23
|
-
|
|
24
|
-
beforeEach(() => {
|
|
25
|
-
onChange.mockClear();
|
|
26
|
-
});
|
|
27
|
-
|
|
28
|
-
describe('rendering', () => {
|
|
29
|
-
it('renders with default props', () => {
|
|
30
|
-
const { container } = render(<Masked {...defaultProps} />);
|
|
31
|
-
expect(container.firstChild).toBeInTheDocument();
|
|
32
|
-
});
|
|
33
|
-
|
|
34
|
-
it('renders markup content', () => {
|
|
35
|
-
render(<Masked {...defaultProps} />);
|
|
36
|
-
expect(screen.getByText(/Foo bar/)).toBeInTheDocument();
|
|
37
|
-
});
|
|
38
|
-
|
|
39
|
-
it('renders paragraph content', () => {
|
|
40
|
-
const { container } = render(<Masked {...defaultProps} />);
|
|
41
|
-
// Paragraph is rendered as a styled div, not a <p> tag
|
|
42
|
-
expect(container.firstChild).toBeInTheDocument();
|
|
43
|
-
expect(screen.getByText(/Foo bar/)).toBeInTheDocument();
|
|
44
|
-
});
|
|
45
|
-
});
|
|
46
|
-
|
|
47
|
-
describe('onChange handler', () => {
|
|
48
|
-
it('calls onChange when value changes', async () => {
|
|
49
|
-
const user = userEvent.setup();
|
|
50
|
-
render(<Masked {...defaultProps} />);
|
|
51
|
-
|
|
52
|
-
const input = screen.queryByTestId('masked-input');
|
|
53
|
-
if (input) {
|
|
54
|
-
await user.clear(input);
|
|
55
|
-
await user.type(input, 'ceva');
|
|
56
|
-
|
|
57
|
-
expect(onChange).toHaveBeenCalled();
|
|
58
|
-
}
|
|
59
|
-
});
|
|
60
|
-
|
|
61
|
-
it('passes event to onChange', async () => {
|
|
62
|
-
const user = userEvent.setup();
|
|
63
|
-
render(<Masked {...defaultProps} />);
|
|
64
|
-
|
|
65
|
-
const input = screen.queryByTestId('masked-input');
|
|
66
|
-
if (input) {
|
|
67
|
-
await user.clear(input);
|
|
68
|
-
await user.type(input, 'test');
|
|
69
|
-
|
|
70
|
-
expect(onChange).toHaveBeenCalled();
|
|
71
|
-
const lastCall = onChange.mock.calls[onChange.mock.calls.length - 1][0];
|
|
72
|
-
expect(lastCall).toHaveProperty('target');
|
|
73
|
-
}
|
|
74
|
-
});
|
|
75
|
-
});
|
|
76
|
-
});
|