@@ -19,6 +19,7 @@ import { ADD_A_TEXT_BLOCK } from '../specs/duplicated-content-using-nested-symbo
19
19
import { EDITING_STYLES } from '../specs/editing-styles.js' ;
20
20
import { ACCORDION_WITH_NO_DETAIL } from '../specs/accordion.js' ;
21
21
import { NEW_BLOCK_ADD , NEW_BLOCK_ADD_2 } from '../specs/new-block-add.js' ;
22
+ import { SECTION_CHILDREN } from '../specs/section-children.js' ;
22
23
23
24
const editorTests = ( {
24
25
noTrustedHosts,
@@ -644,4 +645,183 @@ test.describe('Visual Editing', () => {
644
645
await page . frameLocator ( 'iframe' ) . getByText ( 'new text' ) . waitFor ( { state : 'hidden' } ) ;
645
646
} ) ;
646
647
} ) ;
648
+
649
+ test . describe ( 'New Block addition and deletion with components using props.children / slots' , ( ) => {
650
+ test ( 'should add new block below the last block' , async ( {
651
+ page,
652
+ basePort,
653
+ sdk,
654
+ packageName,
655
+ } ) => {
656
+ test . skip ( checkIsGen1React ( sdk ) ) ;
657
+ test . skip ( packageName === 'nextjs-sdk-next-app' ) ;
658
+ test . skip (
659
+ packageName === 'vue' ,
660
+ `Failing on the CI: TypeError: Cannot read properties of null (reading 'namespaceURI')`
661
+ ) ;
662
+
663
+ await launchEmbedderAndWaitForSdk ( { path : '/section-children' , basePort, page, sdk } ) ;
664
+
665
+ const newContent = cloneContent ( SECTION_CHILDREN ) ;
666
+ newContent . data . blocks [ 0 ] . children . push ( {
667
+ '@type' : '@builder.io/sdk:Element' ,
668
+ '@version' : 2 ,
669
+ id : 'builder-421fe741cdab4a5181fe83ffa0af7ff6' ,
670
+ component : {
671
+ name : 'Text' ,
672
+ options : { text : 'new text' } ,
673
+ } ,
674
+ } ) ;
675
+
676
+ await sendContentUpdateMessage ( {
677
+ page,
678
+ newContent,
679
+ model : 'page' ,
680
+ } ) ;
681
+ await page . frameLocator ( 'iframe' ) . getByText ( 'new text' ) . waitFor ( ) ;
682
+
683
+ const textBlocks = await page . frameLocator ( 'iframe' ) . getByText ( 'text 2' ) . all ( ) ;
684
+ expect ( textBlocks . length ) . toBe ( 1 ) ;
685
+ const newTextBlockBox = await page . frameLocator ( 'iframe' ) . getByText ( 'new text' ) . boundingBox ( ) ;
686
+ expect ( newTextBlockBox ) . toBeDefined ( ) ;
687
+ const textBlockBox = await textBlocks [ 0 ] . boundingBox ( ) ;
688
+ expect ( textBlockBox ) . toBeDefined ( ) ;
689
+
690
+ if ( ! newTextBlockBox || ! textBlockBox ) {
691
+ throw new Error ( 'New text block or text block not found' ) ;
692
+ }
693
+
694
+ expect ( newTextBlockBox . y ) . toBeGreaterThan ( textBlockBox . y ) ;
695
+ } ) ;
696
+
697
+ test ( 'should add new block in the middle' , async ( { page, basePort, sdk, packageName } ) => {
698
+ test . skip ( checkIsGen1React ( sdk ) ) ;
699
+ test . skip ( packageName === 'nextjs-sdk-next-app' ) ;
700
+ test . skip (
701
+ packageName === 'vue' ,
702
+ `Failing on the CI: TypeError: Cannot read properties of null (reading 'namespaceURI')`
703
+ ) ;
704
+
705
+ await launchEmbedderAndWaitForSdk ( { path : '/section-children' , basePort, page, sdk } ) ;
706
+
707
+ const newContent = cloneContent ( SECTION_CHILDREN ) ;
708
+
709
+ newContent . data . blocks [ 0 ] . children . splice ( 1 , 0 , {
710
+ '@type' : '@builder.io/sdk:Element' ,
711
+ '@version' : 2 ,
712
+ id : 'builder-421fe741cdab4a5181fe83ffa0af7ff6' ,
713
+ component : { name : 'Text' , options : { text : 'add to middle' } } ,
714
+ } ) ;
715
+
716
+ await sendContentUpdateMessage ( {
717
+ page,
718
+ newContent,
719
+ model : 'page' ,
720
+ } ) ;
721
+ await page . frameLocator ( 'iframe' ) . getByText ( 'add to middle' ) . waitFor ( ) ;
722
+
723
+ const topTextBlockBox = await page . frameLocator ( 'iframe' ) . getByText ( 'text 1' ) . boundingBox ( ) ;
724
+ const endTextBlockBox = await page . frameLocator ( 'iframe' ) . getByText ( 'text 2' ) . boundingBox ( ) ;
725
+ const middleTextBlockBox = await page
726
+ . frameLocator ( 'iframe' )
727
+ . getByText ( 'add to middle' )
728
+ . boundingBox ( ) ;
729
+
730
+ expect ( middleTextBlockBox ) . toBeDefined ( ) ;
731
+ expect ( topTextBlockBox ) . toBeDefined ( ) ;
732
+ expect ( endTextBlockBox ) . toBeDefined ( ) ;
733
+
734
+ if ( ! middleTextBlockBox || ! topTextBlockBox || ! endTextBlockBox ) {
735
+ throw new Error ( 'Middle text block or text block not found' ) ;
736
+ }
737
+
738
+ expect ( middleTextBlockBox . y ) . toBeGreaterThan ( topTextBlockBox . y ) ;
739
+ expect ( middleTextBlockBox . y ) . toBeLessThan ( endTextBlockBox . y ) ;
740
+ } ) ;
741
+
742
+ test ( 'should add new block at the top' , async ( { page, basePort, sdk, packageName } ) => {
743
+ test . skip ( checkIsGen1React ( sdk ) ) ;
744
+ test . skip ( packageName === 'nextjs-sdk-next-app' ) ;
745
+ test . skip (
746
+ packageName === 'vue' ,
747
+ `Failing on the CI: TypeError: Cannot read properties of null (reading 'namespaceURI')`
748
+ ) ;
749
+
750
+ await launchEmbedderAndWaitForSdk ( { path : '/section-children' , basePort, page, sdk } ) ;
751
+
752
+ const newContent = cloneContent ( SECTION_CHILDREN ) ;
753
+ newContent . data . blocks [ 0 ] . children . unshift ( {
754
+ '@type' : '@builder.io/sdk:Element' ,
755
+ '@version' : 2 ,
756
+ id : 'builder-421fe741cdab4a5181fe83ffa0af7ff6' ,
757
+ component : {
758
+ name : 'Text' ,
759
+ options : { text : 'add to top' } ,
760
+ } ,
761
+ } ) ;
762
+
763
+ await sendContentUpdateMessage ( {
764
+ page,
765
+ newContent,
766
+ model : 'page' ,
767
+ } ) ;
768
+ await page . frameLocator ( 'iframe' ) . getByText ( 'add to top' ) . waitFor ( ) ;
769
+
770
+ const textBlocks = await page . frameLocator ( 'iframe' ) . getByText ( 'text 1' ) . all ( ) ;
771
+ expect ( textBlocks . length ) . toBe ( 1 ) ;
772
+ const newTextBlockBox = await page
773
+ . frameLocator ( 'iframe' )
774
+ . getByText ( 'add to top' )
775
+ . boundingBox ( ) ;
776
+ expect ( newTextBlockBox ) . toBeDefined ( ) ;
777
+ const textBlockBox = await textBlocks [ 0 ] . boundingBox ( ) ;
778
+ expect ( textBlockBox ) . toBeDefined ( ) ;
779
+
780
+ if ( ! newTextBlockBox || ! textBlockBox ) {
781
+ throw new Error ( 'New text block or text block not found' ) ;
782
+ }
783
+
784
+ expect ( newTextBlockBox . y ) . toBeLessThan ( textBlockBox . y ) ;
785
+ } ) ;
786
+
787
+ test ( 'deleting a newly added block should remove it from the DOM' , async ( {
788
+ page,
789
+ basePort,
790
+ sdk,
791
+ packageName,
792
+ } ) => {
793
+ test . skip ( checkIsGen1React ( sdk ) ) ;
794
+ test . skip ( packageName === 'nextjs-sdk-next-app' ) ;
795
+ test . skip (
796
+ packageName === 'vue' ,
797
+ `Failing on the CI: TypeError: Cannot read properties of null (reading 'namespaceURI')`
798
+ ) ;
799
+
800
+ await launchEmbedderAndWaitForSdk ( { path : '/section-children' , basePort, page, sdk } ) ;
801
+
802
+ const newContent = cloneContent ( SECTION_CHILDREN ) ;
803
+ newContent . data . blocks [ 0 ] . children . push ( {
804
+ '@type' : '@builder.io/sdk:Element' ,
805
+ '@version' : 2 ,
806
+ id : 'builder-421fe741cdab4a5181fe83ffa0af7ff6' ,
807
+ component : {
808
+ name : 'Text' ,
809
+ options : { text : 'new text' } ,
810
+ } ,
811
+ } ) ;
812
+
813
+ await sendContentUpdateMessage ( {
814
+ page,
815
+ newContent,
816
+ model : 'page' ,
817
+ } ) ;
818
+ await page . frameLocator ( 'iframe' ) . getByText ( 'new text' ) . waitFor ( ) ;
819
+
820
+ const updatedContent = cloneContent ( SECTION_CHILDREN ) ;
821
+ updatedContent . data . blocks [ 0 ] . children . pop ( ) ;
822
+
823
+ await sendContentUpdateMessage ( { page, newContent : updatedContent , model : 'page' } ) ;
824
+ await page . frameLocator ( 'iframe' ) . getByText ( 'new text' ) . waitFor ( { state : 'hidden' } ) ;
825
+ } ) ;
826
+ } ) ;
647
827
} ) ;
0 commit comments