@@ -29,24 +29,69 @@ const configList: TestBedConfig[] = [{
29
29
indexToReplace : baseSettings . maxIndex ,
30
30
token : 'last'
31
31
}
32
- } ] . map ( config => ( { ...config , datasourceClass : getDatasourceReplacementsClass ( config . datasourceSettings ) } ) ) ;
32
+ } ] . map ( config => ( {
33
+ ...config ,
34
+ datasourceClass : getDatasourceReplacementsClass ( config . datasourceSettings )
35
+ } ) ) ;
36
+
37
+ const someToOneConfigList : TestBedConfig [ ] = [ {
38
+ datasourceSettings : { ...baseSettings } ,
39
+ custom : {
40
+ indexesToReplace : [
41
+ baseSettings . minIndex + 1 ,
42
+ baseSettings . minIndex + 2 ,
43
+ baseSettings . minIndex + 3
44
+ ] ,
45
+ token : 'middle'
46
+ }
47
+ } , {
48
+ datasourceSettings : { ...baseSettings } ,
49
+ custom : {
50
+ indexesToReplace : [
51
+ baseSettings . minIndex ,
52
+ baseSettings . minIndex + 1 ,
53
+ baseSettings . minIndex + 2
54
+ ] ,
55
+ token : 'first'
56
+ }
57
+ } , {
58
+ datasourceSettings : { ...baseSettings , startIndex : baseSettings . maxIndex } ,
59
+ custom : {
60
+ indexesToReplace : [
61
+ baseSettings . maxIndex - 2 ,
62
+ baseSettings . maxIndex - 1 ,
63
+ baseSettings . maxIndex
64
+ ] ,
65
+ token : 'last'
66
+ }
67
+ } ] . map ( config => ( {
68
+ ...config ,
69
+ datasourceClass : getDatasourceReplacementsClass ( config . datasourceSettings )
70
+ } ) ) ;
71
+
33
72
34
73
const shouldReplace = ( config : TestBedConfig ) => ( misc : Misc ) => async ( done : Function ) => {
35
74
await misc . relaxNext ( ) ;
36
75
const { adapter } = misc ;
37
- const { custom : { indexToReplace : index , token } } = config ;
76
+ const { custom : { indexToReplace : index , indexesToReplace : indexes , token } } = config ;
38
77
const { datasourceSettings : { minIndex, itemSize } } = config ;
39
- const maxScrollPosition = misc . getMaxScrollPosition ( ) ;
40
- const position = token === 'last' ? maxScrollPosition : ( index - 1 + minIndex - 1 ) * itemSize ;
41
- const newItem = generateItem ( index ) ;
78
+ const diff = indexes ? indexes . length : 1 ;
79
+ const maxScrollPosition = misc . getMaxScrollPosition ( ) - ( diff - 1 ) * misc . getItemSize ( ) ;
80
+ const newIndex = indexes ? indexes [ 0 ] : index ;
81
+ const position = token === 'last' ? maxScrollPosition : ( newIndex - 1 + minIndex - 1 ) * itemSize ;
82
+ const newItem = generateItem ( newIndex ) ;
42
83
newItem . text += '*' ;
43
84
44
- // replace at the Datasource level
45
- ( misc . datasource as any ) . replaceOne ( index , newItem ) ;
85
+ // replace at the Datasource level (component)
86
+ if ( index ) {
87
+ ( misc . datasource as any ) . replaceOneToOne ( index , newItem ) ;
88
+ } else if ( indexes ) {
89
+ ( misc . datasource as any ) . replaceManyToOne ( indexes , newItem ) ;
90
+ }
46
91
47
- // replace at the Viewport level (Adapter )
92
+ // replace at the Viewport level (scroller )
48
93
await adapter . replace ( {
49
- predicate : ( { $index } ) => [ index ] . includes ( $index ) ,
94
+ predicate : ( { $index } ) => ( indexes || [ index ] ) . includes ( $index ) ,
50
95
items : [ newItem ]
51
96
} ) ;
52
97
@@ -58,12 +103,21 @@ const shouldReplace = (config: TestBedConfig) => (misc: Misc) => async (done: Fu
58
103
await misc . relaxNext ( ) ;
59
104
}
60
105
106
+ // check replaced item
107
+ if ( token === 'last' ) {
108
+ expect ( adapter . lastVisible . $index ) . toEqual ( newIndex ) ;
109
+ } else {
110
+ expect ( adapter . firstVisible . $index ) . toEqual ( newIndex ) ;
111
+ }
112
+ expect ( misc . getElementText ( newIndex ) ) . toEqual ( newIndex + ': ' + newItem . text ) ;
113
+
114
+ // check the next item
61
115
if ( token === 'last' ) {
62
- expect ( adapter . lastVisible . $index ) . toEqual ( index ) ;
116
+ expect ( misc . checkElementContent ( newIndex - 1 , newIndex - 1 ) ) . toEqual ( true ) ;
63
117
} else {
64
- expect ( adapter . firstVisible . $index ) . toEqual ( index ) ;
118
+ expect ( misc . checkElementContent ( newIndex + 1 , newIndex + diff ) ) . toEqual ( true ) ;
65
119
}
66
- expect ( misc . getElementText ( index ) ) . toEqual ( index + ': ' + newItem . text ) ;
120
+
67
121
done ( ) ;
68
122
} ;
69
123
@@ -79,4 +133,14 @@ describe('Adapter Replace Spec', () => {
79
133
)
80
134
) ;
81
135
136
+ describe ( 'some-to-one replacement' , ( ) =>
137
+ someToOneConfigList . forEach ( config =>
138
+ makeTest ( {
139
+ title : `should work (${ config . custom . token } )` ,
140
+ config,
141
+ it : shouldReplace ( config )
142
+ } )
143
+ )
144
+ ) ;
145
+
82
146
} ) ;
0 commit comments