@@ -4,6 +4,8 @@ import { render, waitFor } from '@testing-library/vue'
4
4
import { mount } from '@vue/test-utils'
5
5
import Vue , { FunctionalComponentOptions } from 'vue'
6
6
import { FormProvider , createSchemaField } from '../vue2-components'
7
+ import { connect , mapProps , mapReadPretty } from '../'
8
+ import { defineComponent } from 'vue-demi'
7
9
8
10
Vue . component ( 'FormProvider' , FormProvider )
9
11
@@ -81,7 +83,7 @@ const Previewer3: FunctionalComponentOptions = {
81
83
} ,
82
84
[
83
85
context . scopedSlots . default ( {
84
- scopedProp : '123' ,
86
+ slotProp : '123' ,
85
87
} ) ,
86
88
]
87
89
)
@@ -100,7 +102,7 @@ const Previewer4: FunctionalComponentOptions = {
100
102
} ,
101
103
[
102
104
context . scopedSlots . content ( {
103
- scopedProp : '123' ,
105
+ slotProp : '123' ,
104
106
} ) ,
105
107
]
106
108
)
@@ -444,7 +446,7 @@ describe('x-content', () => {
444
446
const Content = {
445
447
functional : true ,
446
448
render ( h , context ) {
447
- return h ( 'span' , context . props . scopedProp )
449
+ return h ( 'span' , context . props . slotProp )
448
450
} ,
449
451
}
450
452
@@ -481,7 +483,7 @@ describe('x-content', () => {
481
483
const Content = {
482
484
functional : true ,
483
485
render ( h , context ) {
484
- return h ( 'span' , context . props . scopedProp )
486
+ return h ( 'span' , context . props . slotProp )
485
487
} ,
486
488
}
487
489
const { SchemaField } = createSchemaField ( {
@@ -520,7 +522,7 @@ describe('x-content', () => {
520
522
const Content = {
521
523
functional : true ,
522
524
render ( h , context ) {
523
- return h ( 'span' , context . props . scopedProp )
525
+ return h ( 'span' , context . props . slotProp )
524
526
} ,
525
527
}
526
528
const { SchemaField } = createSchemaField ( {
@@ -558,7 +560,7 @@ describe('x-content', () => {
558
560
const Content = {
559
561
functional : true ,
560
562
render ( h , context ) {
561
- return h ( 'span' , context . props . scopedProp )
563
+ return h ( 'span' , context . props . slotProp )
562
564
} ,
563
565
}
564
566
const { SchemaField } = createSchemaField ( {
@@ -591,6 +593,142 @@ describe('x-content', () => {
591
593
expect ( queryByTestId ( 'previewer4' ) . textContent ) . toEqual ( '123' )
592
594
} )
593
595
596
+ test ( 'scoped slot with connect' , ( ) => {
597
+ const form = createForm ( )
598
+ const ConnectedComponent = connect (
599
+ defineComponent ( {
600
+ render ( h ) {
601
+ return h (
602
+ 'div' ,
603
+ {
604
+ attrs : {
605
+ 'data-testid' : 'ConnectedComponent' ,
606
+ } ,
607
+ } ,
608
+ [
609
+ this . $scopedSlots . default ( {
610
+ slotProp : '123' ,
611
+ } ) ,
612
+ ]
613
+ )
614
+ } ,
615
+ } ) ,
616
+ mapProps ( ( props , field ) => {
617
+ return {
618
+ ...props ,
619
+ }
620
+ } )
621
+ )
622
+
623
+ const scopeSlotComponent = {
624
+ functional : true ,
625
+ render ( h , context ) {
626
+ return h ( 'span' , context . props . slotProp )
627
+ } ,
628
+ }
629
+ const { SchemaField } = createSchemaField ( {
630
+ components : {
631
+ ConnectedComponent,
632
+ } ,
633
+ } )
634
+ const { queryByTestId } = render ( {
635
+ components : { SchemaField } ,
636
+ data ( ) {
637
+ return {
638
+ form,
639
+ schema : new Schema ( {
640
+ type : 'string' ,
641
+ name : 'ConnectedComponent' ,
642
+ 'x-component' : 'ConnectedComponent' ,
643
+ 'x-content' : {
644
+ default : scopeSlotComponent ,
645
+ } ,
646
+ } ) ,
647
+ }
648
+ } ,
649
+ template : `<FormProvider :form="form">
650
+ <SchemaField
651
+ name="string"
652
+ :schema="schema"
653
+ />
654
+ </FormProvider>` ,
655
+ } )
656
+ expect ( queryByTestId ( 'ConnectedComponent' ) ) . toBeVisible ( )
657
+ expect ( queryByTestId ( 'ConnectedComponent' ) . textContent ) . toEqual ( '123' )
658
+ } )
659
+
660
+ test ( 'scoped slot with connect and readPretty' , ( ) => {
661
+ const form = createForm ( )
662
+
663
+ const ConnectedWithMapReadPretty = connect (
664
+ defineComponent ( {
665
+ render ( h ) {
666
+ return h (
667
+ 'div' ,
668
+ {
669
+ attrs : {
670
+ 'data-testid' : 'ConnectedWithMapReadPretty' ,
671
+ } ,
672
+ } ,
673
+ [
674
+ this . $scopedSlots . withMapReadPretty ( {
675
+ slotProp : '123' ,
676
+ } ) ,
677
+ ]
678
+ )
679
+ } ,
680
+ } ) ,
681
+ mapProps ( ( props , field ) => {
682
+ return {
683
+ ...props ,
684
+ }
685
+ } ) ,
686
+ mapReadPretty ( {
687
+ render ( h ) {
688
+ return h ( 'div' , 'read pretty' )
689
+ } ,
690
+ } )
691
+ )
692
+
693
+ const scopeSlotComponent = {
694
+ functional : true ,
695
+ render ( h , context ) {
696
+ return h ( 'span' , context . props . slotProp )
697
+ } ,
698
+ }
699
+ const { SchemaField } = createSchemaField ( {
700
+ components : {
701
+ ConnectedWithMapReadPretty,
702
+ } ,
703
+ } )
704
+ const { queryByTestId } = render ( {
705
+ components : { SchemaField } ,
706
+ data ( ) {
707
+ return {
708
+ form,
709
+ schema : new Schema ( {
710
+ type : 'string' ,
711
+ name : 'ConnectedWithMapReadPretty' ,
712
+ 'x-component' : 'ConnectedWithMapReadPretty' ,
713
+ 'x-content' : {
714
+ withMapReadPretty : scopeSlotComponent ,
715
+ } ,
716
+ } ) ,
717
+ }
718
+ } ,
719
+ template : `<FormProvider :form="form">
720
+ <SchemaField
721
+ name="string"
722
+ :schema="schema"
723
+ />
724
+ </FormProvider>` ,
725
+ } )
726
+ expect ( queryByTestId ( 'ConnectedWithMapReadPretty' ) ) . toBeVisible ( )
727
+ expect ( queryByTestId ( 'ConnectedWithMapReadPretty' ) . textContent ) . toEqual (
728
+ '123'
729
+ )
730
+ } )
731
+
594
732
test ( 'slot compitible' , ( ) => {
595
733
const form = createForm ( )
596
734
const { SchemaField } = createSchemaField ( {
0 commit comments