@dotcms/react 0.0.1-alpha.37 → 0.0.1-alpha.39
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/.babelrc +12 -0
- package/.eslintrc.json +18 -0
- package/jest.config.ts +11 -0
- package/package.json +4 -8
- package/project.json +56 -0
- package/src/lib/components/BlockEditorRenderer/BlockEditorRenderer.spec.tsx +51 -0
- package/src/lib/components/BlockEditorRenderer/{BlockEditorRenderer.d.ts → BlockEditorRenderer.tsx} +16 -2
- package/src/lib/components/BlockEditorRenderer/blocks/{Code.d.ts → Code.tsx} +14 -2
- package/src/lib/components/BlockEditorRenderer/blocks/{Contentlet.d.ts → Contentlet.tsx} +21 -1
- package/src/lib/components/BlockEditorRenderer/blocks/Image.tsx +18 -0
- package/src/lib/components/BlockEditorRenderer/blocks/{Lists.d.ts → Lists.tsx} +12 -3
- package/src/lib/components/BlockEditorRenderer/blocks/Table.tsx +60 -0
- package/src/lib/components/BlockEditorRenderer/blocks/Texts.tsx +126 -0
- package/src/lib/components/BlockEditorRenderer/blocks/Video.tsx +26 -0
- package/src/lib/components/BlockEditorRenderer/item/BlockEditorBlock.spec.tsx +634 -0
- package/src/lib/components/BlockEditorRenderer/item/BlockEditorBlock.tsx +146 -0
- package/src/lib/components/Column/Column.module.css +99 -0
- package/src/lib/components/Column/Column.spec.tsx +78 -0
- package/src/lib/components/Column/Column.tsx +59 -0
- package/src/lib/components/Container/Container.module.css +7 -0
- package/src/lib/components/Container/Container.spec.tsx +155 -0
- package/src/lib/components/Container/Container.tsx +122 -0
- package/src/lib/components/DotEditableText/DotEditableText.spec.tsx +232 -0
- package/src/lib/components/DotEditableText/DotEditableText.tsx +168 -0
- package/src/lib/components/DotEditableText/utils.ts +82 -0
- package/src/lib/components/DotcmsLayout/DotcmsLayout.module.css +7 -0
- package/src/lib/components/DotcmsLayout/DotcmsLayout.spec.tsx +46 -0
- package/src/lib/components/DotcmsLayout/{DotcmsLayout.d.ts → DotcmsLayout.tsx} +18 -2
- package/src/lib/components/PageProvider/PageProvider.module.css +7 -0
- package/src/lib/components/PageProvider/PageProvider.spec.tsx +59 -0
- package/src/lib/components/PageProvider/{PageProvider.d.ts → PageProvider.tsx} +10 -1
- package/src/lib/components/Row/Row.module.css +5 -0
- package/src/lib/components/Row/Row.spec.tsx +92 -0
- package/src/lib/components/Row/Row.tsx +52 -0
- package/src/lib/contexts/PageContext.tsx +10 -0
- package/src/lib/hooks/useDotcmsEditor.spec.ts +176 -0
- package/src/lib/hooks/useDotcmsEditor.ts +94 -0
- package/src/lib/hooks/useDotcmsPageContext.spec.tsx +47 -0
- package/src/lib/hooks/{useDotcmsPageContext.d.ts → useDotcmsPageContext.tsx} +7 -1
- package/src/lib/mocks/mockPageContext.tsx +113 -0
- package/src/lib/models/{blocks.interface.d.ts → blocks.interface.ts} +43 -16
- package/src/lib/models/content-node.interface.ts +90 -0
- package/src/lib/models/{index.d.ts → index.ts} +5 -2
- package/src/lib/utils/utils.ts +89 -0
- package/tsconfig.json +20 -0
- package/tsconfig.lib.json +23 -0
- package/tsconfig.spec.json +20 -0
- package/index.esm.d.ts +0 -1
- package/index.esm.js +0 -5070
- package/src/lib/components/BlockEditorRenderer/blocks/Image.d.ts +0 -8
- package/src/lib/components/BlockEditorRenderer/blocks/Table.d.ts +0 -16
- package/src/lib/components/BlockEditorRenderer/blocks/Texts.d.ts +0 -71
- package/src/lib/components/BlockEditorRenderer/blocks/Video.d.ts +0 -8
- package/src/lib/components/BlockEditorRenderer/item/BlockEditorBlock.d.ts +0 -12
- package/src/lib/components/Column/Column.d.ts +0 -5
- package/src/lib/components/Container/Container.d.ts +0 -5
- package/src/lib/components/DotEditableText/DotEditableText.d.ts +0 -3
- package/src/lib/components/DotEditableText/utils.d.ts +0 -36
- package/src/lib/components/Row/Row.d.ts +0 -25
- package/src/lib/contexts/PageContext.d.ts +0 -3
- package/src/lib/hooks/useDotcmsEditor.d.ts +0 -3
- package/src/lib/mocks/mockPageContext.d.ts +0 -8
- package/src/lib/models/content-node.interface.d.ts +0 -29
- package/src/lib/utils/utils.d.ts +0 -23
- /package/src/{index.d.ts → index.ts} +0 -0
- /package/src/lib/mocks/{index.d.ts → index.ts} +0 -0
|
@@ -0,0 +1,634 @@
|
|
|
1
|
+
import '@testing-library/jest-dom';
|
|
2
|
+
import { render } from '@testing-library/react';
|
|
3
|
+
|
|
4
|
+
import { DotCmsClient } from '@dotcms/client';
|
|
5
|
+
|
|
6
|
+
import { BlockEditorBlock } from './BlockEditorBlock';
|
|
7
|
+
|
|
8
|
+
import { ContentNode } from '../../../models/content-node.interface';
|
|
9
|
+
|
|
10
|
+
const BLOCKS_MOCKS = {
|
|
11
|
+
PARAGRAPH: [
|
|
12
|
+
{
|
|
13
|
+
type: 'paragraph',
|
|
14
|
+
attrs: {},
|
|
15
|
+
content: [
|
|
16
|
+
{
|
|
17
|
+
type: 'text',
|
|
18
|
+
text: 'Hello, World!'
|
|
19
|
+
}
|
|
20
|
+
]
|
|
21
|
+
},
|
|
22
|
+
{
|
|
23
|
+
type: 'heading',
|
|
24
|
+
attrs: { level: '4' },
|
|
25
|
+
content: [
|
|
26
|
+
{
|
|
27
|
+
type: 'text',
|
|
28
|
+
text: 'Heading!!'
|
|
29
|
+
}
|
|
30
|
+
]
|
|
31
|
+
}
|
|
32
|
+
],
|
|
33
|
+
LINK: [
|
|
34
|
+
{
|
|
35
|
+
type: 'paragraph',
|
|
36
|
+
content: [
|
|
37
|
+
{
|
|
38
|
+
type: 'text',
|
|
39
|
+
text: 'Link text',
|
|
40
|
+
marks: [
|
|
41
|
+
{
|
|
42
|
+
type: 'link',
|
|
43
|
+
attrs: {
|
|
44
|
+
href: 'https://dotcms.com'
|
|
45
|
+
}
|
|
46
|
+
}
|
|
47
|
+
]
|
|
48
|
+
}
|
|
49
|
+
]
|
|
50
|
+
}
|
|
51
|
+
],
|
|
52
|
+
BOLD: [
|
|
53
|
+
{
|
|
54
|
+
type: 'paragraph',
|
|
55
|
+
content: [
|
|
56
|
+
{
|
|
57
|
+
type: 'text',
|
|
58
|
+
text: 'Bold text',
|
|
59
|
+
marks: [
|
|
60
|
+
{
|
|
61
|
+
type: 'bold',
|
|
62
|
+
attrs: {}
|
|
63
|
+
}
|
|
64
|
+
]
|
|
65
|
+
}
|
|
66
|
+
]
|
|
67
|
+
}
|
|
68
|
+
],
|
|
69
|
+
ITALIC: [
|
|
70
|
+
{
|
|
71
|
+
type: 'paragraph',
|
|
72
|
+
content: [
|
|
73
|
+
{
|
|
74
|
+
type: 'text',
|
|
75
|
+
text: 'Italic text',
|
|
76
|
+
marks: [
|
|
77
|
+
{
|
|
78
|
+
type: 'italic',
|
|
79
|
+
attrs: {}
|
|
80
|
+
}
|
|
81
|
+
]
|
|
82
|
+
}
|
|
83
|
+
]
|
|
84
|
+
}
|
|
85
|
+
],
|
|
86
|
+
STRIKE: [
|
|
87
|
+
{
|
|
88
|
+
type: 'paragraph',
|
|
89
|
+
content: [
|
|
90
|
+
{
|
|
91
|
+
type: 'text',
|
|
92
|
+
text: 'Strike text',
|
|
93
|
+
marks: [
|
|
94
|
+
{
|
|
95
|
+
type: 'strike',
|
|
96
|
+
attrs: {}
|
|
97
|
+
}
|
|
98
|
+
]
|
|
99
|
+
}
|
|
100
|
+
]
|
|
101
|
+
}
|
|
102
|
+
],
|
|
103
|
+
UNDERLINE: [
|
|
104
|
+
{
|
|
105
|
+
type: 'paragraph',
|
|
106
|
+
content: [
|
|
107
|
+
{
|
|
108
|
+
type: 'text',
|
|
109
|
+
text: 'Underline text',
|
|
110
|
+
marks: [
|
|
111
|
+
{
|
|
112
|
+
type: 'underline',
|
|
113
|
+
attrs: {}
|
|
114
|
+
}
|
|
115
|
+
]
|
|
116
|
+
}
|
|
117
|
+
]
|
|
118
|
+
}
|
|
119
|
+
],
|
|
120
|
+
SUPSCRIPT: [
|
|
121
|
+
{
|
|
122
|
+
type: 'paragraph',
|
|
123
|
+
content: [
|
|
124
|
+
{
|
|
125
|
+
type: 'text',
|
|
126
|
+
text: 'Superscript text',
|
|
127
|
+
marks: [
|
|
128
|
+
{
|
|
129
|
+
type: 'superscript',
|
|
130
|
+
attrs: {}
|
|
131
|
+
}
|
|
132
|
+
]
|
|
133
|
+
}
|
|
134
|
+
]
|
|
135
|
+
}
|
|
136
|
+
],
|
|
137
|
+
SUBSCRIPT: [
|
|
138
|
+
{
|
|
139
|
+
type: 'paragraph',
|
|
140
|
+
content: [
|
|
141
|
+
{
|
|
142
|
+
type: 'text',
|
|
143
|
+
text: 'Subscript text',
|
|
144
|
+
marks: [
|
|
145
|
+
{
|
|
146
|
+
type: 'subscript',
|
|
147
|
+
attrs: {}
|
|
148
|
+
}
|
|
149
|
+
]
|
|
150
|
+
}
|
|
151
|
+
]
|
|
152
|
+
}
|
|
153
|
+
],
|
|
154
|
+
LIST: [
|
|
155
|
+
{
|
|
156
|
+
type: 'listItem',
|
|
157
|
+
content: [
|
|
158
|
+
{
|
|
159
|
+
type: 'text',
|
|
160
|
+
text: 'Item 1'
|
|
161
|
+
}
|
|
162
|
+
]
|
|
163
|
+
}
|
|
164
|
+
],
|
|
165
|
+
BULLET_LIST: [
|
|
166
|
+
{
|
|
167
|
+
type: 'bulletList',
|
|
168
|
+
content: [
|
|
169
|
+
{
|
|
170
|
+
type: 'listItem',
|
|
171
|
+
content: [
|
|
172
|
+
{
|
|
173
|
+
type: 'text',
|
|
174
|
+
text: 'Item 1'
|
|
175
|
+
}
|
|
176
|
+
]
|
|
177
|
+
},
|
|
178
|
+
{
|
|
179
|
+
type: 'listItem',
|
|
180
|
+
content: [
|
|
181
|
+
{
|
|
182
|
+
type: 'text',
|
|
183
|
+
text: 'Item 2'
|
|
184
|
+
}
|
|
185
|
+
]
|
|
186
|
+
}
|
|
187
|
+
]
|
|
188
|
+
}
|
|
189
|
+
],
|
|
190
|
+
ORDERED_LIST: [
|
|
191
|
+
{
|
|
192
|
+
type: 'orderedList',
|
|
193
|
+
content: [
|
|
194
|
+
{
|
|
195
|
+
type: 'listItem',
|
|
196
|
+
content: [
|
|
197
|
+
{
|
|
198
|
+
type: 'text',
|
|
199
|
+
text: 'Item 1'
|
|
200
|
+
}
|
|
201
|
+
]
|
|
202
|
+
},
|
|
203
|
+
{
|
|
204
|
+
type: 'listItem',
|
|
205
|
+
content: [
|
|
206
|
+
{
|
|
207
|
+
type: 'text',
|
|
208
|
+
text: 'Item 2'
|
|
209
|
+
}
|
|
210
|
+
]
|
|
211
|
+
}
|
|
212
|
+
]
|
|
213
|
+
}
|
|
214
|
+
],
|
|
215
|
+
BLOCKQUOTE: [
|
|
216
|
+
{
|
|
217
|
+
type: 'blockquote',
|
|
218
|
+
content: [
|
|
219
|
+
{
|
|
220
|
+
type: 'paragraph',
|
|
221
|
+
content: [
|
|
222
|
+
{
|
|
223
|
+
type: 'text',
|
|
224
|
+
text: 'Blockquote text'
|
|
225
|
+
}
|
|
226
|
+
]
|
|
227
|
+
}
|
|
228
|
+
]
|
|
229
|
+
}
|
|
230
|
+
],
|
|
231
|
+
CODE_BLOCK: [
|
|
232
|
+
{
|
|
233
|
+
type: 'codeBlock',
|
|
234
|
+
attrs: {
|
|
235
|
+
language: 'javascript'
|
|
236
|
+
},
|
|
237
|
+
content: [
|
|
238
|
+
{
|
|
239
|
+
type: 'text',
|
|
240
|
+
text: 'console.log("Hello, World!")'
|
|
241
|
+
}
|
|
242
|
+
]
|
|
243
|
+
}
|
|
244
|
+
],
|
|
245
|
+
HARDBREAK: [
|
|
246
|
+
{
|
|
247
|
+
type: 'hardBreak',
|
|
248
|
+
content: []
|
|
249
|
+
}
|
|
250
|
+
],
|
|
251
|
+
HORIZONTAL_RULE: [
|
|
252
|
+
{
|
|
253
|
+
type: 'horizontalRule',
|
|
254
|
+
content: []
|
|
255
|
+
}
|
|
256
|
+
],
|
|
257
|
+
DOT_IMAGE: [
|
|
258
|
+
{
|
|
259
|
+
type: 'dotImage',
|
|
260
|
+
attrs: {
|
|
261
|
+
src: '/image.jpg',
|
|
262
|
+
data: {
|
|
263
|
+
title: 'Image title',
|
|
264
|
+
baseType: 'Image',
|
|
265
|
+
inode: '1234',
|
|
266
|
+
archived: false,
|
|
267
|
+
working: true,
|
|
268
|
+
locked: false,
|
|
269
|
+
contentType: 'Image',
|
|
270
|
+
live: true,
|
|
271
|
+
identifier: 'image-identifier',
|
|
272
|
+
image: 'image.jpg',
|
|
273
|
+
imageContentAsset: 'image-content-asset',
|
|
274
|
+
urlTitle: 'image-url-title',
|
|
275
|
+
url: 'image-url',
|
|
276
|
+
titleImage: 'title-image',
|
|
277
|
+
urlMap: 'image-url-map',
|
|
278
|
+
hasLiveVersion: true,
|
|
279
|
+
hasTitleImage: true,
|
|
280
|
+
sortOrder: 1,
|
|
281
|
+
modUser: 'admin',
|
|
282
|
+
__icon__: 'image-icon',
|
|
283
|
+
contentTypeIcon: 'image-content-type-icon'
|
|
284
|
+
}
|
|
285
|
+
}
|
|
286
|
+
}
|
|
287
|
+
],
|
|
288
|
+
DOT_IMAGE_EXTERNAL: [
|
|
289
|
+
{
|
|
290
|
+
type: 'dotImage',
|
|
291
|
+
attrs: {
|
|
292
|
+
src: 'https://external.com/image.jpg',
|
|
293
|
+
data: {}
|
|
294
|
+
}
|
|
295
|
+
}
|
|
296
|
+
],
|
|
297
|
+
DOT_VIDEO: [
|
|
298
|
+
{
|
|
299
|
+
type: 'dotVideo',
|
|
300
|
+
attrs: {
|
|
301
|
+
src: '/video.mp4',
|
|
302
|
+
width: '640',
|
|
303
|
+
height: '360',
|
|
304
|
+
mimeType: 'video/mp4',
|
|
305
|
+
data: {
|
|
306
|
+
title: 'Video title',
|
|
307
|
+
baseType: 'Video',
|
|
308
|
+
inode: '1234',
|
|
309
|
+
archived: false,
|
|
310
|
+
working: true,
|
|
311
|
+
locked: false,
|
|
312
|
+
contentType: 'Video',
|
|
313
|
+
live: true,
|
|
314
|
+
identifier: 'video-identifier',
|
|
315
|
+
image: 'video.jpg',
|
|
316
|
+
imageContentAsset: 'video-content-asset',
|
|
317
|
+
urlTitle: 'video-url-title',
|
|
318
|
+
url: 'video-url',
|
|
319
|
+
titleImage: 'title-image',
|
|
320
|
+
urlMap: 'video-url-map',
|
|
321
|
+
hasLiveVersion: true,
|
|
322
|
+
hasTitleImage: true,
|
|
323
|
+
sortOrder: 1,
|
|
324
|
+
modUser: 'admin',
|
|
325
|
+
__icon__: 'video-icon',
|
|
326
|
+
contentTypeIcon: 'video-content-type-icon',
|
|
327
|
+
thumbnail: '/thumbnail.jpg'
|
|
328
|
+
}
|
|
329
|
+
}
|
|
330
|
+
}
|
|
331
|
+
],
|
|
332
|
+
TABLE: [
|
|
333
|
+
{
|
|
334
|
+
type: 'table',
|
|
335
|
+
content: [
|
|
336
|
+
{
|
|
337
|
+
type: 'tableRow',
|
|
338
|
+
content: [
|
|
339
|
+
{
|
|
340
|
+
type: 'tableHeader',
|
|
341
|
+
content: [
|
|
342
|
+
[
|
|
343
|
+
{
|
|
344
|
+
type: 'paragraph',
|
|
345
|
+
attrs: {
|
|
346
|
+
textAlign: 'left'
|
|
347
|
+
},
|
|
348
|
+
content: [
|
|
349
|
+
{
|
|
350
|
+
type: 'text',
|
|
351
|
+
text: 'Header 1'
|
|
352
|
+
}
|
|
353
|
+
]
|
|
354
|
+
}
|
|
355
|
+
]
|
|
356
|
+
]
|
|
357
|
+
},
|
|
358
|
+
{
|
|
359
|
+
type: 'tableHeader',
|
|
360
|
+
content: [
|
|
361
|
+
[
|
|
362
|
+
{
|
|
363
|
+
type: 'paragraph',
|
|
364
|
+
attrs: {
|
|
365
|
+
textAlign: 'left'
|
|
366
|
+
},
|
|
367
|
+
content: [
|
|
368
|
+
{
|
|
369
|
+
type: 'text',
|
|
370
|
+
text: 'Header 1'
|
|
371
|
+
}
|
|
372
|
+
]
|
|
373
|
+
}
|
|
374
|
+
]
|
|
375
|
+
]
|
|
376
|
+
}
|
|
377
|
+
]
|
|
378
|
+
},
|
|
379
|
+
{
|
|
380
|
+
type: 'tableRow',
|
|
381
|
+
content: [
|
|
382
|
+
{
|
|
383
|
+
type: 'tableCell',
|
|
384
|
+
attrs: {
|
|
385
|
+
colspan: 1,
|
|
386
|
+
rowspan: 1,
|
|
387
|
+
colwidth: null
|
|
388
|
+
},
|
|
389
|
+
content: [
|
|
390
|
+
{
|
|
391
|
+
type: 'paragraph',
|
|
392
|
+
attrs: {
|
|
393
|
+
textAlign: 'left'
|
|
394
|
+
},
|
|
395
|
+
content: [
|
|
396
|
+
{
|
|
397
|
+
type: 'text',
|
|
398
|
+
text: 'Content 1'
|
|
399
|
+
}
|
|
400
|
+
]
|
|
401
|
+
}
|
|
402
|
+
]
|
|
403
|
+
},
|
|
404
|
+
{
|
|
405
|
+
type: 'tableCell',
|
|
406
|
+
attrs: {
|
|
407
|
+
colspan: 1,
|
|
408
|
+
rowspan: 1,
|
|
409
|
+
colwidth: null
|
|
410
|
+
},
|
|
411
|
+
content: [
|
|
412
|
+
{
|
|
413
|
+
type: 'paragraph',
|
|
414
|
+
attrs: {
|
|
415
|
+
textAlign: 'left'
|
|
416
|
+
},
|
|
417
|
+
content: [
|
|
418
|
+
{
|
|
419
|
+
type: 'text',
|
|
420
|
+
text: 'Content 2'
|
|
421
|
+
}
|
|
422
|
+
]
|
|
423
|
+
}
|
|
424
|
+
]
|
|
425
|
+
}
|
|
426
|
+
]
|
|
427
|
+
}
|
|
428
|
+
]
|
|
429
|
+
}
|
|
430
|
+
],
|
|
431
|
+
DOT_CONTENT: [
|
|
432
|
+
{
|
|
433
|
+
type: 'dotContent',
|
|
434
|
+
attrs: {
|
|
435
|
+
identifier: '1234',
|
|
436
|
+
title: 'My activity'
|
|
437
|
+
}
|
|
438
|
+
}
|
|
439
|
+
]
|
|
440
|
+
} as unknown as { [key: string]: ContentNode[] };
|
|
441
|
+
|
|
442
|
+
describe('BlockEditorItem', () => {
|
|
443
|
+
it('should render the paragraph block', () => {
|
|
444
|
+
const { getByText } = render(<BlockEditorBlock content={BLOCKS_MOCKS.PARAGRAPH} />);
|
|
445
|
+
expect(getByText('Hello, World!')).toBeInTheDocument();
|
|
446
|
+
});
|
|
447
|
+
|
|
448
|
+
it('should render the heading block', () => {
|
|
449
|
+
const { container } = render(<BlockEditorBlock content={BLOCKS_MOCKS.PARAGRAPH} />);
|
|
450
|
+
const heading = container.querySelector('h4');
|
|
451
|
+
expect(heading).toBeInTheDocument();
|
|
452
|
+
});
|
|
453
|
+
|
|
454
|
+
describe('should render the text block', () => {
|
|
455
|
+
it('should render the text block', () => {
|
|
456
|
+
const { getByText } = render(<BlockEditorBlock content={BLOCKS_MOCKS.PARAGRAPH} />);
|
|
457
|
+
expect(getByText('Hello, World!')).toBeInTheDocument();
|
|
458
|
+
});
|
|
459
|
+
|
|
460
|
+
it('should render a link', () => {
|
|
461
|
+
const { container } = render(<BlockEditorBlock content={BLOCKS_MOCKS.LINK} />);
|
|
462
|
+
const link = container.querySelector('a');
|
|
463
|
+
expect(link).toBeInTheDocument();
|
|
464
|
+
expect(link).toHaveTextContent('Link text');
|
|
465
|
+
expect(link).toHaveAttribute('href', 'https://dotcms.com');
|
|
466
|
+
});
|
|
467
|
+
|
|
468
|
+
it('should render a bold text', () => {
|
|
469
|
+
const { container } = render(<BlockEditorBlock content={BLOCKS_MOCKS.BOLD} />);
|
|
470
|
+
const bold = container.querySelector('strong');
|
|
471
|
+
expect(bold).toBeInTheDocument();
|
|
472
|
+
expect(bold).toHaveTextContent('Bold text');
|
|
473
|
+
});
|
|
474
|
+
|
|
475
|
+
it('should render an italic text', () => {
|
|
476
|
+
const { container } = render(<BlockEditorBlock content={BLOCKS_MOCKS.ITALIC} />);
|
|
477
|
+
const italic = container.querySelector('em');
|
|
478
|
+
expect(italic).toBeInTheDocument();
|
|
479
|
+
expect(italic).toHaveTextContent('Italic text');
|
|
480
|
+
});
|
|
481
|
+
|
|
482
|
+
it('should render a strike text', () => {
|
|
483
|
+
const { container } = render(<BlockEditorBlock content={BLOCKS_MOCKS.STRIKE} />);
|
|
484
|
+
const strike = container.querySelector('s');
|
|
485
|
+
expect(strike).toBeInTheDocument();
|
|
486
|
+
expect(strike).toHaveTextContent('Strike text');
|
|
487
|
+
});
|
|
488
|
+
|
|
489
|
+
it('should render an underline text', () => {
|
|
490
|
+
const { container } = render(<BlockEditorBlock content={BLOCKS_MOCKS.UNDERLINE} />);
|
|
491
|
+
const underline = container.querySelector('u');
|
|
492
|
+
expect(underline).toBeInTheDocument();
|
|
493
|
+
expect(underline).toHaveTextContent('Underline text');
|
|
494
|
+
});
|
|
495
|
+
|
|
496
|
+
it('should render a supscript text', () => {
|
|
497
|
+
const { container } = render(<BlockEditorBlock content={BLOCKS_MOCKS.SUPSCRIPT} />);
|
|
498
|
+
const superscript = container.querySelector('sup');
|
|
499
|
+
expect(superscript).toBeInTheDocument();
|
|
500
|
+
expect(superscript).toHaveTextContent('Superscript text');
|
|
501
|
+
});
|
|
502
|
+
|
|
503
|
+
it('should render a subscript text', () => {
|
|
504
|
+
const { container } = render(<BlockEditorBlock content={BLOCKS_MOCKS.SUBSCRIPT} />);
|
|
505
|
+
const subscript = container.querySelector('sub');
|
|
506
|
+
expect(subscript).toBeInTheDocument();
|
|
507
|
+
expect(subscript).toHaveTextContent('Subscript text');
|
|
508
|
+
});
|
|
509
|
+
});
|
|
510
|
+
|
|
511
|
+
describe('Lists', () => {
|
|
512
|
+
const { container } = render(<BlockEditorBlock content={BLOCKS_MOCKS.LIST} />);
|
|
513
|
+
const listItem = container.querySelector('li');
|
|
514
|
+
expect(listItem).toBeInTheDocument();
|
|
515
|
+
expect(listItem).toHaveTextContent('Item 1');
|
|
516
|
+
});
|
|
517
|
+
|
|
518
|
+
it('should render a bullet list', () => {
|
|
519
|
+
const { container } = render(<BlockEditorBlock content={BLOCKS_MOCKS.BULLET_LIST} />);
|
|
520
|
+
const list = container.querySelector('ul');
|
|
521
|
+
expect(list).toBeInTheDocument();
|
|
522
|
+
expect(list).toHaveTextContent('Item 1');
|
|
523
|
+
expect(list).toHaveTextContent('Item 2');
|
|
524
|
+
});
|
|
525
|
+
|
|
526
|
+
it('should render an ordered list', () => {
|
|
527
|
+
const { container } = render(<BlockEditorBlock content={BLOCKS_MOCKS.ORDERED_LIST} />);
|
|
528
|
+
const list = container.querySelector('ol');
|
|
529
|
+
expect(list).toBeInTheDocument();
|
|
530
|
+
expect(list).toHaveTextContent('Item 1');
|
|
531
|
+
expect(list).toHaveTextContent('Item 2');
|
|
532
|
+
});
|
|
533
|
+
});
|
|
534
|
+
|
|
535
|
+
it('should render a blockquote', () => {
|
|
536
|
+
const { container } = render(<BlockEditorBlock content={BLOCKS_MOCKS.BLOCKQUOTE} />);
|
|
537
|
+
const blockquote = container.querySelector('blockquote');
|
|
538
|
+
expect(blockquote).toBeInTheDocument();
|
|
539
|
+
expect(blockquote).toHaveTextContent('Blockquote text');
|
|
540
|
+
});
|
|
541
|
+
|
|
542
|
+
it('should render a code block', () => {
|
|
543
|
+
const { container } = render(<BlockEditorBlock content={BLOCKS_MOCKS.CODE_BLOCK} />);
|
|
544
|
+
const codeBlock = container.querySelector('pre');
|
|
545
|
+
expect(codeBlock).toBeInTheDocument();
|
|
546
|
+
expect(codeBlock).toHaveAttribute('data-language', 'javascript');
|
|
547
|
+
expect(codeBlock).toHaveTextContent('console.log("Hello, World!")');
|
|
548
|
+
});
|
|
549
|
+
|
|
550
|
+
describe('Separators', () => {
|
|
551
|
+
it('should render a horizontal rule', () => {
|
|
552
|
+
const { container } = render(<BlockEditorBlock content={BLOCKS_MOCKS.HORIZONTAL_RULE} />);
|
|
553
|
+
const hr = container.querySelector('hr');
|
|
554
|
+
expect(hr).toBeInTheDocument();
|
|
555
|
+
});
|
|
556
|
+
|
|
557
|
+
it('should render a hard break', () => {
|
|
558
|
+
const { container } = render(<BlockEditorBlock content={BLOCKS_MOCKS.HARDBREAK} />);
|
|
559
|
+
const br = container.querySelector('br');
|
|
560
|
+
expect(br).toBeInTheDocument();
|
|
561
|
+
});
|
|
562
|
+
});
|
|
563
|
+
|
|
564
|
+
describe('Assets', () => {
|
|
565
|
+
it('should render a dotImage using internal src', () => {
|
|
566
|
+
// Mock DotCmsClient
|
|
567
|
+
DotCmsClient.instance = {
|
|
568
|
+
dotcmsUrl: 'https://some.dotcms.com'
|
|
569
|
+
} as unknown as DotCmsClient;
|
|
570
|
+
|
|
571
|
+
const { container } = render(<BlockEditorBlock content={BLOCKS_MOCKS.DOT_IMAGE} />);
|
|
572
|
+
const image = container.querySelector('img');
|
|
573
|
+
expect(image).toBeInTheDocument();
|
|
574
|
+
expect(image).toHaveAttribute('src', 'https://some.dotcms.com/image.jpg');
|
|
575
|
+
});
|
|
576
|
+
|
|
577
|
+
it('should render a dotImage using external src', () => {
|
|
578
|
+
// Mock DotCmsClient
|
|
579
|
+
DotCmsClient.instance = {
|
|
580
|
+
dotcmsUrl: 'https://some.dotcms.com'
|
|
581
|
+
} as unknown as DotCmsClient;
|
|
582
|
+
|
|
583
|
+
const { container } = render(
|
|
584
|
+
<BlockEditorBlock content={BLOCKS_MOCKS.DOT_IMAGE_EXTERNAL} />
|
|
585
|
+
);
|
|
586
|
+
const image = container.querySelector('img');
|
|
587
|
+
expect(image).toBeInTheDocument();
|
|
588
|
+
expect(image).toHaveAttribute('src', 'https://external.com/image.jpg');
|
|
589
|
+
});
|
|
590
|
+
|
|
591
|
+
it('should render a dotVideo', () => {
|
|
592
|
+
// Mock DotCmsClient
|
|
593
|
+
DotCmsClient.instance = {
|
|
594
|
+
dotcmsUrl: 'https://some.dotcms.com'
|
|
595
|
+
} as unknown as DotCmsClient;
|
|
596
|
+
|
|
597
|
+
const { container } = render(<BlockEditorBlock content={BLOCKS_MOCKS.DOT_VIDEO} />);
|
|
598
|
+
const video = container.querySelector('video');
|
|
599
|
+
expect(video).toBeInTheDocument();
|
|
600
|
+
expect(video).toHaveAttribute('width', '640');
|
|
601
|
+
expect(video).toHaveAttribute('height', '360');
|
|
602
|
+
expect(video).toHaveAttribute('poster', 'https://some.dotcms.com/thumbnail.jpg');
|
|
603
|
+
|
|
604
|
+
const source = video?.querySelector('source');
|
|
605
|
+
expect(source).toHaveAttribute('src', 'https://some.dotcms.com/video.mp4');
|
|
606
|
+
expect(source).toHaveAttribute('type', 'video/mp4');
|
|
607
|
+
});
|
|
608
|
+
});
|
|
609
|
+
|
|
610
|
+
it('should render a table', () => {
|
|
611
|
+
const { container } = render(<BlockEditorBlock content={BLOCKS_MOCKS.TABLE} />);
|
|
612
|
+
const table = container.querySelector('table');
|
|
613
|
+
expect(table).toBeInTheDocument();
|
|
614
|
+
|
|
615
|
+
const rows = table?.querySelectorAll('tr');
|
|
616
|
+
expect(rows).toHaveLength(2);
|
|
617
|
+
|
|
618
|
+
const cells = rows?.[1].querySelectorAll('td');
|
|
619
|
+
expect(cells).toHaveLength(2);
|
|
620
|
+
expect(cells?.[0]).toHaveTextContent('Content 1');
|
|
621
|
+
});
|
|
622
|
+
|
|
623
|
+
it('should render a dotContent from customRenderers', () => {
|
|
624
|
+
const customRenderers = {
|
|
625
|
+
dotContent: (props: ContentNode) => {
|
|
626
|
+
return <div data-testid="custom-dot-content">{props.attrs?.title}</div>;
|
|
627
|
+
}
|
|
628
|
+
};
|
|
629
|
+
|
|
630
|
+
const { getByTestId } = render(
|
|
631
|
+
<BlockEditorBlock content={BLOCKS_MOCKS.DOT_CONTENT} customRenderers={customRenderers} />
|
|
632
|
+
);
|
|
633
|
+
expect(getByTestId('custom-dot-content')).toHaveTextContent('My activity');
|
|
634
|
+
});
|