-
Notifications
You must be signed in to change notification settings - Fork 5
Expand file tree
/
Copy pathcollab.test.js
More file actions
607 lines (570 loc) · 29.9 KB
/
collab.test.js
File metadata and controls
607 lines (570 loc) · 29.9 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
/*
* Copyright 2024 Adobe. All rights reserved.
* This file is licensed to you under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License. You may obtain a copy
* of the License at http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software distributed under
* the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR REPRESENTATIONS
* OF ANY KIND, either express or implied. See the License for the specific language
* governing permissions and limitations under the License.
*/
import assert from 'assert';
import * as Y from 'yjs';
import { readFileSync } from 'fs';
import { aem2doc, doc2aem, tableToBlock, EMPTY_DOC } from '../src/collab.js';
const collapseTagWhitespace = (str) => str.replace(/>\s+</g, '><');
const collapseWhitespace = (str) => collapseTagWhitespace(str.replace(/\s+/g, ' ')).trim();
describe('Parsing test suite', () => {
it('table data-id support', async () => {
let html = `
<body>
<header></header>
<main>
<div>
<div class="hello" data-id="96789">
<div>
<div><p>Row 1 - Column 1</p></div>
<div><p>Row 1 - Column 2</p></div>
</div>
</div>
</div>
</main>
<footer></footer>
</body>
`;
html = collapseWhitespace(html);
const yDoc = new Y.Doc();
aem2doc(html, yDoc);
const result = doc2aem(yDoc);
assert.equal(collapseWhitespace(result), html);
});
it('DIV block respects colspan', async () => {
let html = `
<body>
<header></header>
<main>
<div>
<div class="hello">
<div>
<div><p>Row 1 - Column 1</p></div>
<div><p>Row 1 - Column 2</p></div>
</div>
</div>
</div>
</main>
<footer></footer>
</body>
`;
html = collapseWhitespace(html);
const yDoc = new Y.Doc();
aem2doc(html, yDoc);
const result = doc2aem(yDoc);
assert.equal(collapseWhitespace(result), html);
});
it('Text parsing produces error', async () => {
const html = `
<body>
<header></header>
<main><div><p>I'll start again</p><ul><li><p>And here some more text</p><ol><li>And some more</li></ol></li></ul></div></main>
<footer></footer>
</body>
`;
const yDoc = new Y.Doc();
aem2doc(html, yDoc);
const result = doc2aem(yDoc);
console.log(result);
assert.equal(result, html);
})
it('Comments are not an issue', async () => {
const html = `
<body>
<header></header>
<!-- Comment before main --><main><!-- Comment before div --><div><!-- Comment before h1 --><h1>test title</h1><!-- Comment after h1 --></div><!-- Comment after div --></main><!-- Comment after main -->
<footer></footer>
</body>
`;
const expectedResult = `
<body>
<header></header>
<main><div><h1>test title</h1></div></main>
<footer></footer>
</body>
`;
const yDoc = new Y.Doc();
aem2doc(html, yDoc);
const result = doc2aem(yDoc);
assert.equal(result, expectedResult);
});
it('Test linked image', async () => {
const html = `
<body>
<header></header>
<main><div><img src="http://www.foo.com/myimg.jpg" href="https://i.am.link" title="Img Title" data-id="myImgId"></a></div></main>
<footer></footer>
</body>
`;
const expectedResult = `
<body>
<header></header>
<main><div><a href="https://i.am.link" title="Img Title"><picture><source srcset="http://www.foo.com/myimg.jpg"><source srcset="http://www.foo.com/myimg.jpg" media="(min-width: 600px)"><img src="http://www.foo.com/myimg.jpg" data-id="myImgId"></picture></a></div></main>
<footer></footer>
</body>
`;
const yDoc = new Y.Doc();
aem2doc(html, yDoc);
const result = doc2aem(yDoc);
assert.equal(result, expectedResult);
});
it('Test empty roundtrip', async () => {
const html = `
<body>
<header></header>
<main><div></div></main>
<footer></footer>
</body>
`;
const yDoc = new Y.Doc();
aem2doc(html, yDoc);
const result = doc2aem(yDoc);
assert.equal(result, html);
});
it('Test simple roundtrip', async () => {
const html = `
<body>
<header></header>
<main><div><p>Hi</p><p>Test</p><p>World</p><p>test</p></div></main>
<footer></footer>
</body>
`;
const yDoc = new Y.Doc();
aem2doc(html, yDoc);
const result = doc2aem(yDoc);
assert.equal(result, html);
});
it('Test more complex roundtrip', async () => {
const html = `
<body>
<header></header>
<main><div><picture><source srcset="https://main--aem-block-collection--adobe.hlx.live/media_1dc0a2d290d791a050feb1e159746f52db392775a.jpeg?width=750&format=jpeg&optimize=medium"><source srcset="https://main--aem-block-collection--adobe.hlx.live/media_1dc0a2d290d791a050feb1e159746f52db392775a.jpeg?width=750&format=jpeg&optimize=medium" media="(min-width: 600px)"><img src="https://main--aem-block-collection--adobe.hlx.live/media_1dc0a2d290d791a050feb1e159746f52db392775a.jpeg?width=750&format=jpeg&optimize=medium" alt="Decorative double Helix" loading="lazy"></picture><h1>Congrats, you are ready to go!</h1><p>Your forked repo is setup as a helix project and you are ready to start developing.<br>The content you are looking at is served from this <a href="https://drive.google.com/drive/folders/1Gwwrujv0Z4TxJM8askdqQkHSD969dGK7">gdrive</a><br><br>Adjust the <code>fstab.yaml</code> to point to a folder either in your sharepoint or your gdrive that you shared with helix. See the full tutorial here:<br><br><a href="https://bit.ly/3aImqUL">https://www.hlx.live/tutorial</a></p><h2>This is another headline here for more content</h2><div class="columns"><div><div><p>Columns block</p><ul><li>One</li><li>Two</li><li>Three</li></ul><p><a href="/">Live</a></p></div><div><picture><source srcset="https://main--aem-block-collection--adobe.hlx.live/media_17e9dd0aae03d62b8ebe2159b154d6824ef55732d.png?width=750&format=png&optimize=medium"><source srcset="https://main--aem-block-collection--adobe.hlx.live/media_17e9dd0aae03d62b8ebe2159b154d6824ef55732d.png?width=750&format=png&optimize=medium" media="(min-width: 600px)"><img src="https://main--aem-block-collection--adobe.hlx.live/media_17e9dd0aae03d62b8ebe2159b154d6824ef55732d.png?width=750&format=png&optimize=medium" alt="green double Helix" loading="lazy"></picture></div></div><div><div><picture><source srcset="https://main--aem-block-collection--adobe.hlx.live/media_143cf1a441962c90f082d4f7dba2aeefb07f4e821.png?width=750&format=png&optimize=medium"><source srcset="https://main--aem-block-collection--adobe.hlx.live/media_143cf1a441962c90f082d4f7dba2aeefb07f4e821.png?width=750&format=png&optimize=medium" media="(min-width: 600px)"><img src="https://main--aem-block-collection--adobe.hlx.live/media_143cf1a441962c90f082d4f7dba2aeefb07f4e821.png?width=750&format=png&optimize=medium" alt="Yellow Double Helix" loading="lazy"></picture></div><div><p>Or you can just view the preview</p><p><a href="/"><em>Preview</em></a></p></div></div></div></div><div><h2>Boilerplate Highlights?</h2><p>Find some of our favorite staff picks below:</p><div class="cards"><div><div><picture><source srcset="https://main--aem-block-collection--adobe.hlx.live/media_16582eee85490fbfe6b27c6a92724a81646c2e649.jpeg?width=750&format=jpeg&optimize=medium"><source srcset="https://main--aem-block-collection--adobe.hlx.live/media_16582eee85490fbfe6b27c6a92724a81646c2e649.jpeg?width=750&format=jpeg&optimize=medium" media="(min-width: 600px)"><img src="https://main--aem-block-collection--adobe.hlx.live/media_16582eee85490fbfe6b27c6a92724a81646c2e649.jpeg?width=750&format=jpeg&optimize=medium" alt="A fast-moving Tunnel" loading="lazy"></picture></div><div><p><strong>Unmatched speed</strong></p><p>Helix is the fastest way to publish, create, and serve websites</p></div></div><div><div><picture><source srcset="https://main--aem-block-collection--adobe.hlx.live/media_17a5ca5faf60fa6486a1476fce82a3aa606000c81.jpeg?width=750&format=jpeg&optimize=medium"><source srcset="https://main--aem-block-collection--adobe.hlx.live/media_17a5ca5faf60fa6486a1476fce82a3aa606000c81.jpeg?width=750&format=jpeg&optimize=medium" media="(min-width: 600px)"><img src="https://main--aem-block-collection--adobe.hlx.live/media_17a5ca5faf60fa6486a1476fce82a3aa606000c81.jpeg?width=750&format=jpeg&optimize=medium" alt="An iceberg" loading="lazy"></picture></div><div><p><strong>Content at scale</strong></p><p>Helix allows you to publish more content in shorter time with smaller teams</p></div></div><div><div><picture><source srcset="https://main--aem-block-collection--adobe.hlx.live/media_162cf9431ac2dfd17fe7bf4420525bbffb9d0ccfe.jpeg?width=750&format=jpeg&optimize=medium"><source srcset="https://main--aem-block-collection--adobe.hlx.live/media_162cf9431ac2dfd17fe7bf4420525bbffb9d0ccfe.jpeg?width=750&format=jpeg&optimize=medium" media="(min-width: 600px)"><img src="https://main--aem-block-collection--adobe.hlx.live/media_162cf9431ac2dfd17fe7bf4420525bbffb9d0ccfe.jpeg?width=750&format=jpeg&optimize=medium" alt="Doors with light in the dark" loading="lazy"></picture></div><div><p><strong>Uncertainty eliminated</strong></p><p>Preview content at 100% fidelity, get predictable content velocity, and shorten project durations</p></div></div><div><div><picture><source srcset="https://main--aem-block-collection--adobe.hlx.live/media_136fdd3174ff44787179448cc2e0264af1b02ade9.jpeg?width=750&format=jpeg&optimize=medium"><source srcset="https://main--aem-block-collection--adobe.hlx.live/media_136fdd3174ff44787179448cc2e0264af1b02ade9.jpeg?width=750&format=jpeg&optimize=medium" media="(min-width: 600px)"><img src="https://main--aem-block-collection--adobe.hlx.live/media_136fdd3174ff44787179448cc2e0264af1b02ade9.jpeg?width=750&format=jpeg&optimize=medium" alt="A group of people around a Table" loading="lazy"></picture></div><div><p><strong>Widen the talent pool</strong></p><p>Authors on Helix use Microsoft Word, Excel or Google Docs and need no training</p></div></div><div><div><picture><source srcset="https://main--aem-block-collection--adobe.hlx.live/media_1cae8484004513f76c6bf5860375bc020d099a6d6.jpeg?width=750&format=jpeg&optimize=medium"><source srcset="https://main--aem-block-collection--adobe.hlx.live/media_1cae8484004513f76c6bf5860375bc020d099a6d6.jpeg?width=750&format=jpeg&optimize=medium" media="(min-width: 600px)"><img src="https://main--aem-block-collection--adobe.hlx.live/media_1cae8484004513f76c6bf5860375bc020d099a6d6.jpeg?width=750&format=jpeg&optimize=medium" alt="HTML code in a code editor" loading="lazy"></picture></div><div><p><strong>The low-code way to developer productivity</strong></p><p>Say goodbye to complex APIs spanning multiple languages. Anyone with a little bit of HTML, CSS, and JS can build a site on Project Helix.</p></div></div><div><div><picture><source srcset="https://main--aem-block-collection--adobe.hlx.live/media_11381226cb58caf1f0792ea27abebbc8569b00aeb.jpeg?width=750&format=jpeg&optimize=medium"><source srcset="https://main--aem-block-collection--adobe.hlx.live/media_11381226cb58caf1f0792ea27abebbc8569b00aeb.jpeg?width=750&format=jpeg&optimize=medium" media="(min-width: 600px)"><img src="https://main--aem-block-collection--adobe.hlx.live/media_11381226cb58caf1f0792ea27abebbc8569b00aeb.jpeg?width=750&format=jpeg&optimize=medium" alt="A rocket and a headless suit" loading="lazy"></picture></div><div><p><strong>Headless is here</strong></p><p>Go directly from Microsoft Excel or Google Sheets to the web in mere seconds. Sanitize and collect form data at extreme scale with Project Helix Forms.</p></div></div><div><div><picture><source srcset="https://main--aem-block-collection--adobe.hlx.live/media_18fadeb136e84a2efe384b782e8aea6e92de4fc13.jpeg?width=750&format=jpeg&optimize=medium"><source srcset="https://main--aem-block-collection--adobe.hlx.live/media_18fadeb136e84a2efe384b782e8aea6e92de4fc13.jpeg?width=750&format=jpeg&optimize=medium" media="(min-width: 600px)"><img src="https://main--aem-block-collection--adobe.hlx.live/media_18fadeb136e84a2efe384b782e8aea6e92de4fc13.jpeg?width=750&format=jpeg&optimize=medium" alt="A dial with a hand on it" loading="lazy"></picture></div><div><p><strong>Peak performance</strong></p><p>Use Project Helix's serverless architecture to meet any traffic need. Use Project Helix's PageSpeed Insights Github action to evaluate every Pull-Request for Lighthouse Score.</p></div></div></div><p><br></p><div class="section-metadata"><div><div><p>Style</p></div><div><p>highlight</p></div></div></div></div><div><div class="metadata"><div><div><p>Title</p></div><div><p>Home | Helix Project Boilerplate</p></div></div><div><div><p>Image</p></div><div><picture><source srcset="https://main--aem-block-collection--adobe.hlx.live/media_1dc0a2d290d791a050feb1e159746f52db392775a.jpeg?width=1200&format=pjpg&optimize=medium"><source srcset="https://main--aem-block-collection--adobe.hlx.live/media_1dc0a2d290d791a050feb1e159746f52db392775a.jpeg?width=1200&format=pjpg&optimize=medium" media="(min-width: 600px)"><img src="https://main--aem-block-collection--adobe.hlx.live/media_1dc0a2d290d791a050feb1e159746f52db392775a.jpeg?width=1200&format=pjpg&optimize=medium" loading="lazy"></picture></div></div><div><div><p>Description</p></div><div><p>Use this template repository as the starting point for new Helix projects.</p></div></div></div></div></main>
<footer></footer>
</body>
`;
const yDoc = new Y.Doc();
aem2doc(html, yDoc);
const result = doc2aem(yDoc);
assert.equal(result, html);
});
it('Test more link roundtrip', async () => {
const html = `
<body>
<header></header>
<main><div><p>Your forked repo is setup as a helix project and you are ready to start developing.<br>The content you are looking at is served from this <a href="https://drive.google.com/drive/folders/1Gwwrujv0Z4TxJM8askdqQkHSD969dGK7">gdrive</a><br><br>Adjust the <code>fstab.yaml</code> to point to a folder either in your sharepoint or your gdrive that you shared with helix. See the full tutorial here:<br><br><a href="https://bit.ly/3aImqUL">https://www.hlx.live/tutorial</a></p></div></main>
<footer></footer>
</body>
`;
const yDoc = new Y.Doc();
aem2doc(html, yDoc);
const result = doc2aem(yDoc);
assert.equal(result, html);
});
it('Test nested marks roundtrip', async () => {
const html = `
<body>
<header></header>
<main><div><p>Your forked repo is setup as a helix project and you are ready to start developing.<br>The content you are looking at is served <strong>from </strong><em><strong>this</strong></em> <a href="https://drive.google.com/drive/folders/1Gwwrujv0Z4TxJM8askdqQkHSD969dGK7">gdrive</a><br><br>Adjust the <code>fstab.yaml</code> to point to a folder either in your sharepoint or your gdrive that you shared with helix. See the full tutorial here:<br><br><a href="https://bit.ly/3aImqUL">https://www.hlx.live/tutorial</a></p></div></main>
<footer></footer>
</body>
`;
const yDoc = new Y.Doc();
aem2doc(html, yDoc);
const result = doc2aem(yDoc);
assert.equal(result, html);
});
it('Test simple block roundtrip', async () => {
const html = `
<body>
<header></header>
<main><div><div class="foo"><div><div><h1>bar</h1></div><div><h2>bar2</h2></div></div></div></div></main>
<footer></footer>
</body>
`;
const yDoc = new Y.Doc();
aem2doc(html, yDoc);
const result = doc2aem(yDoc);
assert.equal(result, html);
});
it('Test complex block roundtrip', async () => {
const html =`
<body>
<header></header>
<main><div><picture><source srcset="./media_133f71a3e1a71c230536dd8e163189cd5c6269173.png?width=750&format=png&optimize=medium"><source srcset="./media_133f71a3e1a71c230536dd8e163189cd5c6269173.png?width=750&format=png&optimize=medium" media="(min-width: 600px)"><img src="./media_133f71a3e1a71c230536dd8e163189cd5c6269173.png?width=750&format=png&optimize=medium" alt="Wheatley Vodka" loading="lazy"></picture><h1>The truth is in the taste</h1><h2>10 times distilled for<br>ultra-smoothness</h2><p><a href="/about-wheatley">Learn About Wheatley Vodka</a></p><h3>10 times distilled and tripled filtered for an ultra-smooth taste.</h3></div><div><div class="callout"><div><div><h2>An award-winning vodka from the world's most award-winning distillery.</h2></div></div><div><div><picture><source srcset="./media_12c307c8546ea3d44f485807a7ce703751cf23d4c.png?width=750&format=png&optimize=medium"><source srcset="./media_12c307c8546ea3d44f485807a7ce703751cf23d4c.png?width=750&format=png&optimize=medium" media="(min-width: 600px)"><img src="./media_12c307c8546ea3d44f485807a7ce703751cf23d4c.png?width=750&format=png&optimize=medium" alt="" loading="lazy"></picture></div><div><picture><source srcset="./media_1ac96e8af760937793baa1fa6c49de457f8552813.png?width=750&format=png&optimize=medium"><source srcset="./media_1ac96e8af760937793baa1fa6c49de457f8552813.png?width=750&format=png&optimize=medium" media="(min-width: 600px)"><img src="./media_1ac96e8af760937793baa1fa6c49de457f8552813.png?width=750&format=png&optimize=medium" alt="" loading="lazy"></picture></div></div></div></div><div><div class="columns"><div><div><picture><source srcset="./media_117154c8890aced2855ddf92c698df8789757ebf4.png?width=750&format=png&optimize=medium"><source srcset="./media_117154c8890aced2855ddf92c698df8789757ebf4.png?width=750&format=png&optimize=medium" media="(min-width: 600px)"><img src="./media_117154c8890aced2855ddf92c698df8789757ebf4.png?width=750&format=png&optimize=medium" alt="Wheatley Vodka" loading="lazy"></picture></div><div><h2>Buffalo Trace Distillery - 200 years of distilling experience</h2><p>When you set out to craft a vodka from scratch, 200 years of distilling experience comes in handy. Harlen Wheatley is the Master Distiller at Buffalo Trace Distillery, America's oldest continually-operated distillery—and the world's most decorated. It all comes down to a vodka that's deliberately crafted using centuries of spirit-making knowledge.</p><p><a href="/locator">Find Wheatley Near You</a></p></div></div></div><div class="section-metadata"><div><div><p>style</p></div><div><p>reverse</p></div></div><div><div><p>background-image</p></div><div><picture><source srcset="./media_126e3f942f3105fc9f0a3e18d3d91f91fe9e32d9c.png?width=750&format=png&optimize=medium"><source srcset="./media_126e3f942f3105fc9f0a3e18d3d91f91fe9e32d9c.png?width=750&format=png&optimize=medium" media="(min-width: 600px)"><img src="./media_126e3f942f3105fc9f0a3e18d3d91f91fe9e32d9c.png?width=750&format=png&optimize=medium" alt="" loading="lazy"></picture></div></div></div></div><div><div class="featured plain"><div><div><ul><li><a href="/cocktails/cucumber-collins">Cucumber Collins</a></li><li><a href="/cocktails/wheatley-vodka-club">Wheatley Vodka Club</a></li><li><a href="/cocktails/la-luna-rossa">La Luna Rossa</a></li><li><a href="/cocktails/flatiron-flip">Flatiron Flip</a></li><li><a href="/cocktails/romapolitan">Romapolitan</a></li><li><a href="/cocktails">All Cocktails</a></li></ul></div></div></div></div><div><div class="buy"></div></div><div><h2>Follow us on Instagram</h2><p><a href="https://curator.io">Powered by Curator.io</a></p></div><div><picture><source srcset="./media_180bc2eb557a14b99d41d0e539946e44c45b9630e.png?width=750&format=png&optimize=medium"><source srcset="./media_180bc2eb557a14b99d41d0e539946e44c45b9630e.png?width=750&format=png&optimize=medium" media="(min-width: 600px)"><img src="./media_180bc2eb557a14b99d41d0e539946e44c45b9630e.png?width=750&format=png&optimize=medium" alt="" loading="lazy"></picture></div></main>
<footer></footer>
</body>
`;
const yDoc = new Y.Doc();
aem2doc(html, yDoc);
const result = doc2aem(yDoc);
console.log(result);
assert.equal(result, html);
});
it('Test linebreak roundtrip', async () => {
const html =`
<body>
<header></header>
<main><div><p>Is this broken?</p></div></main>
<footer></footer>
</body>
`;
const yDoc = new Y.Doc();
aem2doc(html, yDoc);
const result = doc2aem(yDoc);
console.log(result);
assert.equal(result, html);
});
it('Test regional edits', async () => {
const html = `
<body>
<header></header>
<main><div><da-loc-deleted><h1>Deleted H1 Here</h1></da-loc-deleted><da-loc-added><h1>Added H1 Here</h1></da-loc-added></div></main>
<footer></footer>
</body>
`;
const yDoc = new Y.Doc();
aem2doc(html, yDoc);
const result = doc2aem(yDoc);
console.log(result);
assert.equal(result, html);
});
it('Test regional edit table parsing', async () => {
const html = readFileSync('./test/mocks/regional-edit-1.html', 'utf-8');
const yDoc = new Y.Doc();
aem2doc(html, yDoc);
const result = doc2aem(yDoc);
assert.equal(collapseWhitespace(result.trim()), collapseWhitespace(html.trim()));
});
it('Test data ids', async () => {
let html = `
<body>
<header></header>
<main>
<div>
<p>Paragraph with no data id</p>
<p data-id="p-id">Paragraph with data id</p>
</div>
<div>
<h1 data-id="h1-id">H1</h1>
<h2 data-id="h2-id">H2</h2>
<h3 data-id="h3-id">H3</h3>
<h4 data-id="h4-id">H4</h4>
<h5 data-id="h5-id">H5</h5>
<h6 data-id="h6-id">H6</h6>
</div>
<div>
<h1>H1 with no data id</h1>
<h2>H2 with no data id</h2>
<h3>H3 with no data id</h3>
<h4>H4 with no data id</h4>
<h5>H5 with no data id</h5>
<h6>H6 with no data id</h6>
</div>
<div>
<ol data-id="ol-1">
<li>Item 1</li>
</ol>
<ol>
<li>Item 1</li>
<li>Item 2</li>
</ol>
</div>
<div>
<ul data-id="ul-1">
<li>Item 1</li>
<li>Item 2</li>
</ul>
<ul>
<li>Item 1</li>
<li>Item 2</li>
</ul>
</div>
<div>
<pre data-id="mycode"><code>const hello = 'world';</code></pre>
<pre><code>const hello = 'no id';</code></pre>
</div>
<div>
<blockquote data-id="bq-id">
<p>Words can be like X-rays, if you use them properly—they'll go through anything. You read and you're pierced.</p>
<p>—Aldous Huxley, Brave New World</p>
</blockquote>
</div>
<div>
<blockquote>
<p>No ID Here.</p>
<p>—Shantanu, Adobe</p>
</blockquote>
</div>
</main>
<footer></footer>
</body>
`;
html = collapseWhitespace(html);
const yDoc = new Y.Doc();
aem2doc(html, yDoc);
const result = collapseWhitespace(doc2aem(yDoc));
assert.equal(result, html);
});
it('Test superscript and subscript', async () => {
const html = `
<body>
<header></header>
<main><div><p>Hello <sup>Karl</sup></p><p>And here is <sub>subscript</sub></p><p>Done</p></div></main>
<footer></footer>
</body>
`;
const yDoc = new Y.Doc();
aem2doc(html, yDoc);
const result = doc2aem(yDoc);
console.log(result);
assert.equal(result, html);
});
it('Test section break conversion', () => {
const htmlIn = `
<body>
<header></header>
<main><div><p>ABC</p><p>---</p><p>DEF</p></div></main>
<footer></footer>
</body>
`;
const htmlOut = `
<body>
<header></header>
<main><div><p>ABC</p></div><div><p>DEF</p></div></main>
<footer></footer>
</body>
`;
const yDoc = new Y.Doc();
aem2doc(htmlIn, yDoc);
const result = doc2aem(yDoc);
console.log(result);
assert.equal(result, htmlOut,
'The horizontal line should have been converted to a section break');
});
it('Test table with empty header', () => {
const values = {
// no values
}
const p = {
children: [values]
}
const tr = {
children: [p]
}
const td = {
children: [tr]
}
const tbody = {
children: [td]
}
const table = {
children: [tbody]
}
const fragment = {
children: []
}
tableToBlock(table, fragment);
assert.equal(1, fragment.children.length);
const divEl = fragment.children[0];
assert.equal('div', divEl.type);
assert.equal('', divEl.attributes.class);
});
it('Test table with non-empty header', () => {
const values = {
text: 'myblock'
}
const p = {
children: [values]
}
const tr = {
children: [p]
}
const td = {
children: [tr]
}
const tbody = {
children: [td]
}
const table = {
children: [tbody]
}
const fragment = {
children: []
}
tableToBlock(table, fragment);
assert.equal(1, fragment.children.length);
const divEl = fragment.children[0];
assert.equal('div', divEl.type);
assert.equal('myblock', divEl.attributes.class);
});
it('image links', async () => {
let html = `
<body>
<header></header>
<main>
<div>
<div class="cards video-hover-card">
<div>
<div><a href="https://www.google.com">
<picture>
<source
srcset="https://publish-p107857-e1299068.adobeaemcloud.com/content/dam/jmp/images/design/home/jmp-anthem-thumbnail.png">
<source
srcset="https://publish-p107857-e1299068.adobeaemcloud.com/content/dam/jmp/images/design/home/jmp-anthem-thumbnail.png"
media="(min-width: 600px)"><img
src="https://publish-p107857-e1299068.adobeaemcloud.com/content/dam/jmp/images/design/home/jmp-anthem-thumbnail.png">
</picture>
</a></div>
<div>
<h4>Wo Ihre Entdeckungsreise beginnt</h4>
</div>
</div>
</div>
</div>
</main>
<footer></footer>
</body>
`;
html = collapseWhitespace(html);
const yDoc = new Y.Doc();
aem2doc(html, yDoc);
const result = doc2aem(yDoc);
assert.equal(collapseWhitespace(result), html);
});
it('image links 2', async () => {
let html = `
<body>
<header></header>
<main>
<div>
<a href="https://www.adobe.com" title="Go Home">
<picture>
<source srcset="https://content.da.live/aemsites/da-block-collection/drafts/ccc/dock.jpg">
<source srcset="https://content.da.live/aemsites/da-block-collection/drafts/ccc/dock.jpg"
media="(min-width: 600px)"><img
src="https://content.da.live/aemsites/da-block-collection/drafts/ccc/dock.jpg">
</picture>
</a>
</div>
</main>
<footer></footer>
</body>`;
html = collapseWhitespace(html);
const yDoc = new Y.Doc();
aem2doc(html, yDoc);
const result = doc2aem(yDoc);
assert.equal(collapseWhitespace(result), html);
});
it('picture inside a table', async () => {
let html = `
<body>
<header></header>
<main>
<div>
<div class="columns">
<div>
<div>
<a href="https://adobe.com/blah/blah" title="dock">
<picture>
<source srcset="https://content.da.live/aemsites/da-block-collection/drafts/ccc/dock.jpg">
<source srcset="https://content.da.live/aemsites/da-block-collection/drafts/ccc/dock.jpg" media="(min-width: 600px)">
<img src="https://content.da.live/aemsites/da-block-collection/drafts/ccc/dock.jpg">
</picture>
</a>
</div>
</div>
</div>
</div>
</main>
<footer></footer>
</body>`;
html = collapseWhitespace(html);
const yDoc = new Y.Doc();
aem2doc(html, yDoc);
const result = doc2aem(yDoc);
assert.equal(collapseWhitespace(result), html);
});
it('handles mixed content with image links', async () => {
const html = `
<body>
<header></header>
<main><div>
<h1>Title</h1>
<p>Text before</p>
<a href="https://example.com" title="Mixed">
<picture>
<source srcset="https://example.com/image.jpg">
<source srcset="https://example.com/image.jpg" media="(min-width: 600px)">
<img src="https://example.com/image.jpg" alt="Mixed">
</picture>
</a>
<p>Text after</p>
</div></main>
<footer></footer>
</body>`;
const yDoc = new Y.Doc();
aem2doc(html, yDoc);
const result = doc2aem(yDoc);
assert.equal(collapseWhitespace(result), collapseWhitespace(html));
});
it('handles image links in regional edits', async () => {
const html = `
<body>
<header></header>
<main><div>
<da-loc-deleted>
<a href="https://old.example.com" title="Old">
<picture>
<source srcset="https://old.example.com/image.jpg">
<source srcset="https://old.example.com/image.jpg" media="(min-width: 600px)">
<img src="https://old.example.com/image.jpg" alt="Old">
</picture>
</a>
</da-loc-deleted>
<da-loc-added>
<a href="https://new.example.com" title="New">
<picture>
<source srcset="https://new.example.com/image.jpg">
<source srcset="https://new.example.com/image.jpg" media="(min-width: 600px)">
<img src="https://new.example.com/image.jpg" alt="New">
</picture>
</a>
</da-loc-added>
</div></main>
<footer></footer>
</body>`;
const yDoc = new Y.Doc();
aem2doc(html, yDoc);
const result = doc2aem(yDoc);
assert.equal(collapseWhitespace(result), collapseWhitespace(html));
});
it('can parse empty doc', async () => {
const html = EMPTY_DOC;
const yDoc = new Y.Doc();
aem2doc(html, yDoc);
const result = doc2aem(yDoc);
assert.equal(collapseWhitespace(result), collapseWhitespace(EMPTY_DOC));
});
it('can parse null', async () => {
const html = null;
const yDoc = new Y.Doc();
aem2doc(html, yDoc);
const result = doc2aem(yDoc);
assert.equal(collapseWhitespace(result), collapseWhitespace(EMPTY_DOC));
});
it('can parse no main', async () => {
const html = '<body><header></header><footer></footer></body>';
const yDoc = new Y.Doc();
aem2doc(html, yDoc);
const result = doc2aem(yDoc);
assert.equal(collapseWhitespace(result), collapseWhitespace(EMPTY_DOC));
});
});