forked from BuilderIO/builder
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathediting.spec.ts
827 lines (709 loc) · 27 KB
/
editing.spec.ts
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
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
import { expect } from '@playwright/test';
import {
COLUMNS_WITH_NEW_SPACE,
COLUMNS_WITH_NEW_TEXT,
COLUMNS_WITH_NEW_WIDTHS,
} from '../specs/columns.js';
import { NEW_TEXT } from '../specs/helpers.js';
import { HOMEPAGE } from '../specs/homepage.js';
import { checkIsRN, test, excludeGen1, excludeGen2, checkIsGen1React } from '../helpers/index.js';
import {
cloneContent,
launchEmbedderAndWaitForSdk,
sendContentUpdateMessage,
sendNewStateMessage,
sendPatchOrUpdateMessage,
} from '../helpers/visual-editor.js';
import { MODIFIED_EDITING_COLUMNS } from '../specs/editing-columns-inner-layout.js';
import { ADD_A_TEXT_BLOCK } from '../specs/duplicated-content-using-nested-symbols.js';
import { EDITING_STYLES } from '../specs/editing-styles.js';
import { ACCORDION_WITH_NO_DETAIL } from '../specs/accordion.js';
import { NEW_BLOCK_ADD, NEW_BLOCK_ADD_2 } from '../specs/new-block-add.js';
import { SECTION_CHILDREN } from '../specs/section-children.js';
const editorTests = ({
noTrustedHosts,
editorIsInViewPort,
}: {
noTrustedHosts: boolean;
editorIsInViewPort?: boolean;
}) => {
test('correctly updates Text block', async ({ page, basePort, packageName, sdk }) => {
test.skip(
packageName === 'nextjs-sdk-next-app' ||
packageName === 'gen1-next14-pages' ||
packageName === 'gen1-next15-app' ||
packageName === 'gen1-remix'
);
if (!editorIsInViewPort) {
test.skip(sdk !== 'qwik', 'This is Qwik only test');
}
await launchEmbedderAndWaitForSdk({
path: noTrustedHosts
? '/no-trusted-hosts'
: editorIsInViewPort
? '/editing'
: '/editing-with-top-padding',
basePort,
page,
sdk,
});
await expect(
page.frameLocator('iframe').getByText('SDK Feature testing project')
).toBeVisible();
await sendPatchOrUpdateMessage({
page,
content: cloneContent(HOMEPAGE),
model: 'page',
sdk,
path: '/data/blocks/0/children/0/component/options/text',
updateFn: () => 'foo-bar-new-text',
});
await expect(page.frameLocator('iframe').getByText('foo-bar-new-text')).toBeVisible();
});
test('correctly updates Text block styles', async ({ page, packageName, basePort, sdk }) => {
test.skip(
packageName === 'nextjs-sdk-next-app' ||
packageName === 'gen1-next14-pages' ||
packageName === 'gen1-next15-app' ||
packageName === 'gen1-remix'
);
await launchEmbedderAndWaitForSdk({
path: noTrustedHosts ? '/editing-styles-no-trusted-hosts' : '/editing-styles',
basePort,
page,
sdk,
});
const btn1 = page.frameLocator('iframe').getByRole(sdk === 'oldReact' ? 'button' : 'link');
await expect(btn1).toHaveCSS('background-color', 'rgb(184, 35, 35)');
await sendPatchOrUpdateMessage({
page,
content: cloneContent(EDITING_STYLES),
model: 'page',
sdk,
path: '/data/blocks/0/responsiveStyles/large/backgroundColor',
updateFn: () => 'rgb(19, 67, 92)',
});
const btn = page.frameLocator('iframe').getByRole(sdk === 'oldReact' ? 'button' : 'link');
await expect(btn).toHaveCSS('background-color', 'rgb(19, 67, 92)');
});
};
test.describe('Visual Editing', () => {
editorTests({ noTrustedHosts: false, editorIsInViewPort: false });
test('correctly updates Box -> Columns when used Inner Layout > Columns option', async ({
page,
packageName,
basePort,
sdk,
}) => {
test.skip(
packageName === 'nextjs-sdk-next-app' ||
packageName === 'gen1-next14-pages' ||
packageName === 'gen1-next15-app' ||
packageName === 'gen1-react' ||
packageName === 'gen1-remix'
);
await launchEmbedderAndWaitForSdk({
path: '/editing-box-columns-inner-layout',
basePort,
page,
sdk,
});
const firstText = page.frameLocator('iframe').getByText('first');
const secondText = page.frameLocator('iframe').getByText('second');
await expect(firstText).toBeVisible();
await expect(secondText).toBeVisible();
const firstBox = await firstText.boundingBox();
const secondBox = await secondText.boundingBox();
if (firstBox && secondBox) {
expect(firstBox.y).toBeLessThan(secondBox.y);
}
await sendContentUpdateMessage({ page, newContent: MODIFIED_EDITING_COLUMNS, model: 'page' });
// had to hack this so that we can wait for the content update to actually show up (was failing in Qwik)
await page.frameLocator('iframe').getByText('third').waitFor();
const updatedFirstText = page.frameLocator('iframe').getByText('third');
await expect(updatedFirstText).toBeVisible();
await expect(secondText).toBeVisible();
const updatedFirstBox = await updatedFirstText.boundingBox();
const updatedSecondBox = await secondText.boundingBox();
if (updatedFirstBox && updatedSecondBox) {
if (checkIsRN(sdk)) {
// stack layout incase of RN SDK
expect(updatedFirstBox.x).toBe(updatedSecondBox.x);
expect(updatedFirstBox.y).toBeLessThan(updatedSecondBox.y);
} else {
expect(updatedFirstBox.x).toBeLessThan(updatedSecondBox.x);
expect(updatedFirstBox.y).toBe(updatedSecondBox.y);
}
}
});
test('removal of styles should work properly', async ({ page, packageName, sdk, basePort }) => {
test.skip(packageName === 'nextjs-sdk-next-app' || checkIsGen1React(sdk));
await launchEmbedderAndWaitForSdk({
path: '/editing-styles',
basePort,
page,
sdk,
});
const buttonLocator = checkIsRN(sdk)
? page.frameLocator('iframe').getByText('Click me!').locator('..')
: page.frameLocator('iframe').getByText('Click me!');
await expect(buttonLocator).toHaveCSS('margin-top', '20px');
const newContent = cloneContent(EDITING_STYLES);
delete newContent.data.blocks[0].responsiveStyles.large.marginTop;
await sendContentUpdateMessage({
page,
newContent,
model: 'page',
});
await expect(buttonLocator).toHaveCSS('margin-top', '0px');
});
test('nested ContentVariants with same model name should not duplicate content', async ({
page,
packageName,
basePort,
sdk,
}) => {
test.skip(
packageName === 'nextjs-sdk-next-app' ||
packageName === 'gen1-next14-pages' ||
packageName === 'gen1-next15-app' ||
packageName === 'gen1-react' ||
packageName === 'gen1-remix'
);
test.skip(packageName === 'vue', 'Vue tests flake on this one for an unnkown reason.');
await page.goto('/duplicated-content-using-nested-symbols');
await launchEmbedderAndWaitForSdk({
path: '/duplicated-content-using-nested-symbols',
basePort,
page,
sdk,
});
await sendContentUpdateMessage({
page,
newContent: ADD_A_TEXT_BLOCK,
model: 'symbol',
});
await page.frameLocator('iframe').getByText('something other than the symbol!').waitFor();
const textBlocks = await page
.frameLocator('iframe')
.getByText('something other than the symbol!')
.all();
expect(textBlocks.length).toBe(1);
});
test.describe('Column block', () => {
test('correctly updates nested Text block', async ({ page, basePort, packageName, sdk }) => {
test.skip(
packageName === 'nextjs-sdk-next-app' ||
packageName === 'gen1-next14-pages' ||
packageName === 'gen1-next15-app' ||
packageName === 'gen1-react' ||
packageName === 'gen1-remix'
);
await launchEmbedderAndWaitForSdk({ path: '/columns', basePort, page, sdk });
await sendContentUpdateMessage({ page, newContent: COLUMNS_WITH_NEW_TEXT, model: 'page' });
await page.frameLocator('iframe').getByText(NEW_TEXT).waitFor();
});
test('correctly updates space prop', async ({ page, basePort, packageName, sdk }) => {
test.skip(
packageName === 'nextjs-sdk-next-app' ||
packageName === 'gen1-next14-pages' ||
packageName === 'gen1-next15-app' ||
packageName === 'gen1-react' ||
packageName === 'gen1-remix'
);
const selector = checkIsRN(sdk)
? '[data-builder-block-name=builder-column]'
: '.builder-column';
await launchEmbedderAndWaitForSdk({ path: '/columns', basePort, page, sdk });
const secondColumn = page.frameLocator('iframe').locator(selector).nth(1);
await expect(secondColumn).toHaveCSS('margin-left', checkIsRN(sdk) ? '0px' : '20px');
await sendContentUpdateMessage({ page, newContent: COLUMNS_WITH_NEW_SPACE, model: 'page' });
await expect(secondColumn).toHaveCSS('margin-left', '10px');
});
test('correctly updates width props', async ({ page, basePort, packageName, sdk }) => {
test.skip(
packageName === 'react-native-74' ||
packageName === 'react-native-76-fabric' ||
packageName === 'nextjs-sdk-next-app' ||
packageName === 'gen1-next14-pages' ||
packageName === 'gen1-next15-app' ||
packageName === 'gen1-react' ||
packageName === 'gen1-remix'
);
await launchEmbedderAndWaitForSdk({ path: '/columns', basePort, page, sdk });
const secondColumn = page.frameLocator('iframe').locator('.builder-column').nth(1);
const initialWidth = await secondColumn.evaluate(el =>
getComputedStyle(el).width.replace('px', '')
);
await sendContentUpdateMessage({ page, newContent: COLUMNS_WITH_NEW_WIDTHS, model: 'page' });
await expect
.poll(
async () => {
const currentWidth = await secondColumn.evaluate(el =>
getComputedStyle(el).width.replace('px', '')
);
return Number(currentWidth);
},
{
message: 'Waiting for column width to increase',
timeout: 5000,
}
)
.toBeGreaterThan(Number(initialWidth));
});
});
test.describe('Accordion block', () => {
test('inserting a new detail item adds it to the correct place in the accordion', async ({
page,
sdk,
basePort,
packageName,
}) => {
test.skip(
packageName === 'nextjs-sdk-next-app' ||
packageName === 'gen1-next14-pages' ||
packageName === 'gen1-next15-app' ||
packageName === 'gen1-react' ||
packageName === 'gen1-remix'
);
await launchEmbedderAndWaitForSdk({ path: '/accordion-no-detail', basePort, page, sdk });
const item1 = page.frameLocator('iframe').getByText('Item 1');
const NEW_DETAILS_TEXT = 'new detail';
await item1.click();
await expect(page.frameLocator('iframe').getByText(NEW_DETAILS_TEXT)).not.toBeVisible();
// reset
await item1.click();
const accordion = cloneContent(ACCORDION_WITH_NO_DETAIL);
// insert new detail item
accordion.data.blocks[0].component.options.items[0].detail = [
{
id: 'some-random-id',
component: {
name: 'Text',
options: { text: NEW_DETAILS_TEXT },
},
},
];
await sendContentUpdateMessage({
page,
newContent: accordion,
model: 'page',
});
await item1.click();
const detailElement = page.frameLocator('iframe').getByText(NEW_DETAILS_TEXT);
await detailElement.waitFor();
const [titleBox, detailBox] = await Promise.all([
item1.boundingBox(),
detailElement.boundingBox(),
]);
if (!titleBox || !detailBox) {
throw new Error('Title or detail box not found');
}
expect(detailBox.y).toBeGreaterThan(titleBox.y);
});
});
test.describe('fails for empty trusted hosts', () => {
test.fail();
editorTests({ noTrustedHosts: true });
});
test.describe('Data Models', () => {
test('correctly updates', async ({ page, packageName, basePort, sdk }) => {
test.skip(packageName !== 'react', 'This test is only implemented for React');
await launchEmbedderAndWaitForSdk({ path: '/data-preview', basePort, page, sdk });
await page.frameLocator('iframe').getByText('coffee name: Epoch Chemistry').waitFor();
await page.frameLocator('iframe').getByText('coffee info: Local coffee brand.').waitFor();
await sendContentUpdateMessage({
page,
newContent: {
data: { name: 'Anchored Coffee', info: 'Another coffee brand.' },
},
model: 'coffee',
});
await page.frameLocator('iframe').getByText('coffee name: Anchored Coffee').waitFor();
await page.frameLocator('iframe').getByText('coffee info: Another coffee brand.').waitFor();
});
});
test.describe('SDK', () => {
test('should inject correct SDK data into iframe', async ({ page, basePort, sdk }) => {
test.skip(excludeGen2(sdk));
let consoleMsg = '';
const msgPromise = page.waitForEvent('console', msg => {
if (msg.text().includes('BUILDER_EVENT: builder.sdkInjected')) {
consoleMsg = msg.text();
return true;
}
return false;
});
await launchEmbedderAndWaitForSdk({
page,
basePort,
path: '/editing',
sdk,
});
await msgPromise;
expect(consoleMsg).toContain('modelName: page');
expect(consoleMsg).toContain('apiKey: abcd');
});
test('should inject correct SDK data into iframe for gen-2', async ({
page,
basePort,
sdk,
}) => {
test.skip(excludeGen1(sdk));
let consoleMsg = '';
const msgPromise = page.waitForEvent('console', msg => {
if (msg.text().includes('BUILDER_EVENT: builder.sdkInfo')) {
consoleMsg = msg.text();
return true;
}
return false;
});
await launchEmbedderAndWaitForSdk({
page,
basePort,
path: '/editing',
sdk,
});
await msgPromise;
expect(consoleMsg).toContain('modelName: page');
expect(consoleMsg).toContain('apiKey: abcd');
});
});
test.describe('Content Input', () => {
test('correctly updates', async ({ page, packageName, basePort, sdk }) => {
test.skip(
packageName === 'nextjs-sdk-next-app' ||
packageName === 'gen1-next14-pages' ||
packageName === 'gen1-next15-app' ||
packageName === 'gen1-remix'
);
await launchEmbedderAndWaitForSdk({ path: '/content-input-bindings', basePort, page, sdk });
await page.frameLocator('iframe').getByText('Bye').waitFor();
await sendNewStateMessage({
page,
newState: {
booleanToggle: true,
},
model: 'page',
});
await page.frameLocator('iframe').getByText('Hello').waitFor();
await sendNewStateMessage({
page,
newState: {
booleanToggle: false,
},
model: 'page',
});
await page.frameLocator('iframe').getByText('Bye').waitFor();
});
});
test.describe('New Block addition and deletion', () => {
test('should add new block below the last block', async ({
page,
basePort,
sdk,
packageName,
}) => {
test.skip(checkIsGen1React(sdk));
test.skip(packageName === 'nextjs-sdk-next-app');
test.skip(
packageName === 'vue',
`Failing on the CI: TypeError: Cannot read properties of null (reading 'namespaceURI')`
);
await launchEmbedderAndWaitForSdk({ path: '/new-block-add', basePort, page, sdk });
const newContent = cloneContent(NEW_BLOCK_ADD);
newContent.data.blocks.push({
'@type': '@builder.io/sdk:Element',
'@version': 2,
id: 'builder-421fe741cdab4a5181fe83ffa0af7ff6',
component: {
name: 'Text',
options: { text: 'new text' },
},
});
await sendContentUpdateMessage({
page,
newContent,
model: 'page',
});
await page.frameLocator('iframe').getByText('new text').waitFor();
const textBlocks = await page
.frameLocator('iframe')
.getByText('some text already published')
.all();
expect(textBlocks.length).toBe(1);
const newTextBlockBox = await page.frameLocator('iframe').getByText('new text').boundingBox();
expect(newTextBlockBox).toBeDefined();
const textBlockBox = await textBlocks[0].boundingBox();
expect(textBlockBox).toBeDefined();
if (!newTextBlockBox || !textBlockBox) {
throw new Error('New text block or text block not found');
}
expect(newTextBlockBox.y).toBeGreaterThan(textBlockBox.y);
});
test('should add new block in the middle', async ({ page, basePort, sdk, packageName }) => {
test.skip(checkIsGen1React(sdk));
test.skip(packageName === 'nextjs-sdk-next-app');
test.skip(
packageName === 'vue',
`Failing on the CI: TypeError: Cannot read properties of null (reading 'namespaceURI')`
);
await launchEmbedderAndWaitForSdk({ path: '/new-block-add', basePort, page, sdk });
const newContent = cloneContent(NEW_BLOCK_ADD_2);
newContent.data.blocks.splice(1, 0, {
'@type': '@builder.io/sdk:Element',
'@version': 2,
id: 'builder-421fe741cdab4a5181fe83ffa0af7ff6',
component: { name: 'Text', options: { text: 'add to middle' } },
});
await sendContentUpdateMessage({
page,
newContent,
model: 'page',
});
await page.frameLocator('iframe').getByText('add to middle').waitFor();
const topTextBlockBox = await page
.frameLocator('iframe')
.getByText('some text already published')
.boundingBox();
const endTextBlockBox = await page.frameLocator('iframe').getByText('end text').boundingBox();
const middleTextBlockBox = await page
.frameLocator('iframe')
.getByText('add to middle')
.boundingBox();
expect(middleTextBlockBox).toBeDefined();
expect(topTextBlockBox).toBeDefined();
expect(endTextBlockBox).toBeDefined();
if (!middleTextBlockBox || !topTextBlockBox || !endTextBlockBox) {
throw new Error('New text block or text block not found');
}
expect(middleTextBlockBox.y).toBeGreaterThan(topTextBlockBox.y);
expect(middleTextBlockBox.y).toBeLessThan(endTextBlockBox.y);
});
test('should add new block at the top', async ({ page, basePort, sdk, packageName }) => {
test.skip(checkIsGen1React(sdk));
test.skip(packageName === 'nextjs-sdk-next-app');
test.skip(
packageName === 'vue',
`Failing on the CI: TypeError: Cannot read properties of null (reading 'namespaceURI')`
);
await launchEmbedderAndWaitForSdk({ path: '/new-block-add', basePort, page, sdk });
const newContent = cloneContent(NEW_BLOCK_ADD);
newContent.data.blocks.unshift({
'@type': '@builder.io/sdk:Element',
'@version': 2,
id: 'builder-421fe741cdab4a5181fe83ffa0af7ff6',
component: {
name: 'Text',
options: { text: 'add to top' },
},
});
await sendContentUpdateMessage({
page,
newContent,
model: 'page',
});
await page.frameLocator('iframe').getByText('add to top').waitFor();
const textBlocks = await page
.frameLocator('iframe')
.getByText('some text already published')
.all();
expect(textBlocks.length).toBe(1);
const newTextBlockBox = await page
.frameLocator('iframe')
.getByText('add to top')
.boundingBox();
expect(newTextBlockBox).toBeDefined();
const textBlockBox = await textBlocks[0].boundingBox();
expect(textBlockBox).toBeDefined();
if (!newTextBlockBox || !textBlockBox) {
throw new Error('New text block or text block not found');
}
expect(newTextBlockBox.y).toBeLessThan(textBlockBox.y);
});
test('deleting a newly added block should remove it from the DOM', async ({
page,
basePort,
sdk,
packageName,
}) => {
test.skip(checkIsGen1React(sdk));
test.skip(packageName === 'nextjs-sdk-next-app');
test.skip(
packageName === 'vue',
`Failing on the CI: TypeError: Cannot read properties of null (reading 'namespaceURI')`
);
await launchEmbedderAndWaitForSdk({ path: '/new-block-add', basePort, page, sdk });
const newContent = cloneContent(NEW_BLOCK_ADD);
newContent.data.blocks.push({
'@type': '@builder.io/sdk:Element',
'@version': 2,
id: 'builder-421fe741cdab4a5181fe83ffa0af7ff6',
component: {
name: 'Text',
options: { text: 'new text' },
},
});
await sendContentUpdateMessage({
page,
newContent,
model: 'page',
});
await page.frameLocator('iframe').getByText('new text').waitFor();
const updatedContent = cloneContent(NEW_BLOCK_ADD);
updatedContent.data.blocks.pop();
await sendContentUpdateMessage({ page, newContent: updatedContent, model: 'page' });
await page.frameLocator('iframe').getByText('new text').waitFor({ state: 'hidden' });
});
});
test.describe('New Block addition and deletion with components using props.children / slots', () => {
test('should add new block below the last block', async ({
page,
basePort,
sdk,
packageName,
}) => {
test.skip(checkIsGen1React(sdk));
test.skip(packageName === 'nextjs-sdk-next-app');
test.skip(
packageName === 'vue',
`Failing on the CI: TypeError: Cannot read properties of null (reading 'namespaceURI')`
);
await launchEmbedderAndWaitForSdk({ path: '/section-children', basePort, page, sdk });
const newContent = cloneContent(SECTION_CHILDREN);
newContent.data.blocks[0].children.push({
'@type': '@builder.io/sdk:Element',
'@version': 2,
id: 'builder-421fe741cdab4a5181fe83ffa0af7ff6',
component: {
name: 'Text',
options: { text: 'new text' },
},
});
await sendContentUpdateMessage({
page,
newContent,
model: 'page',
});
await page.frameLocator('iframe').getByText('new text').waitFor();
const textBlocks = await page.frameLocator('iframe').getByText('text 2').all();
expect(textBlocks.length).toBe(1);
const newTextBlockBox = await page.frameLocator('iframe').getByText('new text').boundingBox();
expect(newTextBlockBox).toBeDefined();
const textBlockBox = await textBlocks[0].boundingBox();
expect(textBlockBox).toBeDefined();
if (!newTextBlockBox || !textBlockBox) {
throw new Error('New text block or text block not found');
}
expect(newTextBlockBox.y).toBeGreaterThan(textBlockBox.y);
});
test('should add new block in the middle', async ({ page, basePort, sdk, packageName }) => {
test.skip(checkIsGen1React(sdk));
test.skip(packageName === 'nextjs-sdk-next-app');
test.skip(
packageName === 'vue',
`Failing on the CI: TypeError: Cannot read properties of null (reading 'namespaceURI')`
);
await launchEmbedderAndWaitForSdk({ path: '/section-children', basePort, page, sdk });
const newContent = cloneContent(SECTION_CHILDREN);
newContent.data.blocks[0].children.splice(1, 0, {
'@type': '@builder.io/sdk:Element',
'@version': 2,
id: 'builder-421fe741cdab4a5181fe83ffa0af7ff6',
component: { name: 'Text', options: { text: 'add to middle' } },
});
await sendContentUpdateMessage({
page,
newContent,
model: 'page',
});
await page.frameLocator('iframe').getByText('add to middle').waitFor();
const topTextBlockBox = await page.frameLocator('iframe').getByText('text 1').boundingBox();
const endTextBlockBox = await page.frameLocator('iframe').getByText('text 2').boundingBox();
const middleTextBlockBox = await page
.frameLocator('iframe')
.getByText('add to middle')
.boundingBox();
expect(middleTextBlockBox).toBeDefined();
expect(topTextBlockBox).toBeDefined();
expect(endTextBlockBox).toBeDefined();
if (!middleTextBlockBox || !topTextBlockBox || !endTextBlockBox) {
throw new Error('Middle text block or text block not found');
}
expect(middleTextBlockBox.y).toBeGreaterThan(topTextBlockBox.y);
expect(middleTextBlockBox.y).toBeLessThan(endTextBlockBox.y);
});
test('should add new block at the top', async ({ page, basePort, sdk, packageName }) => {
test.skip(checkIsGen1React(sdk));
test.skip(packageName === 'nextjs-sdk-next-app');
test.skip(
packageName === 'vue',
`Failing on the CI: TypeError: Cannot read properties of null (reading 'namespaceURI')`
);
await launchEmbedderAndWaitForSdk({ path: '/section-children', basePort, page, sdk });
const newContent = cloneContent(SECTION_CHILDREN);
newContent.data.blocks[0].children.unshift({
'@type': '@builder.io/sdk:Element',
'@version': 2,
id: 'builder-421fe741cdab4a5181fe83ffa0af7ff6',
component: {
name: 'Text',
options: { text: 'add to top' },
},
});
await sendContentUpdateMessage({
page,
newContent,
model: 'page',
});
await page.frameLocator('iframe').getByText('add to top').waitFor();
const textBlocks = await page.frameLocator('iframe').getByText('text 1').all();
expect(textBlocks.length).toBe(1);
const newTextBlockBox = await page
.frameLocator('iframe')
.getByText('add to top')
.boundingBox();
expect(newTextBlockBox).toBeDefined();
const textBlockBox = await textBlocks[0].boundingBox();
expect(textBlockBox).toBeDefined();
if (!newTextBlockBox || !textBlockBox) {
throw new Error('New text block or text block not found');
}
expect(newTextBlockBox.y).toBeLessThan(textBlockBox.y);
});
test('deleting a newly added block should remove it from the DOM', async ({
page,
basePort,
sdk,
packageName,
}) => {
test.skip(checkIsGen1React(sdk));
test.skip(packageName === 'nextjs-sdk-next-app');
test.skip(
packageName === 'vue',
`Failing on the CI: TypeError: Cannot read properties of null (reading 'namespaceURI')`
);
await launchEmbedderAndWaitForSdk({ path: '/section-children', basePort, page, sdk });
const newContent = cloneContent(SECTION_CHILDREN);
newContent.data.blocks[0].children.push({
'@type': '@builder.io/sdk:Element',
'@version': 2,
id: 'builder-421fe741cdab4a5181fe83ffa0af7ff6',
component: {
name: 'Text',
options: { text: 'new text' },
},
});
await sendContentUpdateMessage({
page,
newContent,
model: 'page',
});
await page.frameLocator('iframe').getByText('new text').waitFor();
const updatedContent = cloneContent(SECTION_CHILDREN);
updatedContent.data.blocks[0].children.pop();
await sendContentUpdateMessage({ page, newContent: updatedContent, model: 'page' });
await page.frameLocator('iframe').getByText('new text').waitFor({ state: 'hidden' });
});
});
});